File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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-
2324from 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
4450if __name__ == '__main__' :
You can’t perform that action at this time.
0 commit comments