Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle kube config management for sky local commands #2253

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions sky/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4419,15 +4419,6 @@ def local():
def local_up():
"""Creates a local cluster."""
cluster_created = False
# Check if ~/.kube/config exists:
if os.path.exists(os.path.expanduser('~/.kube/config')):
# Check if kubeconfig is valid, `kind delete` leaves an empty kubeconfig
valid, reason = kubernetes_utils.check_credentials()
if valid or (not valid and 'Invalid configuration' not in reason):
# Could be a valid kubeconfig or a non-empty but non-functioning
# kubeconfig - check if user wants to overwrite it
prompt = 'Cluster config found at ~/.kube/config. Overwrite it?'
click.confirm(prompt, default=True, abort=True, show_default=True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a context != kind-skypilot is already set, can we print a message saying that we will automatically switch kubectl context?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid point, I will change the script to prevent switching current context if it's not the SkyPilot context. Wdyt?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think it's okay to automatically switch context, just that we should let the user know that we are going to switch contexts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, will update 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 0b10ef9

with log_utils.safe_rich_status('Creating local cluster...'):
path_to_package = os.path.dirname(os.path.dirname(__file__))
up_script_path = os.path.join(path_to_package, 'sky/utils/kubernetes',
Expand Down
7 changes: 7 additions & 0 deletions sky/utils/kubernetes/delete_cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,10 @@ fi

kind delete cluster --name skypilot
echo "Local cluster deleted!"

# Switch to the first available context
AVAILABLE_CONTEXT=$(kubectl config get-contexts -o name | head -n 1)
if [ ! -z "$AVAILABLE_CONTEXT" ]; then
echo "Switching to context $AVAILABLE_CONTEXT"
kubectl config use-context $AVAILABLE_CONTEXT
fi