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

Skip to content

Commit b538f20

Browse files
committed
Merge branch 'master' of github.com:kubernetes-client/python into release-8.0
2 parents b12fcd2 + 4c4b019 commit b538f20

23 files changed

+464
-54
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ref: https://docs.travis-ci.com/user/languages/python
22
language: python
3-
dist: trusty
3+
dist: xenial
44
sudo: true
55
services:
66
- docker
@@ -12,7 +12,7 @@ matrix:
1212
- python: 2.7
1313
env: TOXENV=py27-functional
1414
- python: 2.7
15-
env: TOXENV=update-pep8
15+
env: TOXENV=update-pycodestyle
1616
- python: 2.7
1717
env: TOXENV=docs
1818
- python: 2.7

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# v8.0.0
2+
**New Feature:**
3+
- Add utility to create API resource from yaml file [kubernetes-client/python#655](https://github.com/kubernetes-client/python/pull/655)
4+
15
# v8.0.0b1
26
**Bug Fix:**
37
- Update ExecProvider to use safe\_get() to tolerate kube-config file that sets

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,13 @@ between client-python versions.
118118
| 4.0 Alpha/Beta | Kubernetes main repo, 1.8 branch ||
119119
| 4.0 | Kubernetes main repo, 1.8 branch ||
120120
| 5.0 Alpha/Beta | Kubernetes main repo, 1.9 branch ||
121-
| 5.0 | Kubernetes main repo, 1.9 branch | |
121+
| 5.0 | Kubernetes main repo, 1.9 branch | |
122122
| 6.0 Alpha/Beta | Kubernetes main repo, 1.10 branch ||
123123
| 6.0 | Kubernetes main repo, 1.10 branch ||
124124
| 7.0 Alpha/Beta | Kubernetes main repo, 1.11 branch ||
125125
| 7.0 | Kubernetes main repo, 1.11 branch ||
126-
| 8.0 Alpha/Beta | Kubernetes main repo, 1.12 branch ||
126+
| 8.0 Alpha/Beta | Kubernetes main repo, 1.12 branch ||
127+
| 8.0 | Kubernetes main repo, 1.12 branch ||
127128

128129

129130
Key:
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright 2018 The Kubernetes Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from os import path
16+
17+
from kubernetes import client, config, utils
18+
19+
20+
def main():
21+
# Configs can be set in Configuration class directly or using helper
22+
# utility. If no argument provided, the config will be loaded from
23+
# default location.
24+
config.load_kube_config()
25+
k8s_client = client.ApiClient()
26+
k8s_api = utils.create_from_yaml(k8s_client, "nginx-deployment.yaml")
27+
deps = k8s_api.read_namespaced_deployment("nginx-deployment", "default")
28+
print("Deployment {0} created".format(deps.metadata.name))
29+
30+
31+
if __name__ == '__main__':
32+
main()

examples/remote_cluster.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Copyright 2018 The Kubernetes Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# This example demonstrate communication with a remote Kube cluster from a
16+
# server outside of the cluster without kube client installed on it.
17+
# The communication is secured with the use of Bearer token.
18+
19+
from kubernetes import client, config
20+
21+
22+
def main():
23+
# Define the barer token we are going to use to authenticate.
24+
# See here to create the token:
25+
# https://kubernetes.io/docs/tasks/access-application-cluster/access-cluster/
26+
aToken = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
27+
28+
# Create a configuration object
29+
aConfiguration = client.Configuration()
30+
31+
# Specify the endpoint of your Kube cluster
32+
aConfiguration.host = "https://XXX.XXX.XXX.XXX:443"
33+
34+
# Security part.
35+
# In this simple example we are not going to verify the SSL certificate of
36+
# the remote cluster (for simplicity reason)
37+
aConfiguration.verify_ssl = False
38+
# Nevertheless if you want to do it you can with these 2 parameters
39+
# configuration.verify_ssl=True
40+
# ssl_ca_cert is the filepath to the file that contains the certificate.
41+
# configuration.ssl_ca_cert="certificate"
42+
43+
aConfiguration.api_key = {"authorization": "Bearer " + aToken}
44+
45+
# Create a ApiClient with our config
46+
aApiClient = client.ApiClient(aConfiguration)
47+
48+
# Do calls
49+
v1 = client.CoreV1Api(aApiClient)
50+
print("Listing pods with their IPs:")
51+
ret = v1.list_pod_for_all_namespaces(watch=False)
52+
for i in ret.items:
53+
print("%s\t%s\t%s" %
54+
(i.status.pod_ip, i.metadata.namespace, i.metadata.name))
55+
56+
57+
if __name__ == '__main__':
58+
main()

kubernetes/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@
2020
import kubernetes.config
2121
import kubernetes.watch
2222
import kubernetes.stream
23+
import kubernetes.utils

kubernetes/base

Submodule base updated 1 file

kubernetes/e2e_test/test_utils.py

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
15+
import unittest
16+
17+
from kubernetes import utils, client
18+
from kubernetes.e2e_test import base
19+
20+
class TestUtils(unittest.TestCase):
21+
22+
@classmethod
23+
def setUpClass(cls):
24+
cls.config = base.get_e2e_configuration()
25+
26+
def test_app_yaml(self):
27+
k8s_client = client.api_client.ApiClient(configuration=self.config)
28+
k8s_api = utils.create_from_yaml(k8s_client,
29+
"kubernetes/e2e_test/test_yaml/apps-deployment.yaml")
30+
self.assertEqual("apps/v1beta1",
31+
k8s_api.get_api_resources().group_version)
32+
dep = k8s_api.read_namespaced_deployment(name="nginx-app",
33+
namespace="default")
34+
self.assertIsNotNone(dep)
35+
resp = k8s_api.delete_namespaced_deployment(
36+
name="nginx-app", namespace="default",
37+
body={})
38+
39+
def test_extension_yaml(self):
40+
k8s_client = client.api_client.ApiClient(configuration=self.config)
41+
k8s_api = utils.create_from_yaml(k8s_client,
42+
"kubernetes/e2e_test/test_yaml/extensions-deployment.yaml")
43+
self.assertEqual("extensions/v1beta1",
44+
k8s_api.get_api_resources().group_version)
45+
dep = k8s_api.read_namespaced_deployment(name="nginx-deployment",
46+
namespace="default")
47+
self.assertIsNotNone(dep)
48+
resp = k8s_api.delete_namespaced_deployment(
49+
name="nginx-deployment", namespace="default",
50+
body={})
51+
52+
def test_core_pod_yaml(self):
53+
k8s_client = client.api_client.ApiClient(configuration=self.config)
54+
k8s_api = utils.create_from_yaml(k8s_client,
55+
"kubernetes/e2e_test/test_yaml/core-pod.yaml")
56+
self.assertEqual("v1",
57+
k8s_api.get_api_resources().group_version)
58+
pod = k8s_api.read_namespaced_pod(name="myapp-pod",
59+
namespace="default")
60+
self.assertIsNotNone(pod)
61+
resp = k8s_api.delete_namespaced_pod(
62+
name="myapp-pod", namespace="default",
63+
body={})
64+
65+
def test_core_service_yaml(self):
66+
k8s_client = client.api_client.ApiClient(configuration=self.config)
67+
k8s_api = utils.create_from_yaml(k8s_client,
68+
"kubernetes/e2e_test/test_yaml/core-service.yaml")
69+
self.assertEqual("v1",
70+
k8s_api.get_api_resources().group_version)
71+
svc = k8s_api.read_namespaced_service(name="my-service",
72+
namespace="default")
73+
self.assertIsNotNone(svc)
74+
resp = k8s_api.delete_namespaced_service(
75+
name="my-service", namespace="default",
76+
body={})
77+
78+
def test_core_namespace_yaml(self):
79+
k8s_client = client.api_client.ApiClient(configuration=self.config)
80+
k8s_api = utils.create_from_yaml(k8s_client,
81+
"kubernetes/e2e_test/test_yaml/core-namespace.yaml")
82+
self.assertEqual("v1",
83+
k8s_api.get_api_resources().group_version)
84+
nmsp = k8s_api.read_namespace(name="development")
85+
self.assertIsNotNone(nmsp)
86+
resp = k8s_api.delete_namespace(name="development", body={})
87+
88+
def test_deployment_in_namespace(self):
89+
k8s_client = client.ApiClient(configuration=self.config)
90+
core_api = utils.create_from_yaml(k8s_client,
91+
"kubernetes/e2e_test/test_yaml/core-namespace-dep.yaml")
92+
self.assertEqual("v1",
93+
core_api.get_api_resources().group_version)
94+
nmsp = core_api.read_namespace(name="dep")
95+
self.assertIsNotNone(nmsp)
96+
dep_api = utils.create_from_yaml(k8s_client,
97+
"kubernetes/e2e_test/test_yaml/extensions-deployment-dep.yaml")
98+
dep = dep_api.read_namespaced_deployment(name="nginx-deployment",
99+
namespace="dep")
100+
self.assertIsNotNone(dep)
101+
resp = dep_api.delete_namespaced_deployment(
102+
name="nginx-deployment", namespace="dep",
103+
body={})
104+
resp = core_api.delete_namespace(name="dep", body={})
105+
106+
def test_api_service(self):
107+
k8s_client = client.api_client.ApiClient(configuration=self.config)
108+
k8s_api = utils.create_from_yaml(k8s_client,
109+
"kubernetes/e2e_test/test_yaml/api-service.yaml")
110+
self.assertEqual("apiregistration.k8s.io/v1beta1",
111+
k8s_api.get_api_resources().group_version)
112+
svc = k8s_api.read_api_service(
113+
name="v1alpha1.wardle.k8s.io")
114+
self.assertIsNotNone(svc)
115+
resp = k8s_api.delete_api_service(
116+
name="v1alpha1.wardle.k8s.io", body={})
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: apiregistration.k8s.io/v1beta1
2+
kind: APIService
3+
metadata:
4+
name: v1alpha1.wardle.k8s.io
5+
spec:
6+
insecureSkipTLSVerify: true
7+
group: wardle.k8s.io
8+
groupPriorityMinimum: 1000
9+
versionPriority: 15
10+
service:
11+
name: api
12+
namespace: wardle
13+
version: v1alpha1
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: apps/v1beta1
2+
kind: Deployment
3+
metadata:
4+
name: nginx-app
5+
labels:
6+
app: nginx
7+
spec:
8+
replicas: 3
9+
selector:
10+
matchLabels:
11+
app: nginx
12+
template:
13+
metadata:
14+
labels:
15+
app: nginx
16+
spec:
17+
containers:
18+
- name: nginx
19+
image: nginx:1.15.4
20+
ports:
21+
- containerPort: 80
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v1
2+
kind: Namespace
3+
metadata:
4+
name: dep
5+
labels:
6+
name: dep
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v1
2+
kind: Namespace
3+
metadata:
4+
name: development
5+
labels:
6+
name: development
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: myapp-pod
5+
labels:
6+
app: myapp
7+
spec:
8+
containers:
9+
- name: myapp-container
10+
image: busybox
11+
command: ['sh', '-c', 'echo Hello Kubernetes! && sleep 3600']
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
kind: Service
2+
apiVersion: v1
3+
metadata:
4+
name: my-service
5+
spec:
6+
selector:
7+
app: MyApp
8+
ports:
9+
- protocol: TCP
10+
port: 80
11+
targetPort: 9376
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: extensions/v1beta1
2+
kind: Deployment
3+
metadata:
4+
name: nginx-deployment
5+
namespace: dep
6+
spec:
7+
replicas: 3
8+
template:
9+
metadata:
10+
labels:
11+
app: nginx
12+
spec:
13+
containers:
14+
- name: nginx
15+
image: nginx:1.7.9
16+
ports:
17+
- containerPort: 80
18+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: extensions/v1beta1
2+
kind: Deployment
3+
metadata:
4+
name: nginx-deployment
5+
spec:
6+
replicas: 3
7+
template:
8+
metadata:
9+
labels:
10+
app: nginx
11+
spec:
12+
containers:
13+
- name: nginx
14+
image: nginx:1.7.9
15+
ports:
16+
- containerPort: 80
17+

kubernetes/utils/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2018 The Kubernetes Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from .create_from_yaml import create_from_yaml

0 commit comments

Comments
 (0)