File tree Expand file tree Collapse file tree 1 file changed +16
-10
lines changed Expand file tree Collapse file tree 1 file changed +16
-10
lines changed Original file line number Diff line number Diff line change 13
13
# limitations under the License.
14
14
15
15
"""
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
19
22
"""
20
23
21
- from pprint import pprint
22
-
23
24
from kubernetes import client , config
24
25
25
-
26
26
def main ():
27
27
config .load_kube_config ()
28
28
@@ -35,10 +35,16 @@ def main():
35
35
"baz" : None }
36
36
}
37
37
}
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 ))
42
48
43
49
44
50
if __name__ == '__main__' :
You can’t perform that action at this time.
0 commit comments