Commit 0b10ef9 1 parent 9aae657 commit 0b10ef9 Copy full SHA for 0b10ef9
File tree 2 files changed +25
-1
lines changed
skylet/providers/kubernetes
2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -4419,6 +4419,15 @@ def local():
4419
4419
def local_up ():
4420
4420
"""Creates a local cluster."""
4421
4421
cluster_created = False
4422
+ # Check if ~/.kube/config exists:
4423
+ if os .path .exists (os .path .expanduser ('~/.kube/config' )):
4424
+ current_context = kubernetes_utils .get_current_kube_config_context ()
4425
+ skypilot_context = "kind-skypilot"
4426
+ if current_context is not None and current_context != skypilot_context :
4427
+ click .echo (
4428
+ f'Current context in kube config: { current_context } '
4429
+ '\n Will automatically switch to kind-skypilot after the local cluster is created.'
4430
+ )
4422
4431
with log_utils .safe_rich_status ('Creating local cluster...' ):
4423
4432
path_to_package = os .path .dirname (os .path .dirname (__file__ ))
4424
4433
up_script_path = os .path .join (path_to_package , 'sky/utils/kubernetes' ,
Original file line number Diff line number Diff line change 1
- from typing import List , Tuple , Optional
1
+ from typing import List , Tuple , Optional , Union
2
2
3
3
from sky import status_lib
4
4
from sky .adaptors import kubernetes
@@ -66,3 +66,18 @@ def get_cluster_status(cluster_name: str,
66
66
cluster_status .append (status_lib .ClusterStatus .INIT )
67
67
# If pods are not found, we don't add them to the return list
68
68
return cluster_status
69
+
70
+
71
+ def get_current_kube_config_context () -> Union [str , None ]:
72
+ """
73
+ Get the current kubernetes context from the kubeconfig file
74
+
75
+ Returns:
76
+ str | None: The current kubernetes context if it exists, None otherwise
77
+ """
78
+ k8s = kubernetes .get_kubernetes ()
79
+ try :
80
+ _ , current_context = k8s .config .list_kube_config_contexts ()
81
+ return current_context ['name' ]
82
+ except k8s .config .config_exception .ConfigException :
83
+ return None
You can’t perform that action at this time.
0 commit comments