From fe7076982024b7c886072edd4f0ff2ecb04b504f Mon Sep 17 00:00:00 2001 From: Nikhil Jiju Date: Fri, 25 Oct 2024 13:50:29 -0400 Subject: [PATCH] feat(prefect-worker): support extra initContainers (#403) * Adding option for defining extra Init Containers Signed-off-by: Nikhil Jiju * fixing trailing space and adding test case Signed-off-by: Nikhil Jiju --------- Signed-off-by: Nikhil Jiju --- charts/prefect-worker/templates/deployment.yaml | 7 ++++++- charts/prefect-worker/tests/worker_test.yaml | 17 +++++++++++++++++ charts/prefect-worker/values.schema.json | 8 ++++++++ charts/prefect-worker/values.yaml | 2 ++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/charts/prefect-worker/templates/deployment.yaml b/charts/prefect-worker/templates/deployment.yaml index cf93e08c..5543b1b5 100644 --- a/charts/prefect-worker/templates/deployment.yaml +++ b/charts/prefect-worker/templates/deployment.yaml @@ -54,8 +54,9 @@ spec: {{- if .Values.worker.priorityClassName }} priorityClassName: {{ .Values.worker.priorityClassName }} {{- end }} - {{- if include "worker.baseJobTemplateName" . }} + {{- if or (include "worker.baseJobTemplateName" .) (.Values.worker.initContainer.extraContainers) }} initContainers: + {{- if include "worker.baseJobTemplateName" . }} - name: sync-base-job-template image: "{{ .Values.worker.image.repository }}:{{ .Values.worker.image.prefectTag }}" imagePullPolicy: {{ .Values.worker.image.pullPolicy }} @@ -125,6 +126,10 @@ spec: {{- with .Values.worker.initContainer.containerSecurityContext }} securityContext: {{- toYaml . | nindent 12 }} {{- end }} + {{- end }} + {{- if .Values.worker.initContainer.extraContainers }} + {{- include "common.tplvalues.render" (dict "value" .Values.worker.initContainer.extraContainers "context" $) | nindent 8 }} + {{- end }} {{- end }} containers: - name: prefect-worker diff --git a/charts/prefect-worker/tests/worker_test.yaml b/charts/prefect-worker/tests/worker_test.yaml index 08914117..619f19b6 100644 --- a/charts/prefect-worker/tests/worker_test.yaml +++ b/charts/prefect-worker/tests/worker_test.yaml @@ -8,6 +8,23 @@ values: - ./required_values.yaml tests: + - it: Should set extra init containers + set: + worker: + initContainer: + extraContainers: + - name: code-init + image: custom/prefect-init:v2.0.0 + asserts: + - template: deployment.yaml + equal: + path: .spec.template.spec.initContainers[0].name + value: code-init + - template: deployment.yaml + equal: + path: .spec.template.spec.initContainers[0].image + value: custom/prefect-init:v2.0.0 + - it: Should set the correct image and tag asserts: - template: deployment.yaml diff --git a/charts/prefect-worker/values.schema.json b/charts/prefect-worker/values.schema.json index 698fa0ad..de3daf91 100644 --- a/charts/prefect-worker/values.schema.json +++ b/charts/prefect-worker/values.schema.json @@ -172,6 +172,14 @@ } } } + }, + "extraContainers": { + "type": "array", + "title": "Extra Containers", + "description": "additional init containers", + "items": { + "type": "object" + } } } }, diff --git a/charts/prefect-worker/values.yaml b/charts/prefect-worker/values.yaml index 9c29f752..2d614474 100644 --- a/charts/prefect-worker/values.yaml +++ b/charts/prefect-worker/values.yaml @@ -52,6 +52,8 @@ worker: allowPrivilegeEscalation: false # -- set init container's security context capabilities capabilities: {} + # -- additional sidecar containers + extraContainers: [] image: # -- worker image repository