Skip to content

Commit

Permalink
Updates ingress_production to use the static service names (#1632)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjahl authored Sep 20, 2024
1 parent 451a3b6 commit 428a2cb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 42 deletions.
45 changes: 5 additions & 40 deletions deploy/deployctl/subcommands/ingress_production.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,6 @@
ports:
- port: 80
targetPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: gnomad-reads
labels:
tier: production
spec:
type: NodePort
selector:
name: gnomad-reads
deployment: '{reads_deployment}'
ports:
- port: 80
targetPort: 80
"""


Expand All @@ -51,20 +36,13 @@ def get_current_browser_deployment() -> str:
return browser_manifest["spec"]["selector"]["deployment"]


def get_current_reads_deployment() -> str:
reads_manifest = json.loads(kubectl(["get", "service", "gnomad-reads", "--output=json"]))
return reads_manifest["spec"]["selector"]["deployment"]


def describe_services() -> None:
browser_deployment = get_current_browser_deployment()
reads_deployment = get_current_reads_deployment()

print("active browser deployment:", browser_deployment)
print("active reads deployment:", reads_deployment)


def apply_services(browser_deployment: str = None, reads_deployment: str = None) -> None:
def apply_services(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")
Expand All @@ -74,26 +52,15 @@ def apply_services(browser_deployment: str = None, reads_deployment: str = None)
except Exception: # pylint: disable=broad-except; FIXME: Use a more specific exception class
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:
try:
reads_deployment = get_current_reads_deployment()
except Exception: # pylint: disable=broad-except; FIXME: Use a more specific exception class
reads_deployment = get_most_recent_k8s_deployment("component=gnomad-reads")[len("gnomad-reads-") :]

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

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

print(f"Updated production ingresses. browser: '{browser_deployment}', reads: '{reads_deployment}' ")
print(f"Updated production ingresses. browser: '{browser_deployment}' ")


def apply_ingress(browser_deployment: str = None, reads_deployment: str = None, quiet: bool = False) -> None:
apply_services(browser_deployment, reads_deployment)
def apply_ingress(browser_deployment: str = None, quiet: bool = False) -> None:
apply_services(browser_deployment)

if quiet or input("Apply changes to production ingress (y/n) ").lower() == "y":
kubectl(["apply", "-f", os.path.join(manifests_directory(), "gnomad.backendconfig.yaml")])
Expand All @@ -112,12 +79,10 @@ def main(argv: typing.List[str]) -> None:
apply_services_parser = subparsers.add_parser("update")
apply_services_parser.set_defaults(action=apply_services)
apply_services_parser.add_argument("--browser-deployment")
apply_services_parser.add_argument("--reads-deployment")

apply_ingress_parser = subparsers.add_parser("apply-ingress")
apply_ingress_parser.set_defaults(action=apply_ingress)
apply_ingress_parser.add_argument("--browser-deployment")
apply_ingress_parser.add_argument("--reads-deployment")
apply_ingress_parser.add_argument("--quiet", action="store_true")

args = parser.parse_args(argv)
Expand Down
18 changes: 16 additions & 2 deletions deploy/manifests/ingress/gnomad.ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,32 @@ spec:
paths:
- backend:
service:
name: gnomad-reads
name: reads-bluegreen-active-prod
port:
number: 80
path: /reads
pathType: ImplementationSpecific
- backend:
service:
name: gnomad-reads
name: reads-bluegreen-active-prod
port:
number: 80
path: /reads/*
pathType: ImplementationSpecific
- backend:
service:
name: reads-bluegreen-preview-prod
port:
number: 80
path: /preview-reads
pathType: ImplementationSpecific
- backend:
service:
name: reads-bluegreen-preview-prod
port:
number: 80
path: /preview-reads/*
pathType: ImplementationSpecific
- backend:
service:
name: gnomad-blog
Expand Down

0 comments on commit 428a2cb

Please sign in to comment.