Skip to content

Commit

Permalink
Update demo_ingress to expect a reads service name instead of managin…
Browse files Browse the repository at this point in the history
…g services (#1634)
  • Loading branch information
sjahl authored Sep 30, 2024
1 parent cf1a721 commit 732d049
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 37 deletions.
55 changes: 54 additions & 1 deletion deploy/deployctl/subcommands/browser_deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,55 @@
value: 'gs://{cluster_name}-gene-cache/2024-04-24'
"""

DEMO_DEPLOYMENT_KUSTOMIZATION = """
- patch: |-
apiVersion: apps/v1
kind: Deployment
metadata:
name: gnomad-api
spec:
template:
spec:
tolerations:
- key: "volatile"
operator: "Equal"
value: "true"
effect: "NoSchedule"
- patch: |-
apiVersion: apps/v1
kind: Deployment
metadata:
name: gnomad-browser
spec:
template:
spec:
tolerations:
- key: "volatile"
operator: "Equal"
value: "true"
effect: "NoSchedule"
- patch: |-
apiVersion: apps/v1
kind: Deployment
metadata:
name: gnomad-api
spec:
template:
spec:
nodeSelector:
cloud.google.com/gke-nodepool: 'demo-pool'
- patch: |-
apiVersion: apps/v1
kind: Deployment
metadata:
name: gnomad-browser
spec:
template:
spec:
nodeSelector:
cloud.google.com/gke-nodepool: 'demo-pool'
"""


def deployments_directory() -> str:
path = os.path.realpath(os.path.join(os.path.dirname(__file__), "../../manifests/browser/deployments"))
Expand All @@ -81,7 +130,7 @@ def list_deployments() -> None:
print(deployment[len("gnomad-browser-") :])


def create_deployment(name: str, browser_tag: str = None, api_tag: str = None) -> None:
def create_deployment(name: str, browser_tag: str = None, api_tag: str = None, demo: bool = False) -> None:
if not name:
name = datetime.datetime.now().strftime("%Y%m%d-%H%M")
else:
Expand Down Expand Up @@ -124,6 +173,9 @@ def create_deployment(name: str, browser_tag: str = None, api_tag: str = None) -
cluster_name=config.gke_cluster_name,
)

if demo:
kustomization = kustomization + DEMO_DEPLOYMENT_KUSTOMIZATION

kustomization_file.write(kustomization)

print(f"configured local deployment manifest '{name}'")
Expand Down Expand Up @@ -174,6 +226,7 @@ def main(argv: typing.List[str]) -> None:
create_parser.add_argument("--name")
create_parser.add_argument("--browser-tag")
create_parser.add_argument("--api-tag")
create_parser.add_argument("--demo", action="store_true")

apply_parser = subparsers.add_parser("apply")
apply_parser.set_defaults(action=apply_deployment)
Expand Down
46 changes: 11 additions & 35 deletions deploy/deployctl/subcommands/ingress_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,6 @@
ports:
- port: 80
targetPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: gnomad-reads-demo-{name}
labels:
tier: demo
spec:
type: NodePort
selector:
name: gnomad-reads
deployment: '{reads_deployment}'
ports:
- port: 80
targetPort: 80
"""

INGRESS_MANIFEST_TEMPLATE = """---
Expand All @@ -54,14 +39,14 @@
pathType: ImplementationSpecific
backend:
service:
name: gnomad-reads-demo-{name}
name: {reads_service}
port:
number: 80
- path: /reads/*
pathType: ImplementationSpecific
backend:
service:
name: gnomad-reads-demo-{name}
name: {reads_service}
port:
number: 80
- path:
Expand Down Expand Up @@ -92,41 +77,32 @@ def list_demo_ingresses() -> None:
def describe_services(name: str) -> None:
try:
browser_manifest = json.loads(kubectl(["get", "service", f"gnomad-browser-demo-{name}", "--output=json"]))
reads_manifest = json.loads(kubectl(["get", "service", f"gnomad-reads-demo-{name}", "--output=json"]))

browser_deployment = browser_manifest["spec"]["selector"]["deployment"]
reads_deployment = reads_manifest["spec"]["selector"]["deployment"]

print("active browser deployment:", browser_deployment)
print("active reads deployment:", reads_deployment)
except Exception: # pylint: disable=broad-except
print(f"Could not get services for '{name}' demo environment")


def apply_services(name: str, browser_deployment: str = None, reads_deployment: str = None) -> None:
def apply_services(name: str, browser_deployment: str = None) -> None:
if browser_deployment:
if not k8s_deployment_exists(f"gnomad-browser-{browser_deployment}"):
raise RuntimeError(f"browser deployment {browser_deployment} not found")
else:
browser_deployment = get_most_recent_k8s_deployment("component=gnomad-browser")[len("gnomad-browser-") :]

if reads_deployment:
if not k8s_deployment_exists(f"gnomad-reads-{reads_deployment}"):
raise RuntimeError(f"reads deployment {reads_deployment} not found")
else:
reads_deployment = get_most_recent_k8s_deployment("component=gnomad-reads")[len("gnomad-reads-") :]

manifest = SERVICES_MANIFEST_TEMPLATE.format(
name=name, browser_deployment=browser_deployment, reads_deployment=reads_deployment
)
manifest = SERVICES_MANIFEST_TEMPLATE.format(name=name, browser_deployment=browser_deployment)

kubectl(["apply", "-f", "-"], input=manifest)


def apply_ingress(name: str, browser_deployment: str = None, reads_deployment: str = None) -> None:
apply_services(name, browser_deployment, reads_deployment)
def apply_ingress(
name: str, browser_deployment: str = None, reads_service: str = "reads-bluegreen-active-prod"
) -> None:
apply_services(name, browser_deployment)

manifest = INGRESS_MANIFEST_TEMPLATE.format(name=name)
manifest = INGRESS_MANIFEST_TEMPLATE.format(name=name, reads_service=reads_service)

kubectl(["apply", "-f", "-"], input=manifest)

Expand Down Expand Up @@ -154,13 +130,13 @@ def main(argv: typing.List[str]) -> None:
apply_services_parser.set_defaults(action=apply_services)
apply_services_parser.add_argument("name")
apply_services_parser.add_argument("--browser-deployment")
apply_services_parser.add_argument("--reads-deployment")
apply_services_parser.add_argument("--reads-service")

apply_ingress_parser = subparsers.add_parser("apply-ingress")
apply_ingress_parser.set_defaults(action=apply_ingress)
apply_ingress_parser.add_argument("name")
apply_ingress_parser.add_argument("--browser-deployment")
apply_ingress_parser.add_argument("--reads-deployment")
apply_ingress_parser.add_argument("--reads-service")

delete_ingress_and_services_parser = subparsers.add_parser("delete")
delete_ingress_and_services_parser.set_defaults(action=delete_ingress_and_services)
Expand Down
4 changes: 3 additions & 1 deletion deploy/docs/Deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,11 @@ There exist several Python scripts in the `deployctl` package that make this pro
2. Create a local manifest file that describes the deployment with:

```
./deployctl deployments create --name <DEPLOYMENT_NAME> --browser-tag <BROWSER_IMAGE_TAG> --api-tag <API_IMAGE_TAG>
./deployctl deployments create --name <DEPLOYMENT_NAME> --browser-tag <BROWSER_IMAGE_TAG> --api-tag <API_IMAGE_TAG> --demo
```

Note the `--demo` flag is optional, but it will cause your deployment to run on an autoscaling demo pool, so that you don't have to ensure capacity on the prod pool.

- 'Apply' the deployment, assigning pods to run it in the [Google Kubernetes Engine](https://console.cloud.google.com/kubernetes/workload/overview?project=exac-gnomad):

```
Expand Down

0 comments on commit 732d049

Please sign in to comment.