From 0e376546134fdab98a678ec055c164d45555ee70 Mon Sep 17 00:00:00 2001 From: Priyanka Saggu Date: Tue, 27 Apr 2021 21:04:42 +0530 Subject: [PATCH 1/5] simplify & enhance the node_labels.py example --- examples/node_labels.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/examples/node_labels.py b/examples/node_labels.py index 22ac3197a..70936eec0 100644 --- a/examples/node_labels.py +++ b/examples/node_labels.py @@ -13,16 +13,16 @@ # limitations under the License. """ -Changes the labels of the "minikube" node. Adds the label "foo" with value -"bar" and will overwrite the "foo" label if it already exists. Removes the -label "baz". +This example demonstrates the following: + - Get a list of all the cluster nodes + - Iterate through each node list item + - Add or overwirite label "foo" with the value "bar" + - Remove the label "baz" + - Return the list of node with updated labels """ -from pprint import pprint - from kubernetes import client, config - def main(): config.load_kube_config() @@ -35,10 +35,16 @@ def main(): "baz": None} } } + + # Creating a list of cluster nodes + node_list = api_instance.list_node() + + print("%s\t\t%s" % ("NAME", "LABELS")) - api_response = api_instance.patch_node("minikube", body) - - pprint(api_response) + # Patching the node labels + for node in node_list.items: + api_response = api_instance.patch_node(node.metadata.name, body) + print("%s\t%s" % (node.metadata.name, node.metadata.labels)) if __name__ == '__main__': From adac2e07062afe5639b6fd62616665725cfa8c1b Mon Sep 17 00:00:00 2001 From: Priyanka Saggu Date: Tue, 27 Apr 2021 22:42:51 +0530 Subject: [PATCH 2/5] improve comments --- examples/node_labels.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/node_labels.py b/examples/node_labels.py index 70936eec0..a4038d1a9 100644 --- a/examples/node_labels.py +++ b/examples/node_labels.py @@ -36,7 +36,7 @@ def main(): } } - # Creating a list of cluster nodes + # Listing the cluster nodes node_list = api_instance.list_node() print("%s\t\t%s" % ("NAME", "LABELS")) From 41d331f990d661f71275758335a912059442ef92 Mon Sep 17 00:00:00 2001 From: Priyanka Saggu Date: Wed, 28 Apr 2021 07:12:02 +0530 Subject: [PATCH 3/5] fix whitespaces --- examples/node_labels.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/node_labels.py b/examples/node_labels.py index a4038d1a9..7089b5acf 100644 --- a/examples/node_labels.py +++ b/examples/node_labels.py @@ -23,6 +23,7 @@ This example demonstrates the following: from kubernetes import client, config + def main(): config.load_kube_config() @@ -37,8 +38,7 @@ def main(): } # Listing the cluster nodes - node_list = api_instance.list_node() - + node_list = api_instance.list_node() print("%s\t\t%s" % ("NAME", "LABELS")) # Patching the node labels From b5d41cb3eb9438ad90db3f2d4a0b376be63a4e81 Mon Sep 17 00:00:00 2001 From: Priyanka Saggu Date: Wed, 28 Apr 2021 07:37:07 +0530 Subject: [PATCH 4/5] fix whitspaces --- examples/node_labels.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/node_labels.py b/examples/node_labels.py index 7089b5acf..462ff9868 100644 --- a/examples/node_labels.py +++ b/examples/node_labels.py @@ -38,9 +38,9 @@ def main(): } # Listing the cluster nodes - node_list = api_instance.list_node() + node_list = api_instance.list_node() + print("%s\t\t%s" % ("NAME", "LABELS")) - # Patching the node labels for node in node_list.items: api_response = api_instance.patch_node(node.metadata.name, body) From 60e8c895a5ca0fe639739cfd8708564eb357f53b Mon Sep 17 00:00:00 2001 From: Priyanka Saggu Date: Wed, 28 Apr 2021 22:09:40 +0530 Subject: [PATCH 5/5] Update node_labels.py --- examples/node_labels.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/node_labels.py b/examples/node_labels.py index 462ff9868..f71c8126e 100644 --- a/examples/node_labels.py +++ b/examples/node_labels.py @@ -36,10 +36,10 @@ def main(): "baz": None} } } - + # Listing the cluster nodes node_list = api_instance.list_node() - + print("%s\t\t%s" % ("NAME", "LABELS")) # Patching the node labels for node in node_list.items: