From 22305b4834ea2322f3d0dc6e0a291c669d42183c Mon Sep 17 00:00:00 2001 From: Graham Dumpleton Date: Sun, 30 Jul 2023 12:06:15 +1000 Subject: [PATCH] Add section to workshop definition to specify init containers. --- .../11-session-manager/01-crds-workshop.yaml | 10 ++++++++++ session-manager/handlers/workshopsession.py | 14 ++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/carvel-packages/training-platform/bundle/config/11-session-manager/01-crds-workshop.yaml b/carvel-packages/training-platform/bundle/config/11-session-manager/01-crds-workshop.yaml index 5b4c556d..c3215a4d 100644 --- a/carvel-packages/training-platform/bundle/config/11-session-manager/01-crds-workshop.yaml +++ b/carvel-packages/training-platform/bundle/config/11-session-manager/01-crds-workshop.yaml @@ -683,6 +683,16 @@ spec: name: type: string x-kubernetes-preserve-unknown-fields: true + initContainers: + type: array + items: + type: object + required: + - name + properties: + name: + type: string + x-kubernetes-preserve-unknown-fields: true applications: type: object properties: diff --git a/session-manager/handlers/workshopsession.py b/session-manager/handlers/workshopsession.py index 8fdaae03..8fa06456 100644 --- a/session-manager/handlers/workshopsession.py +++ b/session-manager/handlers/workshopsession.py @@ -899,10 +899,10 @@ def resolve_security_policy(name): image_repository = IMAGE_REPOSITORY - assets_repository=f"assets-server.{workshop_namespace}.svc.{CLUSTER_DOMAIN}" + assets_repository = f"assets-server.{workshop_namespace}.svc.{CLUSTER_DOMAIN}" if xget(workshop_spec, "environment.assets.ingress.enabled", False): - assets_repository=f"assets-{workshop_namespace}.{INGRESS_DOMAIN}" + assets_repository = f"assets-{workshop_namespace}.{INGRESS_DOMAIN}" workshop_image_cache = f"image-cache.{workshop_namespace}.svc.{CLUSTER_DOMAIN}" @@ -1894,6 +1894,16 @@ def vendir_secrets_required(contents): deployment_pod_template_spec["initContainers"].append(downloads_init_container) + # Append any init containers specified in the workshop definition. + + session_init_containers = workshop_spec["session"].get("initContainers", []) + + session_init_containers = substitute_variables( + session_init_containers, session_variables + ) + + deployment_pod_template_spec["initContainers"].extend(session_init_containers) + # Apply any patches for the pod specification for the deployment which # are specified in the workshop resource definition. This would be used # to set resources and setup volumes. If the target item is a list, look