Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 054edcf

Browse files
committed
Merge branch 'master' of github.com:kubernetes-incubator/client-python into release-1.0
2 parents a498649 + 436351b commit 054edcf

File tree

15 files changed

+873
-147
lines changed

15 files changed

+873
-147
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
# v1.0.0b2
2+
- Support exec calls in both interactive and non-interactive mode #58
3+
4+
# v1.0.0b1
5+
6+
- Support insecure-skip-tls-verify config flag #99
7+
- Added example for using yaml files as models #63
8+
- Added end to end tests #41, #94
9+
- Bugfix: Fix ValueError in list_namespaced_config_map #104
10+
- Bugfix: Export missing models #101
11+
- Bugfix: Patch operations #93
12+
113
# v1.0.0a5
214

315
- Bugfix: Missing fields in some models #85, kubernetes/kubernetes#39465

devel/release.md

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# Release process
2+
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.
6+
7+
## Change logs
8+
Make sure changes logs are up to date [here](https://github.com/kubernetes-incubator/client-python/blob/master/CHANGELOG.md).
9+
If they are not, follow commits added after last release and update/commit
10+
the change logs to master.
11+
12+
## Release branch
13+
14+
Release branch name should have release-x.x format. All minor and pre-releases
15+
should be on the same branch. To update an existing branch:
16+
17+
```bash
18+
export RELEASE_BRANCH=release-x.x
19+
git checkout RELEASE_BRANCH
20+
git fetch upstream
21+
git pull upstream/master
22+
git push origin RELEASE_BRANCH
23+
```
24+
25+
You may need to fix some conflicts. For auto-generated files, you can commit
26+
either version. They will be updated to the current version in the next step.
27+
28+
## Sanity check generated client
29+
We need to make sure there is no API changes after running update client
30+
scripts. Such changes should be committed to master branch first. Run this
31+
command:
32+
33+
```bash
34+
scripts/update-client.sh
35+
```
36+
37+
And make sure there is no API change (version number changes should be fine
38+
as they will be updated in next step anyway). Do not commit any changes at
39+
this step and go back to master branch if there is any API changes.
40+
41+
## Update release tags
42+
43+
Release tags are in scripts/constants.py file. These are the constants you may
44+
need to update:
45+
46+
CLIENT_VERSION: Client version should follow x.y.zDn where x,y,z are version
47+
numbers (integers) and D is one of "a" for alpha or "b" for beta and n is the
48+
pre-release number. For a final release, "Dn" part should be omitted. Examples:
49+
1.0.0a1, 2.0.1b2, 1.5.1
50+
SPEC_VERSION: This would be the kubernetes OpenAPI spec version. It should be
51+
deprecated after kubernetes/kubernetes#37055 takes effect.
52+
DEVELOPMENT_STATUS: Update it to one of the values of "Development Status"
53+
in [this list](https://pypi.python.org/pypi?%3Aaction=list_classifiers).
54+
55+
after changing constants to proper versions, update the client using this
56+
command:
57+
58+
```bash
59+
scripts/update-client.sh
60+
```
61+
62+
and commit changes (should be only version number changes) to the release branch.
63+
Name the commit something like "Update version constants for XXX release".
64+
65+
```bash
66+
git push upstream RELEASE_BRANCH
67+
```
68+
69+
## Make distribution packages
70+
First make sure you are using a clean version of python. Use virtualenv and
71+
pyenv packages, make sure you are using python 2.7.12. I would normally do this
72+
on a clean machine:
73+
74+
(install [pyenv](https://github.com/yyuu/pyenv#installation))
75+
(install [pip](https://pip.pypa.io/en/stable/installing/))
76+
(install [virtualenv](https://virtualenv.pypa.io/en/stable/installation/))
77+
78+
```bash
79+
git clean -xdf
80+
pyenv install 2.7.12
81+
pyenv global 2.7.12
82+
virtualenv .release
83+
source .release/bin/activate
84+
python --version # Make sure you get Python 2.7.12
85+
pip install twine
86+
```
87+
88+
Now we need to create a "~/.pypirc" with this content:
89+
90+
```
91+
[distutils]
92+
index-servers=pypi
93+
94+
[pypi]
95+
repository = https://upload.pypi.org/legacy/
96+
username = kubernetes
97+
```
98+
99+
TODO: we should be able to pass these parameters to twine directly. My first attempt failed.
100+
101+
Now that the environment is ready, lets create distribution packages:
102+
103+
```bash
104+
python setup.py sdist
105+
python setup.py bdist_wheel --universal
106+
ls dist/
107+
```
108+
109+
You should see two files in dist folder. kubernetes*.whl and kubernetes*.tar.gz.
110+
111+
TODO: We need a dry-run option an some way to test package upload process to pypi.
112+
113+
If everything looks good, run this command to upload packages to pypi:
114+
115+
```
116+
twine upload dist/*
117+
```
118+
119+
## Create github release
120+
121+
Create a gihub release by starting from
122+
[this page(https://github.com/kubernetes-incubator/client-python/releases).
123+
Click Deaft new release button. Name the tag the same as CLIENT_VERSION. Change
124+
the target branch to "release-x.y"
125+
126+
127+
ref: https://packaging.python.org/distributing/
128+
129+
## Cleanup
130+
131+
```bash
132+
deactivate
133+
rm -rf .release
134+
```
135+
136+
TODO: Convert steps in this document to an (semi-) automated script.

devel/stats.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Download Statistics
2+
3+
Pypi stores download information in a [BigQuery public dataset](https://bigquery.cloud.google.com/dataset/the-psf:pypi). It can be queried to get detail infomration about downloads. For example, to get number of downloads per version, you can run this query:
4+
5+
```sql
6+
SELECT
7+
file.version,
8+
COUNT(*) as total_downloads,
9+
FROM
10+
TABLE_DATE_RANGE(
11+
[the-psf:pypi.downloads],
12+
TIMESTAMP("20161120"),
13+
CURRENT_TIMESTAMP()
14+
)
15+
where file.project == "kubernetes"
16+
GROUP BY
17+
file.version
18+
ORDER BY
19+
total_downloads DESC
20+
LIMIT 20
21+
```
22+
23+
More example queries can be found [here](https://gist.github.com/alex/4f100a9592b05e9b4d63)
24+
25+
Reference: https://mail.python.org/pipermail/distutils-sig/2016-May/028986.html
26+

examples/exec.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import time
2+
3+
from kubernetes import config
4+
from kubernetes.client import configuration
5+
from kubernetes.client.apis import core_v1_api
6+
from kubernetes.client.rest import ApiException
7+
8+
config.load_kube_config()
9+
configuration.assert_hostname = False
10+
api = core_v1_api.CoreV1Api()
11+
name = 'busybox-test'
12+
13+
resp = None
14+
try:
15+
resp = api.read_namespaced_pod(name=name,
16+
namespace='default')
17+
except ApiException as e:
18+
if e.status != 404:
19+
print("Unknown error: %s" % e)
20+
exit(1)
21+
22+
if not resp:
23+
print("Pod %s does not exits. Creating it..." % name)
24+
pod_manifest = {
25+
'apiVersion': 'v1',
26+
'kind': 'Pod',
27+
'metadata': {
28+
'name': name
29+
},
30+
'spec': {
31+
'containers': [{
32+
'image': 'busybox',
33+
'name': 'sleep',
34+
"args": [
35+
"/bin/sh",
36+
"-c",
37+
"while true;do date;sleep 5; done"
38+
]
39+
}]
40+
}
41+
}
42+
resp = api.create_namespaced_pod(body=pod_manifest,
43+
namespace='default')
44+
while True:
45+
resp = api.read_namespaced_pod(name=name,
46+
namespace='default')
47+
if resp.status.phase != 'Pending':
48+
break
49+
time.sleep(1)
50+
print("Done.")
51+
52+
53+
# calling exec and wait for response.
54+
exec_command = [
55+
'/bin/sh',
56+
'-c',
57+
'echo This message goes to stderr >&2; echo This message goes to stdout']
58+
resp = api.connect_get_namespaced_pod_exec(name, 'default',
59+
command=exec_command,
60+
stderr=True, stdin=False,
61+
stdout=True, tty=False)
62+
print("Response: " + resp)
63+
64+
# Calling exec interactively.
65+
exec_command = ['/bin/sh']
66+
resp = api.connect_get_namespaced_pod_exec(name, 'default',
67+
command=exec_command,
68+
stderr=True, stdin=True,
69+
stdout=True, tty=False,
70+
71+
_preload_content=False)
72+
commands = [
73+
"echo test1",
74+
"echo \"This message goes to stderr\" >&2",
75+
]
76+
while resp.is_open():
77+
resp.update(timeout=1)
78+
if resp.peek_stdout():
79+
print("STDOUT: %s" % resp.read_stdout())
80+
if resp.peek_stderr():
81+
print("STDERR: %s" % resp.read_stderr())
82+
if commands:
83+
c = commands.pop(0)
84+
print("Running command... %s\n" % c)
85+
resp.write_stdin(c + "\n")
86+
else:
87+
break
88+
89+
resp.write_stdin("date\n")
90+
sdate = resp.readline_stdout(timeout=3)
91+
print("Server date command returns: %s" % sdate)
92+
resp.write_stdin("whoami\n")
93+
user = resp.readline_stdout(timeout=3)
94+
print("Server user is: %s" % user)

kubernetes/client/api_client.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from __future__ import absolute_import
2222

2323
from . import models
24+
from . import ws_client
2425
from .rest import RESTClientObject
2526
from .rest import ApiException
2627

@@ -343,6 +344,15 @@ def request(self, method, url, query_params=None, headers=None,
343344
"""
344345
Makes the HTTP request using RESTClient.
345346
"""
347+
# FIXME(dims) : We need a better way to figure out which
348+
# calls end up using web sockets
349+
if url.endswith('/exec') and (method == "GET" or method == "POST"):
350+
return ws_client.websocket_call(self.config,
351+
url,
352+
query_params=query_params,
353+
_request_timeout=_request_timeout,
354+
_preload_content=_preload_content,
355+
headers=headers)
346356
if method == "GET":
347357
return self.rest_client.GET(url,
348358
query_params=query_params,

kubernetes/client/configuration.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ def __init__(self):
8585
self.cert_file = None
8686
# client key file
8787
self.key_file = None
88+
# check host name
89+
# Set this to True/False to enable/disable SSL hostname verification.
90+
self.assert_hostname = None
8891

8992
@property
9093
def logger_file(self):

kubernetes/client/rest.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,20 @@ def __init__(self, pools_size=4, config=configuration):
9595
# key file
9696
key_file = config.key_file
9797

98+
kwargs = {
99+
'num_pools': pools_size,
100+
'cert_reqs': cert_reqs,
101+
'ca_certs': ca_certs,
102+
'cert_file': cert_file,
103+
'key_file': key_file,
104+
}
105+
106+
if config.assert_hostname is not None:
107+
kwargs['assert_hostname'] = config.assert_hostname
108+
98109
# https pool manager
99110
self.pool_manager = urllib3.PoolManager(
100-
num_pools=pools_size,
101-
cert_reqs=cert_reqs,
102-
ca_certs=ca_certs,
103-
cert_file=cert_file,
104-
key_file=key_file
111+
**kwargs
105112
)
106113

107114
def request(self, method, url, query_params=None, headers=None,

0 commit comments

Comments
 (0)