Skip to content

Commit

Permalink
WIP: add aws-curvenote to deploy.py
Browse files Browse the repository at this point in the history
  • Loading branch information
manics committed Jun 13, 2023
1 parent 4bc89a3 commit ccf4887
Showing 1 changed file with 66 additions and 1 deletion.
67 changes: 66 additions & 1 deletion deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
"prod": "us-central1",
}

# Mapping of config name to cluster name for AWS EKS deployments
AWS_DEPLOYMENTS = {"aws-curvenote": "binderhub"}

# Mapping of cluster names (keys) to resource group names (values) for Azure deployments
AZURE_RGs = {}

Expand Down Expand Up @@ -140,6 +143,27 @@ def setup_auth_gcloud(release, cluster=None, dry_run=False):
)


def setup_auth_aws(cluster, dry_run=False):
"""
Set up authentication for EKS on AWS
Assumes you already have an AWS CLI profile setup with access to EKS,
and that either this is the default profile (e.g. on CI) or you have set the
AWS_PROFILE environment variable.
"""
print(BOLD + GREEN + f"Obtaining AWS EKS kubeconfig for {cluster}" + NC, flush=True)

eks_kubeconfig = [
"aws",
"eks",
"update-kubeconfig",
"--name",
AWS_DEPLOYMENTS[cluster],
]
stdout = check_output(eks_kubeconfig, dry_run)
print(stdout)


def update_networkbans(cluster, dry_run=False):
"""
Run secrets/ban.py to update network bans
Expand All @@ -165,7 +189,9 @@ def get_config_files(release, config_dir="config"):
)
# release-specific config files
for config_dir in (config_dir, os.path.join("secrets", config_dir)):
config_files.append(os.path.join(config_dir, release + ".yaml"))
f = os.path.join(config_dir, release + ".yaml")
if os.path.exists(f):
config_files.append(f)
return config_files


Expand Down Expand Up @@ -309,6 +335,41 @@ def patch_coredns(dry_run=False):
)


def deploy_kube_system_charts(release, name=None, dry_run=False):
"""
Some charts must be deployed into the kube-system namespace
"""
if not name:
name = release
log_name = f"mybinder-kube-system {release}"

config_files = get_config_files(release, config_dir="config-kube-system")
if not config_files:
print(BOLD + GREEN + f"No config files found for {log_name}" + NC, flush=True)
return

print(BOLD + GREEN + f"Starting helm upgrade for {log_name}" + NC, flush=True)
helm = [
"helm",
"upgrade",
"--install",
"--cleanup-on-fail",
"--namespace=kube-system",
name,
"mybinder-kube-system",
]
for config_file in config_files:
helm.extend(["-f", config_file])

check_call(helm, dry_run)
print(
BOLD + GREEN + f"SUCCESS: Helm upgrade for {log_name} completed" + NC,
flush=True,
)

wait_for_deployments_daemonsets("kube-system", dry_run)


def main():
# parse command line args
argparser = argparse.ArgumentParser()
Expand All @@ -320,6 +381,7 @@ def main():
"prod",
"ovh",
"ovh2",
"aws-curvenote",
],
)
argparser.add_argument(
Expand Down Expand Up @@ -383,10 +445,13 @@ def main():
setup_auth_azure(cluster, args.dry_run)
elif cluster in GCP_PROJECTS:
setup_auth_gcloud(args.release, cluster, args.dry_run)
elif cluster in AWS_DEPLOYMENTS:
setup_auth_aws(cluster, args.dry_run)
else:
raise Exception("Cloud cluster not recognised!")

update_networkbans(cluster, args.dry_run)
deploy_kube_system_charts(args.release, args.name, args.dry_run)
deploy(args.release, args.name, args.dry_run)


Expand Down

0 comments on commit ccf4887

Please sign in to comment.