Skip to content

Commit 0e37654

Browse files
simplify & enhance the node_labels.py example
1 parent e2aad06 commit 0e37654

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

examples/node_labels.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
# limitations under the License.
1414

1515
"""
16-
Changes the labels of the "minikube" node. Adds the label "foo" with value
17-
"bar" and will overwrite the "foo" label if it already exists. Removes the
18-
label "baz".
16+
This example demonstrates the following:
17+
- Get a list of all the cluster nodes
18+
- Iterate through each node list item
19+
- Add or overwirite label "foo" with the value "bar"
20+
- Remove the label "baz"
21+
- Return the list of node with updated labels
1922
"""
2023

21-
from pprint import pprint
22-
2324
from kubernetes import client, config
2425

25-
2626
def main():
2727
config.load_kube_config()
2828

@@ -35,10 +35,16 @@ def main():
3535
"baz": None}
3636
}
3737
}
38-
39-
api_response = api_instance.patch_node("minikube", body)
40-
41-
pprint(api_response)
38+
39+
# Creating a list of cluster nodes
40+
node_list = api_instance.list_node()
41+
42+
print("%s\t\t%s" % ("NAME", "LABELS"))
43+
44+
# Patching the node labels
45+
for node in node_list.items:
46+
api_response = api_instance.patch_node(node.metadata.name, body)
47+
print("%s\t%s" % (node.metadata.name, node.metadata.labels))
4248

4349

4450
if __name__ == '__main__':

0 commit comments

Comments
 (0)