Skip to content

Commit

Permalink
better nc error message on mac (#3374)
Browse files Browse the repository at this point in the history
* initial commit

* newline

* comments

* run linter

* reminder for down

* tentatively done with example

* formatting

* yapf

* [Storage] Storage mounting tool permissions fix (#3215)

* fix permissions

* fix permissions

* [LLM] Example for Serving Gemma (#3207)

* Add serve for gemma and fix mixtral dependency

* Add hf token

* fix model len

* Add comment

* Serve your private gemma

* fix serve yaml

* readme

* Remove chat completion due to the wrong template

* add readme

* Update llm/gemma/README.md

Co-authored-by: Zongheng Yang <[email protected]>

* address comments

* Update README.md

Co-authored-by: Zongheng Yang <[email protected]>

* Update llm/gemma/README.md

Co-authored-by: Zongheng Yang <[email protected]>

* Update llm/gemma/README.md

Co-authored-by: Zongheng Yang <[email protected]>

* Update llm/gemma/README.md

Co-authored-by: Zongheng Yang <[email protected]>

* Change to it

* Add chat API

* use HF_TOKEN env

* typo

---------

Co-authored-by: Zongheng Yang <[email protected]>

* [LLM] Add logo for Gemma (#3220)

* Minor fixes for release 0.5.0 (#3212)

* when removing cudo credential, sky check fails

* remove tips

* minor hint fix

* fix cluster version for k8s

* fix typo

* [Docker] Add retry for docker pull due to daemon not ready (#3218)

* Add retry for docker pull due to daemon not ready

* longer wait time

* longer wait time

* retry earlier

* add retry for retries as well

* longer wait time

* change wait time

* format

* Add comment

* Fix

* Fix indent for azure docker config

* Fix docker login config

* Fix comments

* More robust docker login config

* Add retry for docker check

* minor fix

* Add additional test for stop and start with docker

* Fix cancelled

* added comments

* quick fix

* finished pip issues

* fix

* fix storage error message, add example link to docs

* changed error message if default nc installed on mac

* refactored check_port_forward_mode_dependencies function

* update comment

---------

Co-authored-by: Sheth <[email protected]>
Co-authored-by: Romil Bhardwaj <[email protected]>
Co-authored-by: Zhanghao Wu <[email protected]>
Co-authored-by: Zongheng Yang <[email protected]>
Co-authored-by: Romil Bhardwaj <[email protected]>
  • Loading branch information
6 people authored Apr 15, 2024
1 parent 91d6d1b commit c9f575c
Showing 1 changed file with 57 additions and 21 deletions.
78 changes: 57 additions & 21 deletions sky/provision/kubernetes/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1025,28 +1025,64 @@ def fill_ssh_jump_template(ssh_key_secret: str, ssh_jump_image: str,


def check_port_forward_mode_dependencies() -> None:
"""Checks if 'socat' is installed"""
# We store the dependency list as a list of lists. Each inner list
# contains the name of the dependency, the command to check if it is
# installed, and the package name to install it.
dependency_list = [['socat', ['socat', '-V'], 'socat'],
['nc', ['nc', '-h'], 'netcat']]
for name, check_cmd, install_cmd in dependency_list:
try:
subprocess.run(check_cmd,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
check=True)
except (FileNotFoundError, subprocess.CalledProcessError):
"""Checks if 'socat' and 'nc' are installed"""

# Construct runtime errors
socat_default_error = RuntimeError(
f'`socat` is required to setup Kubernetes cloud with '
f'`{kubernetes_enums.KubernetesNetworkingMode.PORTFORWARD.value}` ' # pylint: disable=line-too-long
'default networking mode and it is not installed. '
'On Debian/Ubuntu, install it with:\n'
f' $ sudo apt install socat\n'
f'On MacOS, install it with: \n'
f' $ brew install socat')
netcat_default_error = RuntimeError(
f'`nc` is required to setup Kubernetes cloud with '
f'`{kubernetes_enums.KubernetesNetworkingMode.PORTFORWARD.value}` ' # pylint: disable=line-too-long
'default networking mode and it is not installed. '
'On Debian/Ubuntu, install it with:\n'
f' $ sudo apt install netcat\n'
f'On MacOS, install it with: \n'
f' $ brew install netcat')
mac_installed_error = RuntimeError(
f'The default MacOS `nc` is installed. However, for '
f'`{kubernetes_enums.KubernetesNetworkingMode.PORTFORWARD.value}` ' # pylint: disable=line-too-long
'default networking mode, GNU netcat is required. '
f'On MacOS, install it with: \n'
f' $ brew install netcat')

# Ensure socat is installed
try:
subprocess.run(['socat', '-V'],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
check=True)
except (FileNotFoundError, subprocess.CalledProcessError):
with ux_utils.print_exception_no_traceback():
raise socat_default_error from None

# Ensure netcat is installed
#
# In some cases, the user may have the default MacOS nc installed, which
# does not support the -z flag. To use the -z flag for port scanning,
# they need GNU nc installed. We check for this case and raise an error.
try:
netcat_output = subprocess.run(['nc', '-h'],
capture_output=True,
check=False)
nc_mac_installed = netcat_output.returncode == 1 and 'apple' in str(
netcat_output.stderr)

if nc_mac_installed:
with ux_utils.print_exception_no_traceback():
raise mac_installed_error from None
elif netcat_output.returncode != 0:
with ux_utils.print_exception_no_traceback():
raise RuntimeError(
f'`{name}` is required to setup Kubernetes cloud with '
f'`{kubernetes_enums.KubernetesNetworkingMode.PORTFORWARD.value}` ' # pylint: disable=line-too-long
'default networking mode and it is not installed. '
'On Debian/Ubuntu, install it with:\n'
f' $ sudo apt install {install_cmd}\n'
f'On MacOS, install it with: \n'
f' $ brew install {install_cmd}') from None
raise netcat_default_error from None

except FileNotFoundError:
with ux_utils.print_exception_no_traceback():
raise netcat_default_error from None


def get_endpoint_debug_message() -> str:
Expand Down

0 comments on commit c9f575c

Please sign in to comment.