File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -417,3 +417,24 @@ def wait_for_pod(pod_name, timeout_seconds=10):
417417 return
418418 sleep (1 )
419419 timeout_seconds -= 1
420+
421+
422+ def open_kubeconfig (kubeconfig_path : str = KUBECONFIG ) -> dict :
423+ try :
424+ with open (kubeconfig_path ) as file :
425+ return yaml .safe_load (file )
426+ except FileNotFoundError as e :
427+ raise K8sError (f"Kubeconfig file { kubeconfig_path } not found." ) from e
428+ except yaml .YAMLError as e :
429+ raise K8sError (f"Error parsing kubeconfig: { e } " ) from e
430+
431+
432+ def write_kubeconfig (kube_config : dict ) -> None :
433+ dir_name = os .path .dirname (KUBECONFIG )
434+ try :
435+ with tempfile .NamedTemporaryFile ("w" , dir = dir_name , delete = False ) as temp_file :
436+ yaml .safe_dump (kube_config , temp_file )
437+ os .replace (temp_file .name , KUBECONFIG )
438+ except Exception as e :
439+ os .remove (temp_file .name )
440+ raise K8sError (f"Error writing kubeconfig: { KUBECONFIG } " ) from e
You can’t perform that action at this time.
0 commit comments