Skip to content

Commit 11e1248

Browse files
committed
WIP: add aws-curvenote to deploy.py
1 parent 229aa48 commit 11e1248

File tree

1 file changed

+68
-3
lines changed

1 file changed

+68
-3
lines changed

deploy.py

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
"prod": "us-central1",
3030
}
3131

32+
AWS_DEPLOYMENTS = {"aws-curvenote": "binderhub"}
33+
3234
# Mapping of cluster names (keys) to resource group names (values) for Azure deployments
3335
AZURE_RGs = {}
3436

@@ -41,7 +43,7 @@ def check_call(*args):
4143
Print a command if DRY_RUN is true, otherwise run it with subprocess.check_call
4244
"""
4345
if DRY_RUN:
44-
print("dry-run: ".join(*args))
46+
print("dry-run:", " ".join(*args))
4547
else:
4648
subprocess.check_call(*args)
4749

@@ -51,7 +53,8 @@ def check_output(*args):
5153
Print a command if DRY_RUN is true, otherwise run it with subprocess.check_output
5254
"""
5355
if DRY_RUN:
54-
print("dry-run: ".join(*args))
56+
print("dry-run:", " ".join(*args))
57+
return b""
5558
else:
5659
return subprocess.check_output(*args)
5760

@@ -138,6 +141,27 @@ def setup_auth_gcloud(release, cluster=None):
138141
)
139142

140143

144+
def setup_auth_aws(cluster):
145+
"""
146+
Set up authentication for EKS on AWS
147+
148+
Assumes you already have an AWS CLI profile setup with access to EKS,
149+
and that either this is the default profile (e.g. on CI) or you have set the
150+
AWS_PROFILE environment variable.
151+
"""
152+
print(f"Obtaining AWS EKS kubeconfig for {cluster}")
153+
154+
eks_kubeconfig = [
155+
"aws",
156+
"eks",
157+
"update-kubeconfig",
158+
"--name",
159+
AWS_DEPLOYMENTS[cluster],
160+
]
161+
stdout = check_output(eks_kubeconfig)
162+
print(stdout.decode("utf8"))
163+
164+
141165
def update_networkbans(cluster):
142166
"""
143167
Run secrets/ban.py to update network bans
@@ -163,7 +187,9 @@ def get_config_files(release, config_dir="config"):
163187
)
164188
# release-specific config files
165189
for config_dir in (config_dir, os.path.join("secrets", config_dir)):
166-
config_files.append(os.path.join(config_dir, release + ".yaml"))
190+
f = os.path.join(config_dir, release + ".yaml")
191+
if os.path.exists(f):
192+
config_files.append(f)
167193
return config_files
168194

169195

@@ -303,6 +329,41 @@ def patch_coredns():
303329
)
304330

305331

332+
def deploy_kube_system_charts(release, name=None):
333+
"""
334+
Some charts must be deployed into the kube-system namespace
335+
"""
336+
if not name:
337+
name = release
338+
log_name = f"mybinder-kube-system {release}"
339+
340+
config_files = get_config_files(release, config_dir="config-kube-system")
341+
if not config_files:
342+
print(BOLD + GREEN + f"No config files found for {log_name}" + NC, flush=True)
343+
return
344+
345+
print(BOLD + GREEN + f"Starting helm upgrade for {log_name}" + NC, flush=True)
346+
helm = [
347+
"helm",
348+
"upgrade",
349+
"--install",
350+
"--cleanup-on-fail",
351+
"--namespace=kube-system",
352+
name,
353+
"mybinder-kube-system",
354+
]
355+
for config_file in config_files:
356+
helm.extend(["-f", config_file])
357+
358+
check_call(helm)
359+
print(
360+
BOLD + GREEN + f"SUCCESS: Helm upgrade for {log_name} completed" + NC,
361+
flush=True,
362+
)
363+
364+
wait_for_deployments_daemonsets("kube-system")
365+
366+
306367
def main():
307368
# parse command line args
308369
argparser = argparse.ArgumentParser()
@@ -314,6 +375,7 @@ def main():
314375
"prod",
315376
"ovh",
316377
"ovh2",
378+
"aws-curvenote",
317379
],
318380
)
319381
argparser.add_argument(
@@ -372,10 +434,13 @@ def main():
372434
setup_auth_azure(cluster)
373435
elif cluster in GCP_PROJECTS:
374436
setup_auth_gcloud(args.release, cluster)
437+
elif cluster in AWS_DEPLOYMENTS:
438+
setup_auth_aws(cluster)
375439
else:
376440
raise Exception("Cloud cluster not recognised!")
377441

378442
update_networkbans(cluster)
443+
deploy_kube_system_charts(args.release, args.name)
379444
deploy(args.release, args.name)
380445

381446

0 commit comments

Comments
 (0)