Skip to content

Commit c3f1a1c

Browse files
authored
Merge pull request #1435 from Priyankasaggu11929/psaggu-enhance_node_labels_example
simplify & enhance the node_labels.py example
2 parents b5fedc3 + 60e8c89 commit c3f1a1c

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

examples/node_labels.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@
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

2526

@@ -36,9 +37,14 @@ def main():
3637
}
3738
}
3839

39-
api_response = api_instance.patch_node("minikube", body)
40+
# Listing the cluster nodes
41+
node_list = api_instance.list_node()
4042

41-
pprint(api_response)
43+
print("%s\t\t%s" % ("NAME", "LABELS"))
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)