Skip to content

Commit 1251fdf

Browse files
Merge pull request #1 from silogen/fix/z2jh-chart
Fix Z2JH version
2 parents 67ffa66 + 6e83a51 commit 1251fdf

5 files changed

Lines changed: 43 additions & 82 deletions

File tree

codehub/cli/helm/create.py

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def admin_to_yaml_str(admin):
5050

5151
__add_config_content(hub_deploy_dir, template_fp, placeholder_replacements)
5252

53-
__download_helm_chart(helm_deploy_dir)
53+
__add_helm_chart_config(helm_deploy_dir)
5454

5555

5656
def __get_config_fps(https=None, oauth=None):
@@ -91,40 +91,9 @@ def __build_template(hub_deploy_dir, config_fps):
9191
return output_fp
9292

9393

94-
def __download_helm_chart(helm_deploy_dir):
94+
def __add_helm_chart_config(helm_deploy_dir):
9595
load_dotenv()
9696

97-
repo_template_fp = os.path.join(STRUCTURE["templates"]["helm"], "repo.yaml")
98-
repo_deploy_fp = os.path.join(helm_deploy_dir, "repo.yaml")
97+
repo_template_fp = os.path.join(STRUCTURE["templates"]["helm"], "chart.yaml")
98+
repo_deploy_fp = os.path.join(helm_deploy_dir, "chart.yaml")
9999
copy_file(repo_template_fp, repo_deploy_fp)
100-
101-
k8s_conf = read_yaml(repo_deploy_fp)
102-
jupyterhub_url = k8s_conf["url"]
103-
k8s_hash = k8s_conf["hash"]
104-
105-
jupyterhub_repo = os.path.join(helm_deploy_dir, "jupyterhub_repo")
106-
helm_chart = os.path.join(helm_deploy_dir, "helm-chart")
107-
108-
cmds = [
109-
["git", "clone", jupyterhub_url, jupyterhub_repo],
110-
["cd", jupyterhub_repo, "&&", "git", "reset", "--hard", k8s_hash],
111-
["mv", os.path.join(jupyterhub_repo, "jupyterhub"), helm_chart],
112-
["rm", "-rf", os.path.join(jupyterhub_repo)],
113-
]
114-
115-
for cmd in cmds:
116-
run_cmd(cmd)
117-
118-
files_to_replace = ["Chart.yaml", "values.yaml"]
119-
for fn in files_to_replace:
120-
fp = os.path.join(helm_chart, fn)
121-
with open(fp) as f:
122-
newText = (
123-
f.read()
124-
.replace("set.by.chartpress", "2.0.0")
125-
.replace("set-by-chartpress", "2.0.0")
126-
)
127-
with open(fp, "w") as f:
128-
f.write(newText)
129-
130-
return helm_chart

codehub/cli/helm/install.py

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,15 @@ def upgrade_helm_chart(cluster_name, region, helm_deploy_dir, hub_deploy_dir):
1818
def __upgrade_or_install_helm_chart(
1919
cluster_name, region, helm_deploy_dir, hub_deploy_dir, upgrade=False
2020
):
21-
install_template_fp = os.path.join(STRUCTURE["templates"]["helm"], "install.yaml")
22-
install_deploy_fp = os.path.join(helm_deploy_dir, "install.yaml")
21+
chart_template_fp = os.path.join(STRUCTURE["templates"]["helm"], "chart.yaml")
22+
chart_deploy_fp = os.path.join(helm_deploy_dir, "chart.yaml")
2323

2424
placeholder_replacements = dict(REGION=region)
25-
fill_file_placeholders(
26-
install_template_fp, install_deploy_fp, placeholder_replacements
27-
)
28-
29-
helm = read_yaml(install_deploy_fp)
25+
fill_file_placeholders(chart_template_fp, chart_deploy_fp, placeholder_replacements)
3026

31-
chart_release = helm["release"]
32-
cluster_namespace = helm["namespace"]
33-
region = helm["region"]
34-
35-
helm_chart = os.path.join(helm_deploy_dir, "helm-chart")
27+
helm_config = read_yaml(chart_deploy_fp)
28+
repo_config = helm_config["repo"]
29+
install_config = helm_config["install"]
3630

3731
config_file = os.path.join(hub_deploy_dir, "config.yaml")
3832

@@ -43,40 +37,34 @@ def __upgrade_or_install_helm_chart(
4337
"container",
4438
"clusters",
4539
"get-credentials",
46-
f"--location={region}",
40+
f"--location={install_config['region']}",
4741
cluster_name,
4842
]
4943
)
5044

51-
if upgrade:
52-
cmds.append(
53-
[
54-
"helm",
55-
"upgrade",
56-
"--cleanup-on-fail",
57-
chart_release,
58-
helm_chart,
59-
"--namespace",
60-
cluster_namespace,
61-
"--values",
62-
config_file,
63-
]
64-
)
65-
else:
66-
cmds.append(
67-
[
68-
"helm",
69-
"upgrade",
70-
"--cleanup-on-fail",
71-
"--install",
72-
chart_release,
73-
helm_chart,
74-
"--namespace",
75-
cluster_namespace,
76-
"--values",
77-
config_file,
78-
]
79-
)
45+
# Add and update Helm repo
46+
cmds.append(["helm", "repo", "add", repo_config["repo_name"], repo_config["url"]])
47+
cmds.append(["helm", "repo", "update"])
48+
49+
# Main helm command
50+
helm_command = [
51+
"helm",
52+
"upgrade",
53+
"--cleanup-on-fail",
54+
]
55+
if not upgrade:
56+
helm_command.append("--install")
57+
helm_command += [
58+
install_config["release"],
59+
f"{repo_config['repo_name']}/{install_config['chart_name']}",
60+
"--namespace",
61+
install_config["namespace"],
62+
"--version",
63+
install_config["chart_version"],
64+
"--values",
65+
config_file,
66+
]
67+
cmds.append(helm_command)
8068

8169
for cmd in cmds:
8270
run_cmd(cmd)

codehub/templates/helm/chart.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
repo:
2+
url: https://hub.jupyter.org/helm-chart/
3+
repo_name: jupyterhub
4+
install:
5+
release: jhub
6+
namespace: jhub
7+
region: {{REGION}}
8+
chart_name: jupyterhub
9+
chart_version: 4.2.0

codehub/templates/helm/install.yaml

Lines changed: 0 additions & 3 deletions
This file was deleted.

codehub/templates/helm/repo.yaml

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)