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

[k8s] Show enabled contexts in sky check #4587

Merged
merged 2 commits into from
Jan 23, 2025
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
32 changes: 31 additions & 1 deletion sky/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ def get_all_clouds():
# Pretty print for UX.
if not quiet:
enabled_clouds_str = '\n :heavy_check_mark: '.join(
[''] + sorted(all_enabled_clouds))
[''] +
[_format_enabled_cloud(c) for c in sorted(all_enabled_clouds)])
rich.print('\n[green]:tada: Enabled clouds :tada:'
f'{enabled_clouds_str}[/green]')

Expand Down Expand Up @@ -222,3 +223,32 @@ def get_cloud_credential_file_mounts(
r2_credential_mounts = cloudflare.get_credential_file_mounts()
file_mounts.update(r2_credential_mounts)
return file_mounts


def _format_enabled_cloud(cloud_name: str) -> str:
if cloud_name == repr(sky_clouds.Kubernetes()):
# Get enabled contexts for Kubernetes
contexts = sky_clouds.Kubernetes.existing_allowed_contexts()
romilbhardwaj marked this conversation as resolved.
Show resolved Hide resolved
if not contexts:
return cloud_name

# Check if allowed_contexts is explicitly set in config
allowed_contexts = skypilot_config.get_nested(
('kubernetes', 'allowed_contexts'), None)

# Format the context info with consistent styling
if allowed_contexts is not None:
contexts_formatted = []
for i, context in enumerate(contexts):
# TODO: We should use ux_utils.INDENT_SYMBOL and
# INDENT_LAST_SYMBOL but, they are formatted for colorama, while
# here we are using rich. We should migrate this file to
# use colorama as we do in the rest of the codebase.
Michaelvll marked this conversation as resolved.
Show resolved Hide resolved
symbol = ('└── ' if i == len(contexts) - 1 else '├── ')
contexts_formatted.append(f'\n {symbol}{context}')
context_info = f'Allowed contexts:{"".join(contexts_formatted)}'
else:
context_info = f'Active context: {contexts[0]}'

return f'{cloud_name}[/green][dim]\n └── {context_info}[/dim][green]'
return cloud_name
6 changes: 3 additions & 3 deletions sky/clouds/kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def _log_skipped_contexts_once(cls, skipped_contexts: Tuple[str,
'Ignoring these contexts.')

@classmethod
def _existing_allowed_contexts(cls) -> List[str]:
def existing_allowed_contexts(cls) -> List[str]:
"""Get existing allowed contexts.

If None is returned in the list, it means that we are running in a pod
Expand Down Expand Up @@ -175,7 +175,7 @@ def regions_with_offering(cls, instance_type: Optional[str],
use_spot: bool, region: Optional[str],
zone: Optional[str]) -> List[clouds.Region]:
del accelerators, zone, use_spot # unused
existing_contexts = cls._existing_allowed_contexts()
existing_contexts = cls.existing_allowed_contexts()

regions = []
for context in existing_contexts:
Expand Down Expand Up @@ -591,7 +591,7 @@ def _make(instance_list):
def check_credentials(cls) -> Tuple[bool, Optional[str]]:
# Test using python API
try:
existing_allowed_contexts = cls._existing_allowed_contexts()
existing_allowed_contexts = cls.existing_allowed_contexts()
except ImportError as e:
return (False,
f'{common_utils.format_exception(e, use_bracket=True)}')
Expand Down
Loading