3
3
from kubernetes import client , config
4
4
5
5
def print_number_of_nodes (cluster ):
6
- # Load the Kubernetes configuration
7
- config .load_kube_config (context = cluster )
6
+ # Load the Kubernetes configuration
7
+ config .load_kube_config (context = cluster )
8
8
9
- # Create a Kubernetes API client
10
- api_client = client .CoreV1Api ()
9
+ # Create a Kubernetes API client
10
+ api_client = client .CoreV1Api ()
11
11
12
- nodes = api_client .list_node (pretty = True )
13
- logging .info (f"Total number of nodes: { len (nodes .items )} " )
12
+ nodes = api_client .list_node (pretty = True )
13
+ logging .info (f"Total number of nodes: { len (nodes .items )} " )
14
14
15
+ def print_number_of_namespaces (cluster ):
16
+ # Load the Kubernetes configuration
17
+ config .load_kube_config (context = cluster )
18
+
19
+ # Create a Kubernetes API client
20
+ api_client = client .CoreV1Api ()
21
+
22
+ namespaces = api_client .list_namespace (pretty = True )
23
+ logging .info (f"Total number of namespaces: { len (namespaces .items )} " )
24
+ namespace_names = [namespace .metadata .name for namespace in namespaces .items ]
25
+ logging .info (f"Namespace names: { namespace_names } " )
15
26
16
27
def parse_arguments ():
17
28
parser = argparse .ArgumentParser ()
@@ -22,4 +33,5 @@ def parse_arguments():
22
33
if __name__ == "__main__" :
23
34
kubecontext = parse_arguments ()
24
35
logging .basicConfig (level = logging .INFO , format = '%(asctime)s - %(levelname)s - %(message)s' , filename = 'logs/main.log' )
25
- print_number_of_nodes (kubecontext )
36
+ print_number_of_nodes (kubecontext )
37
+ print_number_of_namespaces (kubecontext )
0 commit comments