11from kubernetes .client .rest import ApiException
22from kubernetes import client
33
4- from typing import Optional
4+ from typing import Optional , List , Dict
55
66
7- def get_crds () -> Optional [dict ]:
7+ def get_crds () -> Optional [Dict ]:
88 crdv1 = client .ApiextensionsV1beta1Api ()
99 try :
1010 crd = crdv1 .list_custom_resource_definition (pretty = "true" )
@@ -14,7 +14,20 @@ def get_crds() -> Optional[dict]:
1414 return crd .to_dict ()
1515
1616
17- def get_persistent_volumes () -> Optional [dict ]:
17+ def get_all_mongodb_namespaced (namespace : str ) -> Optional [List ]:
18+ customv1 = client .CustomObjectsApi ()
19+ try :
20+ return list (
21+ customv1 .list_namespaced_custom_object (
22+ "mongodb.com" , "v1" , namespace , "mongodb" , pretty = True
23+ )["items" ]
24+ )
25+ except ApiException as e :
26+ print ("Exception when calling get_namespaced_custom_object %s\n " % e )
27+ return None
28+
29+
30+ def get_persistent_volumes () -> Optional [Dict ]:
1831 corev1 = client .CoreV1Api ()
1932 try :
2033 pv = corev1 .list_persistent_volume (pretty = "true" )
@@ -24,7 +37,7 @@ def get_persistent_volumes() -> Optional[dict]:
2437 return pv .to_dict ()
2538
2639
27- def get_stateful_sets_namespaced (namespace : str ) -> Optional [dict ]:
40+ def get_stateful_sets_namespaced (namespace : str ) -> Optional [Dict ]:
2841 av1beta1 = client .AppsV1Api ()
2942 try :
3043 sst = av1beta1 .list_namespaced_stateful_set (namespace , pretty = "true" )
@@ -34,7 +47,7 @@ def get_stateful_sets_namespaced(namespace: str) -> Optional[dict]:
3447 return sst .to_dict ()
3548
3649
37- def get_configmap_namespaced (namespace : str , name : str ) -> Optional [dict ]:
50+ def get_configmap_namespaced (namespace : str , name : str ) -> Optional [Dict ]:
3851 corev1 = client .CoreV1Api ()
3952 try :
4053 config_map = corev1 .read_namespaced_config_map (name , namespace , pretty = "true" )
@@ -44,7 +57,7 @@ def get_configmap_namespaced(namespace: str, name: str) -> Optional[dict]:
4457 return config_map .to_dict ()
4558
4659
47- def get_pods_namespaced (namespace : str ) -> Optional [list ]:
60+ def get_pods_namespaced (namespace : str ) -> Optional [List ]:
4861 corev1 = client .CoreV1Api ()
4962 try :
5063 pods = corev1 .list_namespaced_pod (namespace )
@@ -60,6 +73,7 @@ def get_pod_namespaced(namespace: str, pod_name: str) -> Optional[client.V1Pod]:
6073 pod = corev1 .read_namespaced_pod (name = pod_name , namespace = namespace )
6174 except ApiException as e :
6275 print ("Exception when calling read_namespaced_pod: %s\n " % e )
76+ return None
6377 return pod
6478
6579
0 commit comments