From cd8e17fe4fe91d728c1e48b7fac5ba3cf820a491 Mon Sep 17 00:00:00 2001 From: FingerLiu <524570375@qq.com> Date: Thu, 28 Sep 2017 11:06:15 +0800 Subject: [PATCH 1/2] Add example to patch a deployment add example in issue #347 --- examples/patch_deployment.py | 52 ++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 examples/patch_deployment.py diff --git a/examples/patch_deployment.py b/examples/patch_deployment.py new file mode 100644 index 0000000000..be5eaa3dfe --- /dev/null +++ b/examples/patch_deployment.py @@ -0,0 +1,52 @@ +# Copyright 2016 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from pprint import pprint + +from kubernetes import client, config + + +def main(): + """ + Update image of container1 in deployment deploy1: + """ + # Configs can be set in Configuration class directly or using helper + # utility. If no argument provided, the config will be loaded from + # default location. + config.load_kube_config() + + api_instance = client.AppsV1beta1Api() + + body = { + "spec": { + "template": { + "spec": { + "containers": [ + { + "name": "container1", + "image":"gcr.io/xxx/image:tag" + } + ] + } + } + } + } + + api_response = api_instance.patch_namespaced_deployment('deploy1', 'default', body, pretty=True) + + pprint(api_response) + + +if __name__ == '__main__': + main() From 3c5cf310c1cf63525a1adeed9b5b23d4fad633a7 Mon Sep 17 00:00:00 2001 From: FingerLiu <524570375@qq.com> Date: Thu, 28 Sep 2017 11:19:19 +0800 Subject: [PATCH 2/2] fix pep8 fix pep8 --- examples/patch_deployment.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/patch_deployment.py b/examples/patch_deployment.py index be5eaa3dfe..7352af5c65 100644 --- a/examples/patch_deployment.py +++ b/examples/patch_deployment.py @@ -35,7 +35,7 @@ def main(): "containers": [ { "name": "container1", - "image":"gcr.io/xxx/image:tag" + "image": "gcr.io/xxx/image:tag" } ] } @@ -43,7 +43,8 @@ def main(): } } - api_response = api_instance.patch_namespaced_deployment('deploy1', 'default', body, pretty=True) + api_response = api_instance.patch_namespaced_deployment( + 'deploy1', 'default', body, pretty=True) pprint(api_response)