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] Fix for spaces and equals signs in docker env vars #3322

Merged
merged 3 commits into from
Mar 18, 2024
Merged
Changes from all commits
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
22 changes: 15 additions & 7 deletions sky/provision/kubernetes/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,15 @@ def _set_env_vars_in_pods(namespace: str, new_pods: List):
shell sessions.
"""
set_k8s_env_var_cmd = [
'/bin/sh', '-c',
('prefix_cmd() '
'{ if [ $(id -u) -ne 0 ]; then echo "sudo"; else echo ""; fi; } && '
'printenv | awk -F "=" \'{print "export " $1 "=\\047" $2 "\\047"}\' > '
'~/k8s_env_var.sh && '
'mv ~/k8s_env_var.sh /etc/profile.d/k8s_env_var.sh || '
'$(prefix_cmd) mv ~/k8s_env_var.sh /etc/profile.d/k8s_env_var.sh')
'/bin/sh',
'-c',
(
'prefix_cmd() '
'{ if [ $(id -u) -ne 0 ]; then echo "sudo"; else echo ""; fi; } && '
'printenv | while IFS=\'=\' read -r key value; do echo "export $key=\\\"$value\\\""; done > ' # pylint: disable=line-too-long
'~/k8s_env_var.sh && '
'mv ~/k8s_env_var.sh /etc/profile.d/k8s_env_var.sh || '
'$(prefix_cmd) mv ~/k8s_env_var.sh /etc/profile.d/k8s_env_var.sh')
]

for new_pod in new_pods:
Expand Down Expand Up @@ -510,9 +512,15 @@ def _create_pods(region: str, cluster_name_on_cloud: str,
logger.debug(f'run_instances: Initializing {len(uninitialized_pods)} '
f'pods: {list(uninitialized_pods.keys())}')
uninitialized_pods_list = list(uninitialized_pods.values())

# Setup SSH and environment variables in pods.
# Make sure commands used in these methods are generic and work
# on most base images. E.g., do not use Python, since that may not
# be installed by default.
_check_user_privilege(namespace, uninitialized_pods_list)
_setup_ssh_in_pods(namespace, uninitialized_pods_list)
_set_env_vars_in_pods(namespace, uninitialized_pods_list)

for pod in uninitialized_pods.values():
_label_pod(namespace,
pod.metadata.name,
Expand Down
Loading