File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -545,3 +545,19 @@ def write_kubeconfig(kube_config: dict, kubeconfig_path: str) -> None:
545
545
except Exception as e :
546
546
os .remove (temp_file .name )
547
547
raise K8sError (f"Error writing kubeconfig: { kubeconfig_path } " ) from e
548
+
549
+
550
+ def get_pods_with_label (label_selector : str , namespace : Optional [str ] = None ) -> list [V1Pod ]:
551
+ """Get a list of pods by label.
552
+ Label example: "mission=lightning"
553
+ """
554
+ namespace = get_default_namespace_or (namespace )
555
+ v1 = get_static_client ()
556
+
557
+ try :
558
+ pods = v1 .list_namespaced_pod (namespace = namespace , label_selector = label_selector )
559
+ v1_pods = [pod for pod in pods .items ]
560
+ return v1_pods
561
+ except client .exceptions .ApiException as e :
562
+ print (f"Error fetching pods: { e } " )
563
+ return []
You can’t perform that action at this time.
0 commit comments