Skip to content

Commit f74b703

Browse files
Merge pull request #9 from InformaticsMatters/sc-3208
Operator now adds project and owner env variables
2 parents 99e21b3 + 62ca730 commit f74b703

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

operator/handlers.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,17 +301,27 @@ def create(spec: Dict[str, Any], name: str, namespace: str, **_: Any) -> Dict[st
301301
] = _DEFAULT_POD_PRIORITY_CLASS
302302

303303
# Additional labels?
304-
# Provided by the DM as an array of strings of the form '<KEY>=<VALUE>'
304+
#
305+
# If we find a key ending with '/owner', keep it
306+
# (for use as an environment variable later)
307+
instance_owner = "Unknown"
305308
for label in material.get("labels", []):
306309
key, value = label.split("=")
307310
deployment_body["spec"]["template"]["metadata"]["labels"][key] = value
311+
if key.endswith("/owner"):
312+
instance_owner = value
308313

309314
# To simplify the dynamic ENV adjustments we're about to make...
310315
c_env = deployment_body["spec"]["template"]["spec"]["containers"][0]["env"]
311316

312317
if notebook_interface != "classic":
313318
c_env.append({"name": "JUPYTER_ENABLE_LAB", "value": "true"})
314319

320+
# Add a Project UUID environment variable
321+
c_env.append({"name": "DM_PROJECT_ID", "value": str(project_id)})
322+
# Add the instance owner (expected to have been extracted from a label)
323+
c_env.append({"name": "DM_INSTANCE_OWNER", "value": str(instance_owner)})
324+
315325
kopf.adopt(deployment_body)
316326
apps_api = kubernetes.client.AppsV1Api()
317327
apps_api.create_namespaced_deployment(namespace, deployment_body)

0 commit comments

Comments
 (0)