8000 Merge remote-tracking branch 'upstream/master' into util-improvements · abhinavcoder/python@3489838 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3489838

Browse files
committed
Merge remote-tracking branch 'upstream/master' into util-improvements
2 parents f6566ee + c86e489 commit 3489838

File tree

10 files changed

+103
-40
lines changed

10 files changed

+103
-40
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Contributing guidelines
1+
# Contributing Guidelines
22

33
## How to become a contributor and submit your own code
44

@@ -21,6 +21,6 @@ Follow either of the two links above to access the appropriate CLA and instructi
2121
1. Fork the desired repo, develop and test your code changes.
2222
1. Submit a pull request.
2323

24-
### Adding dependencies
24+
### Adding Dependencies
2525

2626
If your patch depends on new packages, add those packages to [requirements.txt](requirements.txt) and [setup.py](setup.py).

OWNERS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@ approvers:
66
- lavalamp
77
- yliaog
88
- roycaihw
9-

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ python -m examples.example1
7070

7171
(replace example1 with the example base filename)
7272

73-
7473
## Documentation
7574

7675
All APIs and Models' documentation can be found at the [Generated client's README file](kubernetes/README.md)
@@ -131,7 +130,6 @@ between client-python versions.
131130
| 9.0 | Kubernetes main repo, 1.13 branch ||
132131
| 10.0 Alpha/Beta | Kubernetes main repo, 1.14 branch ||
133132

134-
135133
Key:
136134

137135
* `` Changes in main Kubernetes repo are manually ([should be automated](https://github.com/kubernetes-client/python/issues/177)) published to client-python when they are available.
@@ -151,11 +149,10 @@ Participation in the Kubernetes community is governed by the [CNCF Code of Condu
151149

152150
## Kubernetes Incubator
153151

154-
This is a [Kubernetes Incubator project](https://github.com/kubernetes/community/blob/master/incubator.md).
152+
This is a [Kubernetes Incubator project](https://github.com/kubernetes/community/blob/master/incubator.md).
155153

156154
* [SIG: sig-api-machinery](https://github.com/kubernetes/community/tree/master/sig-api-machinery)
157155

158-
159156
## Troubleshooting
160157

161158
### SSLError on macOS
@@ -179,10 +176,11 @@ You'll need a version with OpenSSL version 1.0.0 or later.
179176

180177
### Hostname doesn't match
181178

182-
If you get an `ssl.CertificateError` complaining about hostname match, your installed packages does not meet version [requirements](requirements.txt).
179+
If you get an `ssl.CertificateError` complaining about hostname match, your installed packages does not meet version [requirements](requirements.txt).
183180
Specifically check `ipaddress` and `urllib3` package versions to make sure they met requirements in [requirements.txt](requirements.txt) file.
184181

185182
### Why Exec/Attach calls doesn't work
183+
186184
Starting from 4.0 release, we do not support directly calling exec or attach calls. you should use stream module to call them. so instead
187185
of `resp = api.connect_get_namespaced_pod_exec(name, ...` you should call `resp = stream(api.connect_get_namespaced_pod_exec, name, ...`.
188186
See more at [exec example](examples/exec.py).

devel/release.md

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
# Release process
22

3-
Release process of python client involve creating (or updating) a release
4-
branch, update release tags, create distribution packages and upload them to
5-
pip.
3+
The release process of the python client involves creating (or updating) a release
4+
branch, updating release tags, and creating distribution packages and uploading them to
5+
pypi.
66

77
## Change logs
8-
Make sure changes logs are up to date [here](https://github.com/kubernetes-client/python/blob/master/CHANGELOG.md).
9-
If they are not, follow commits added after last release and update/commit
8+
Make sure the change logs are up to date [here](https://github.com/kubernetes-client/python/blob/master/CHANGELOG.md).
9+
If they are not, follow commits added after the last release and update/commit
1010
the change logs to master.
1111

1212
Then based on the release, follow one of next two steps.
1313

1414
## Update pre-release branch
1515

16-
Release branch name should have release-x.x format. All minor and pre-releases
17-
should be on the same branch. To update an existing branch with master(only for
16+
The release branch name should have release-x.x format. All minor and pre-releases
17+
should be on the same branch. To update an existing branch with master (only for
1818
latest pre-release):
1919

2020
```bash
@@ -37,8 +37,8 @@ cherry pick first:
3737
scripts/cherry_pick_pull.sh
3838
```
3939

40-
Do not merge master into an stable releast branch. Run the script without
41-
parameters and follow its instruction to create cherry pick PR and get the
40+
Do not merge master into a stable release branch. Run the script without
41+
parameters and follow its instructions to create a cherry pick PR. Get the
4242
PR merged then update your local branch:
4343

4444
```bash
@@ -49,26 +49,27 @@ git rebase upstream/$RELEASE_BRANCH
4949
```
5050

5151
## Sanity check generated client
52-
We need to make sure there is no API changes after running update client
53-
scripts. Such changes should be committed to master branch first. Run this
52+
53+
We need to make sure there are no API changes after running update client
54+
scripts. Such changes should be committed to the master branch first. Run this
5455
command:
5556

5657
```bash
5758
scripts/update-client.sh
5859
```
5960

6061
And make sure there is no API change (version number changes should be fine
61-
as they will be updated in next step anyway). Do not commit any changes at
62-
this step and go back to master branch if there is any API changes.
62+
as they will be updated in the next step anyway). Do not commit any changes at
63+
this step and go back to the master branch if there are any API changes.
6364

6465
## Update release tags
6566

66-
Release tags are in scripts/constants.py file. These are the constants you may
67+
Release tags are in the "scripts/constants.py" file. These are the constants you may
6768
need to update:
6869

6970
CLIENT_VERSION: Client version should follow x.y.zDn where x,y,z are version
7071
numbers (integers) and D is one of "a" for alpha or "b" for beta and n is the
71-
pre-release number. For a final release, "Dn" part should be omitted. Examples:
72+
pre-release number. For a final release, the "Dn" part should be omitted. Examples:
7273
1.0.0a1, 2.0.1b2, 1.5.1.
7374

7475
DEVELOPMENT_STATUS: Update it to one of the values of "Development Status"
@@ -89,8 +90,9 @@ git push upstream $RELEASE_BRANCH
8990
```
9091

9192
## Make distribution packages
93+
9294
First make sure you are using a clean version of python. Use virtualenv and
93-
pyenv packages, make sure you are using python 2.7.12. I would normally do this
95+
pyenv packages. Make sure you are using python 2.7.12. I would normally do this
9496
on a clean machine:
9597

9698
(install [pyenv](https://github.com/yyuu/pyenv#installation))
@@ -128,9 +130,9 @@ python setup.py bdist_wheel --universal
128130
ls dist/
129131
```
130132

131-
You should see two files in dist folder. kubernetes\*.whl and kubernetes\*.tar.gz.
133+
You should see two files in dist folder: "kubernetes\*.whl" and "kubernetes\*.tar.gz".
132134

133-
TODO: We need a dry-run option an some way to test package upload process to pypi.
135+
TODO: We need a dry-run option and some way to test the package upload process to pypi.
134136

135137
If everything looks good, run this command to upload packages to pypi:
136138

@@ -142,13 +144,13 @@ twine upload dist/*
142144

143145
Create a gihub release by starting from
144146
[this page](https://github.com/kubernetes-client/python/releases).
145-
Click Deaft new release button. Name the tag the same as CLIENT_VERSION. Change
147+
Click the `Draft a new release button`. Name the tag the same as CLIENT_VERSION. Change
146148
the target branch to "release-x.y". If the release is a pre-release, check the
147149
`This is a pre-release` option.
148150

149-
150151
## Announcement
151-
Send an announcement email to kubernetes-dev@googlegroups.com with the subject [ANNOUNCE] kubernetes python-client $VERSION is released
152+
153+
Send an announcement email to kubernetes-dev@googlegroups.com with the subject: [ANNOUNCE] kubernetes python-client $VERSION is released
152154

153155
## Cleanup
154156

@@ -159,5 +161,4 @@ rm -rf .release
159161

160162
TODO: Convert steps in this document to an (semi-) automated script.
161163

162-
163164
ref: https://packaging.python.org/distributing/

devel/stats.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,3 @@ LIMIT 20
2323
More example queries can be found [here](https://gist.github.com/alex/4f100a9592b05e9b4d63)
2424

2525
Reference: https://mail.python.org/pipermail/distutils-sig/2016-May/028986.html
26-

devel/submodules.md

Lines changed: 8 additions & 6 deletions
22
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
# Submodules
2+
23
To comply with [client library structure requirement](https://github.com/kubernetes/community/blob/master/contributors/design-proposals/api-machinery/csi-client-structure-proposal.md),
3-
python client base utilities is moved into kubernetes-client/python-base repo. `git submodules` is being used to handle dependency to that repo.
4-
This document will provide basic steps to get submodules work.
4+
python client base utilities is moved into the [kubernetes-client/python-base](https://github.com/kubernetes-client/python-base) repo. `git submodules` is being used to handle dependency to that repo.
5+
This document will provide basic steps to get submodules working.
56

67
# Clone repo
7-
To clone repo, you need to pass `recursive` parameter to make the clone also get submodules:
8+
9+
To clone the repo, you need to pass the `recursive` parameter to make the clone also get submodules:
810

911
```bash
1012
git clone --recursive https://github.com/kubernetes-client/python.git
1113
```
1214

13-
if you already clone repo with no `--recursive` option, you can run this command to get submodules:
15+
if you have already cloned the repo with no `--recursive` option, you can run this command to get submodules:
1416

1517
```bash
1618
git submodule update --init
1719
```
1820

1921
# Update submodule
20-
If you changed kubernetes-client/python-base and want to pull your changes into this repo run this command:
22+
23+
If you changed [kubernetes-client/python-base](https://github.com/kubernetes-client/python-base) and want to pull your changes into this repo run this command:
2124

25
```bash
2326
git submodule update --remote
2427
```
2528

2629
Once updated, you should create a new PR to commit changes to the repository.
27-

kubernetes/base

kubernetes/e2e_test/test_utils.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,17 @@ class TestUtils(unittest.TestCase):
2626
def setUpClass(cls):
2727
cls.config = base.get_e2e_configuration()
2828
cls.path_prefix = "kubernetes/e2e_test/test_yaml/"
29+
cls.test_namespace = "e2e-test-utils"
30+
k8s_client = client.api_client.ApiClient(configuration=cls.config)
31+
core_v1 = client.CoreV1Api(api_client=k8s_client)
32+
body = client.V1Namespace(metadata=client.V1ObjectMeta(name=cls.test_namespace))
33+
core_v1.create_namespace(body=body)
2934

35+
@classmethod
36+
def tearDownClass(cls):
37+
k8s_client = client.api_client.ApiClient(configuration=cls.config)
38+
core_v1 = client.CoreV1Api(api_client=k8s_client)
39+
core_v1.delete_namespace(name=cls.test_namespace)
3040
# Tests for creating individual API objects
3141

3242
def test_create_apps_deployment_from_yaml(self):
@@ -376,3 +386,44 @@ def test_create_from_multi_resource_yaml_with_multi_conflicts(self):
376386
ext_api.delete_namespaced_deployment(
377387
name="triple-nginx", namespace="default",
378388
body={})
389+
390+
def test_create_namespaces_apps_deployment_from_yaml(self):
391+
"""
392+
Should be able to create an apps/v1beta1 deployment.
393+
"""
394+
k8s_client = client.api_client.ApiClient(configuration=self.config)
395+
utils.create_from_yaml(
396+
k8s_client, self.path_prefix + "apps-deployment.yaml", namespace=self.test_namespace)
397+
app_api = client.AppsV1beta1Api(k8s_client)
398+
dep = app_api.read_namespaced_deployment(name="nginx-app",
399+
namespace=self.test_namespace)
400+
self.assertIsNotNone(dep)
401+
app_api.delete_namespaced_deployment(
402+
name="nginx-app", namespace=self.test_namespace,
403+
body={})
404+
405+
def test_create_from_list_in_multi_resource_yaml(self):
406+
"""
407+
Should be able to create the items in the PodList and a deployment
408+
specified in the multi-resource file
409+
"""
410+
k8s_client = client.api_client.ApiClient(configuration=self.config)
411+
utils.create_from_yaml(
412+
k8s_client, self.path_prefix + "multi-resource-with-list.yaml", namespace=self.test_namespace)
413+
core_api = client.CoreV1Api(k8s_client)
414+
app_api = client.AppsV1beta1Api(k8s_client)
415+
pod_0 = core_api.read_namespaced_pod(
416+
name="mock-pod-0", namespace=self.test_namespace)
417+
self.assertIsNotNone(pod_0)
418+
pod_1 = core_api.read_namespaced_pod(
419+
name="mock-pod-1", namespace=self.test_namespace)
420+
self.assertIsNotNone(pod_1)
421+
dep = app_api.read_namespaced_deployment(
422+
name="mock", namespace=self.test_namespace)
423+
self.assertIsNotNone(dep)
424+
core_api.delete_namespaced_pod(
425+
name="mock-pod-0", namespace=self.test_namespace, body={})
426+
core_api.delete_namespaced_pod(
427+
name="mock-pod-1", namespace=self.test_namespace, body={})
428+
app_api.delete_namespaced_deployment(
429+
name="mock", namespace=self.test_namespace, body={})

kubernetes/utils/create_from_yaml.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
15+
1416
import re
1517
import sys
1618
from os import path
@@ -29,15 +31,26 @@ def create_from_yaml(
2931
k8s_client,
3032
yaml_file,
3133
verbose=False,
34+
namespace="default",
3235
**kwargs):
3336
"""
3437
Perform an action from a yaml file. Pass True for verbose to
3538
print confirmation information.
3639
Input:
37-
yaml_file: string. Contains yaml string or a path to yaml file.
40+
yaml_file: string. Contains the path to yaml file.
3841
k8s_client: an ApiClient object, initialized with the client args.
3942
verbose: If True, print confirmation from the create action.
4043
Default is False.
44+
namespace: string. Contains the namespace to create all
45+
resources inside. The namespace must preexist otherwise
46+
the resource creation will fail. If the API object in
47+
the yaml file already contains a namespace definition
48+
this parameter has no effect.
49+
50+
Returns:
51+
An k8s api object or list of apis objects created from YAML.
52+
When a single object is generated, return type is dependent
53+
on output_list.
4154
4255
Throws a FailToCreateError exception if creation of any object
4356
fails with helpful messages from the server.

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ certifi>=14.05.14 # MPL
22
six>=1.9.0 # MIT
33
python-dateutil>=2.5.3 # BSD
44
setuptools>=21.0.0 # PSF/ZPL
5-
urllib3>=1.23 # MIT
65
pyyaml>=3.12 # MIT
76
google-auth>=1.0.1 # Apache-2.0
87
ipaddress>=1.0.17;python_version=="2.7" # PSF
98
websocket-client>=0.32.0,!=0.40.0,!=0.41.*,!=0.42.* # LGPLv2+
109
requests # Apache-2.0
1110
requests-oauthlib # ISC
11+
urllib3>=1.23 # MIT

0 commit comments

Comments
 (0)
0