skypilot-org / skypilot

SkyPilot: Run AI and batch jobs on any infra (Kubernetes or 12+ clouds). Get unified execution, cost savings, and high GPU availability via a simple interface.
https://skypilot.readthedocs.io
Apache License 2.0
6.81k stars 513 forks source link

[UX] user-friendly message shown if Kubernetes is not enabled. #4336

Closed zpoint closed 1 day ago

zpoint commented 1 week ago

Resolve issue #4324

Catch exceptions for the sky check command in Kubernetes.

Before:

  Kubernetes: disabled                              
    Reason: Traceback (most recent call last):
  File "/Users/zepingguo/Desktop/skypilot/sky/adaptors/common.py", line 31, in load_module
    self._module = importlib.import_module(self._module_name)
  File "/Users/zepingguo/miniconda3/envs/sky/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'kubernetes'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/zepingguo/Desktop/skypilot/sky/provision/kubernetes/utils.py", line 854, in get_all_kube_config_context_names
    all_contexts, _ = k8s.config.list_kube_config_contexts()
  File "/Users/zepingguo/Desktop/skypilot/sky/adaptors/common.py", line 46, in __getattr__
    return getattr(self.load_module(), name)
  File "/Users/zepingguo/Desktop/skypilot/sky/adaptors/common.py", line 36, in load_module
    raise ImportError(self._import_error_message) from e
ImportError: Failed to import dependencies for Kubernetes. Try running: pip install "skypilot[kubernetes]"

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/zepingguo/Desktop/skypilot/sky/adaptors/common.py", line 31, in load_module
    self._module = importlib.import_module(self._module_name)
  File "/Users/zepingguo/miniconda3/envs/sky/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'kubernetes'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/zepingguo/Desktop/skypilot/sky/check.py", line 35, in check_one_cloud
    ok, reason = cloud.check_credentials()
  File "/Users/zepingguo/Desktop/skypilot/sky/clouds/kubernetes.py", line 523, in check_credentials
    existing_allowed_contexts = cls._existing_allowed_contexts()
  File "/Users/zepingguo/Desktop/skypilot/sky/clouds/kubernetes.py", line 138, in _existing_allowed_contexts
    all_contexts = kubernetes_utils.get_all_kube_config_context_names()
  File "/Users/zepingguo/Desktop/skypilot/sky/provision/kubernetes/utils.py", line 858, in get_all_kube_config_context_names
    except k8s.config.config_exception.ConfigException:
  File "/Users/zepingguo/Desktop/skypilot/sky/adaptors/common.py", line 46, in __getattr__
    return getattr(self.load_module(), name)
  File "/Users/zepingguo/Desktop/skypilot/sky/adaptors/common.py", line 36, in load_module
    raise ImportError(self._import_error_message) from e
ImportError: Failed to import dependencies for Kubernetes. Try running: pip install "skypilot[kubernetes]"

After:

  Kubernetes: disabled                              
    Reason: [ImportError] Failed to import dependencies for Kubernetes. Try running: pip install "skypilot[kubernetes]"

Tested (run the relevant ones):