From af32a648f5507e1420ea49272aac5d65318e896d Mon Sep 17 00:00:00 2001 From: Stavros kois Date: Tue, 17 Jan 2023 16:14:23 +0200 Subject: [PATCH] "plumb" the job "controller" --- library/common-test/values.yaml | 7 +++++ .../common/1.0.0/templates/loader/_apply.tpl | 4 ++- .../templates/spawner/_jobAndCronJob.tpl | 30 ++++++++++++++++++- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/library/common-test/values.yaml b/library/common-test/values.yaml index 67cebbb6ff..db0e439e86 100644 --- a/library/common-test/values.yaml +++ b/library/common-test/values.yaml @@ -3,3 +3,10 @@ service: ports: main: port: 65535 + +# controller: +# type: Job + +# cron: +# enabled: true +# schedule: "* * * * *" diff --git a/library/common/1.0.0/templates/loader/_apply.tpl b/library/common/1.0.0/templates/loader/_apply.tpl index b6a1ed5d1e..c74b829198 100644 --- a/library/common/1.0.0/templates/loader/_apply.tpl +++ b/library/common/1.0.0/templates/loader/_apply.tpl @@ -19,8 +19,10 @@ {{- include "ix.v1.common.daemonset" . | nindent 0 -}} {{- else if eq .Values.controller.type "StatefulSet" -}} {{- include "ix.v1.common.statefulset" . | nindent 0 -}} + {{- else if eq .Values.controller.type "Job" -}} + {{/* Pass, it will render from the spawner.jobAndCronJob bellow */}} {{- else -}} - {{- fail (printf "Not a valid controller.type (%s). Valid options are Deployment, DaemonSet, StatefulSet" .Values.controller.type) -}} + {{- fail (printf "Not a valid controller.type (%s). Valid options are Deployment, DaemonSet, StatefulSet, Job" .Values.controller.type) -}} {{- end -}} {{- end -}} diff --git a/library/common/1.0.0/templates/spawner/_jobAndCronJob.tpl b/library/common/1.0.0/templates/spawner/_jobAndCronJob.tpl index 418037ce5f..fef395eab7 100644 --- a/library/common/1.0.0/templates/spawner/_jobAndCronJob.tpl +++ b/library/common/1.0.0/templates/spawner/_jobAndCronJob.tpl @@ -1,5 +1,33 @@ {{- define "ix.v1.common.spawner.jobAndCronJob" -}} - {{- range $jobName, $job := .Values.jobs -}} + {{- $jobs := dict -}} + + {{- if eq .Values.controller.type "Job" -}} + {{- $jobValues := dict -}} + + {{- $_ := set $jobValues "enabled" true -}} + {{- $_ := set $jobValues "podSpec" dict -}} + + {{- if hasKey .Values "cron" -}} + {{- $_ := set $jobValues "cron" .Values.cron -}} + {{- end -}} + + {{- $_ := set $jobValues.podSpec "containers" dict -}} + {{- $_ := set $jobValues.podSpec.containers "main" .Values -}} + {{- $_ := set $jobValues.podSpec.containers.main "enabled" "true" -}} + + {{- $_ := unset $jobValues.podSpec.containers.main "probes" -}} + {{- $_ := unset $jobValues.podSpec.containers.main "lifecycle" -}} + + {{- if not $jobValues.nameOverride -}} + {{- $_ := set $jobValues "nameOverride" (include "ix.v1.common.names.fullname" $) -}} + {{- end -}} + + {{- $_ := set $jobs "main" $jobValues -}} + {{- else -}} + {{- $jobs = .Values.jobs -}} + {{- end -}} + + {{- range $jobName, $job := $jobs -}} {{- if $job.enabled -}} {{- $jobValues := $job -}}