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

[WIP] Support Cloud-Init in GCP #2209

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion sky/clouds/service_catalog/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Constants used for service catalog."""
import os

HOSTED_CATALOG_DIR_URL = 'https://raw.githubusercontent.com/skypilot-org/skypilot-catalog/master/catalogs' # pylint: disable=line-too-long
HOSTED_CATALOG_DIR_URL = 'https://raw.githubusercontent.com/cblmemo/skypilot-catalog/ubuntu-in-gcp/catalogs' # pylint: disable=line-too-long
CATALOG_SCHEMA_VERSION = 'v5'
LOCAL_CATALOG_DIR = os.path.expanduser('~/.sky/catalogs/')
39 changes: 39 additions & 0 deletions sky/skylet/providers/gcp/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import base64
import copy
import json
import logging
import os
import textwrap
import time
from functools import partial
from typing import Dict, List, Set, Tuple
Expand Down Expand Up @@ -309,6 +311,8 @@ def bootstrap_gcp(config):
config = _configure_iam_role(config, crm, iam)
config = _configure_key_pair(config, compute)
config = _configure_subnet(config, compute)
config = _configure_cloud_init(config)
print("DEBUG HERE", config)

return config

Expand Down Expand Up @@ -841,6 +845,41 @@ def _configure_subnet(config, compute):
return config


def _configure_cloud_init(config):
"""Configure cloud-init for the cluster."""
config = copy.deepcopy(config)

node_configs = [
node_type["node_config"]
for node_type in config["available_node_types"].values()
]

cloud_init_encoded_script = base64.b64encode(
textwrap.dedent(
"""\
#cloud-config
write_files:
- path: /etc/apt/apt.conf.d/20auto-upgrades
content: |
APT::Periodic::Update-Package-Lists "0";
APT::Periodic::Download-Upgradeable-Packages "0";
APT::Periodic::AutocleanInterval "0";
APT::Periodic::Unattended-Upgrade "0";
- path: /etc/apt/apt.conf.d/10cloudinit-disable
content: |
APT::Periodic::Enable "0";
"""
).encode("utf-8")
).decode("utf-8")

for node_config in node_configs:
node_config["metadata"] = {
"items": [{"key": "user-data", "value": cloud_init_encoded_script}]
}

return config


def _create_firewall_rule(config, compute, body):
operation = (
compute.firewalls()
Expand Down
13 changes: 1 addition & 12 deletions sky/templates/gcp-ray.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ initialization_commands: []
# Increment the following for catching performance bugs easier:
# current num items (num SSH connections): 1 (+1 if tpu_vm)
setup_commands:
# Disable `unattended-upgrades` to prevent apt-get from hanging. It should be called at the beginning before the process started to avoid being blocked. (This is a temporary fix.)
# Line 'mkdir -p ..': Create ~/.ssh/config file in case the file does not exist in the custom image.
# Line 'pip3 --v ..': Make sure python3 & pip3 are available on this image.
# Line 'which conda ..': some images (TPU VM) do not install conda by
Expand All @@ -150,17 +149,7 @@ setup_commands:
# Line 'sudo grep ..': set the number of threads per process to unlimited to avoid ray job submit stucking issue when the number of running ray jobs increase.
# Line 'mkdir -p ..': disable host key check
# Line 'python3 -c ..': patch the buggy ray files and enable `-o allow_other` option for `goofys`
- function mylsof { p=$(for pid in /proc/{0..9}*; do i=$(basename "$pid"); for file in "$pid"/fd/*; do link=$(readlink -e "$file"); if [ "$link" = "$1" ]; then echo "$i"; fi; done; done); echo "$p"; };
sudo systemctl stop unattended-upgrades || true;
sudo systemctl disable unattended-upgrades || true;
sudo sed -i 's/Unattended-Upgrade "1"/Unattended-Upgrade "0"/g' /etc/apt/apt.conf.d/20auto-upgrades || true;
p=$(mylsof "/var/lib/dpkg/lock-frontend"); echo "$p";
sudo kill -9 `echo "$p" | tail -n 1` || true;
sudo rm /var/lib/dpkg/lock-frontend;
sudo pkill -9 dpkg;
sudo pkill -9 apt-get;
sudo dpkg --configure --force-overwrite -a;
mkdir -p ~/.ssh; touch ~/.ssh/config;
- mkdir -p ~/.ssh; touch ~/.ssh/config;
pip3 --version > /dev/null 2>&1 || (curl -sSL https://bootstrap.pypa.io/get-pip.py -o get-pip.py && python3 get-pip.py && echo "PATH=$HOME/.local/bin:$PATH" >> ~/.bashrc);
(type -a python | grep -q python3) || echo 'alias python=python3' >> ~/.bashrc;
(type -a pip | grep -q pip3) || echo 'alias pip=pip3' >> ~/.bashrc;
Expand Down