|
5 | 5 | import string
|
6 | 6 | import sys
|
7 | 7 | import typing
|
| 8 | +import yaml |
8 | 9 |
|
9 | 10 | from deployctl.config import config
|
10 | 11 | from deployctl.shell import kubectl, get_most_recent_tag, image_exists, get_k8s_deployments
|
@@ -115,19 +116,58 @@ def deployments_directory() -> str:
|
115 | 116 | return path
|
116 | 117 |
|
117 | 118 |
|
| 119 | +def print_pool_name(pool: str) -> str: |
| 120 | + if pool == "demo-pool": |
| 121 | + return "(demo)" |
| 122 | + if pool == "main-pool": |
| 123 | + return "" |
| 124 | + |
| 125 | + return pool |
| 126 | + |
| 127 | + |
| 128 | +def determine_deployment_pool(path: str) -> str: |
| 129 | + with open(path) as f: |
| 130 | + content = yaml.safe_load(f) |
| 131 | + |
| 132 | + patches = content.get("patches", []) |
| 133 | + for patch in patches: |
| 134 | + if isinstance(patch, dict): |
| 135 | + patch_content = yaml.safe_load(patch.get("patch", "")) |
| 136 | + else: |
| 137 | + patch_content = yaml.safe_load(patch) |
| 138 | + |
| 139 | + if ( |
| 140 | + patch_content |
| 141 | + and patch_content.get("kind") == "Deployment" |
| 142 | + and patch_content.get("spec", {}) |
| 143 | + .get("template", {}) |
| 144 | + .get("spec", {}) |
| 145 | + .get("nodeSelector", {}) |
| 146 | + .get("cloud.google.com/gke-nodepool") |
| 147 | + == "demo-pool" |
| 148 | + ): |
| 149 | + return "demo-pool" |
| 150 | + |
| 151 | + return "main-pool" |
| 152 | + |
| 153 | + |
118 | 154 | def list_deployments() -> None:
|
119 | 155 | print("Local configurations")
|
120 | 156 | print("====================")
|
121 | 157 | paths = reversed(sorted(glob.iglob(f"{deployments_directory()}/*/kustomization.yaml"), key=os.path.getmtime))
|
122 | 158 | for path in paths:
|
123 |
| - print(os.path.basename(os.path.dirname(path))) |
| 159 | + name = os.path.basename(os.path.dirname(path)) |
| 160 | + pool = determine_deployment_pool(path) |
| 161 | + print(f"{name} {print_pool_name(pool)}") |
124 | 162 |
|
125 | 163 | print()
|
126 | 164 |
|
127 | 165 | print("Cluster deployments")
|
128 | 166 | print("===================")
|
129 |
| - for deployment in get_k8s_deployments("component=gnomad-browser"): |
130 |
| - print(deployment[len("gnomad-browser-") :]) |
| 167 | + for deployment, pool in get_k8s_deployments("component=gnomad-browser"): |
| 168 | + print(f"{deployment[len('gnomad-browser-'):]} {print_pool_name(pool)}") |
| 169 | + |
| 170 | + print() |
131 | 171 |
|
132 | 172 |
|
133 | 173 | def create_deployment(name: str, browser_tag: str = None, api_tag: str = None, demo: bool = False) -> None:
|
|
0 commit comments