Skip to content

Commit

Permalink
Show context in check
Browse files Browse the repository at this point in the history
  • Loading branch information
romilbhardwaj committed Jan 18, 2025
1 parent 1578108 commit ed5870b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
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()
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.
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

0 comments on commit ed5870b

Please sign in to comment.