From 06cf5eabb76c200e8d07c86a5ff382381f8ca3c4 Mon Sep 17 00:00:00 2001 From: Daniel Panzella Date: Thu, 26 Dec 2024 11:44:31 -0800 Subject: [PATCH 1/4] feat: Add Jobs and CronJobs support, refactor container templating --- charts/wandb-base/templates/_containers.tpl | 36 +++++-------- charts/wandb-base/templates/cronjob | 56 +++++++++++++++++++ charts/wandb-base/templates/deployment.yaml | 4 +- charts/wandb-base/templates/job.yaml | 57 ++++++++++++++++++++ charts/wandb-base/templates/statefulset.yaml | 32 ++--------- 5 files changed, 134 insertions(+), 51 deletions(-) create mode 100644 charts/wandb-base/templates/cronjob create mode 100644 charts/wandb-base/templates/job.yaml diff --git a/charts/wandb-base/templates/_containers.tpl b/charts/wandb-base/templates/_containers.tpl index 308e2f57..ac7545fb 100644 --- a/charts/wandb-base/templates/_containers.tpl +++ b/charts/wandb-base/templates/_containers.tpl @@ -1,30 +1,22 @@ +{{/* + wandb-base.containers should be passed a dict with key `containers` containing the map of containers and a key `root` + containing the . from the calling context + */}} {{- define "wandb-base.containers" }} -{{- range .Values.containers}} +{{- range $containerName, $containerSource := .containers}} {{- $container := dict }} -{{- $_ := deepCopy . | merge $container }} -{{- $_ = set $container "securityContext" (coalesce $container.securityContext $.Values.securityContext) }} -{{- $_ = set $container "image" (coalesce $container.image $.Values.image) }} -{{- $_ = set $container "envFrom" (merge (default (dict) ($container.envFrom)) (default (dict) ($.Values.envFrom))) }} -{{- $_ = set $container "env" (merge (default (dict) ($container.env)) (default (dict) ($.Values.env))) }} -{{- $_ = set $container "root" $ }} -{{- include "wandb-base.container" $container }} +{{- $_ := deepCopy $containerSource | merge $container }} +{{- $_ = set $container "name" $containerName }} +{{- $_ = set $container "securityContext" (coalesce $container.securityContext $.root.Values.securityContext) }} +{{- $_ = set $container "image" (coalesce $container.image $.root.Values.image) }} +{{- $_ = set $container "envFrom" (merge (default (dict) ($container.envFrom)) (default (dict) ($.root.Values.envFrom))) }} +{{- $_ = set $container "env" (merge (default (dict) ($container.env)) (default (dict) ($.root.Values.env))) }} +{{- $_ = set $container "root" $.root }} +{{- include "wandb-base.container" $container -}} {{- end }} {{- end }} -{{- define "wandb-base.initContainers" }} -{{- range .Values.initContainers}} -{{- $container := dict }} -{{- $_ := deepCopy . | merge $container }} -{{- $_ = set $container "securityContext" (coalesce $container.securityContext $.Values.securityContext) }} -{{- $_ = set $container "image" (coalesce $container.image $.Values.image) }} -{{- $_ = set $container "envFrom" (merge (default (dict) ($container.envFrom)) (default (dict) ($.Values.envFrom))) }} -{{- $_ = set $container "env" (merge (default (dict) ($container.env)) (default (dict) ($.Values.env))) }} -{{- $_ = set $container "root" $ }} -{{- include "wandb-base.container" $container }} -{{- end }} -{{- end }} - -{{- define "wandb-base.container" }} +{{- define "wandb-base.container" -}} - name: {{ .name }} {{- if .command }} command: diff --git a/charts/wandb-base/templates/cronjob b/charts/wandb-base/templates/cronjob new file mode 100644 index 00000000..7275a0cf --- /dev/null +++ b/charts/wandb-base/templates/cronjob @@ -0,0 +1,56 @@ +{{- range $cronJobName, $cronJob := .Values.cronJobs }} +apiVersion: batch/v1 +kind: CronJob +metadata: + name: {{ printf "%s-%s" .Release.Name $cronJobName }} + labels: + {{- include "wandb-base.labels" . | nindent 4 }} +spec: + schedule: "{{ $cronJob.schedule }}" + jobTemplate: + spec: + template: + metadata: + {{- with $cronJob.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "wandb-base.labels" . | nindent 8 }} + {{- with $cronJob.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + {{- with $.Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "wandb-base.serviceAccountName" . }} + securityContext: + {{- toYaml $.Values.podSecurityContext | nindent 8 }} + {{- if $cronJob.initContainers }} + initContainers: + {{- include "wandb-base.containers" (dict "containers" $cronJob.initContainers "root" $) | nindent 8 }} + {{- end }} + containers: + {{- include "wandb-base.containers" (dict "containers" $cronJob.containers "root" $) | nindent 8 }} + restartPolicy: Never + {{/* TODO: enable this as needed + volumes: + {{- tpl (toYaml . | nindent 8) $ }} + {{- end }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} + */}} +--- +{{- end }} \ No newline at end of file diff --git a/charts/wandb-base/templates/deployment.yaml b/charts/wandb-base/templates/deployment.yaml index 40d140ec..073893e5 100644 --- a/charts/wandb-base/templates/deployment.yaml +++ b/charts/wandb-base/templates/deployment.yaml @@ -33,10 +33,10 @@ spec: {{- toYaml .Values.podSecurityContext | nindent 8 }} {{- if .Values.initContainers }} initContainers: - {{- include "wandb-base.initContainers" . | nindent 8 }} + {{- include "wandb-base.containers" (dict "containers" .Values.initContainers "root" .) | nindent 8 }} {{- end }} containers: - {{- include "wandb-base.containers" . | nindent 8 }} + {{- include "wandb-base.containers" (dict "containers" .Values.containers "root" .) | nindent 8 }} {{- with .Values.volumes }} volumes: {{- tpl (toYaml . | nindent 8) $ }} diff --git a/charts/wandb-base/templates/job.yaml b/charts/wandb-base/templates/job.yaml new file mode 100644 index 00000000..8f7d4cdb --- /dev/null +++ b/charts/wandb-base/templates/job.yaml @@ -0,0 +1,57 @@ +{{- range $jobName, $job := .Values.jobs }} +apiVersion: batch/v1 +kind: Job +metadata: + name: {{ printf "%s-%s" $.Release.Name $jobName }} + labels: + {{- include "wandb-base.labels" $ | nindent 4 }} + {{- with $job.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + template: + metadata: + {{- with $job.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "wandb-base.labels" $ | nindent 8 }} + {{- with $job.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + {{- with $.Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "wandb-base.serviceAccountName" $ }} + securityContext: + {{- toYaml $.Values.podSecurityContext | nindent 8 }} + {{- if $job.initContainers }} + initContainers: + {{- include "wandb-base.containers" (dict "containers" $job.initContainers "root" $) | nindent 8 }} + {{- end }} + containers: + {{- include "wandb-base.containers" (dict "containers" $job.containers "root" $) | nindent 8 }} + restartPolicy: Never +{{/* TODO: enable this as needed + volumes: + {{- tpl (toYaml . | nindent 8) $ }} + {{- end }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} +*/}} +--- +{{- end }} \ No newline at end of file diff --git a/charts/wandb-base/templates/statefulset.yaml b/charts/wandb-base/templates/statefulset.yaml index 475083e3..a5f9d694 100644 --- a/charts/wandb-base/templates/statefulset.yaml +++ b/charts/wandb-base/templates/statefulset.yaml @@ -31,34 +31,12 @@ spec: serviceAccountName: {{ include "wandb-base.serviceAccountName" . }} securityContext: {{- toYaml .Values.podSecurityContext | nindent 8 }} + {{- if .Values.initContainers }} + initContainers: + {{- include "wandb-base.containers" (dict "containers" .Values.initContainers "root" .) | nindent 8 }} + {{- end }} containers: - - name: {{ .Chart.Name }} - {{ with .Values.envFrom }} - envFrom: - {{- toYaml . | nindent 12 }} - {{- end }} - {{ with .Values.env }} - env: - {{- toYaml . | nindent 12 }} - {{- end }} - securityContext: - {{- toYaml .Values.securityContext | nindent 12 }} - image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" - imagePullPolicy: {{ .Values.image.pullPolicy }} - ports: - - name: http - containerPort: {{ .Values.service.port }} - protocol: TCP - livenessProbe: - {{- toYaml .Values.livenessProbe | nindent 12 }} - readinessProbe: - {{- toYaml .Values.readinessProbe | nindent 12 }} - resources: - {{- toYaml .Values.resources | nindent 12 }} - {{- with .Values.volumeMounts }} - volumeMounts: - {{- toYaml . | nindent 12 }} - {{- end }} + {{- include "wandb-base.containers" (dict "containers" .Values.containers "root" .) | nindent 8 }} {{- with .Values.volumes }} volumes: {{- toYaml . | nindent 8 }} From 08d5e837a3e14fb2ee6238419197cbe60a184bc1 Mon Sep 17 00:00:00 2001 From: Daniel Panzella Date: Thu, 26 Dec 2024 11:50:24 -0800 Subject: [PATCH 2/4] fix: fix CronJob and add example values --- charts/wandb-base/templates/cronjob | 28 +++++------ charts/wandb-base/values.yaml | 76 ++++++++++++++++++++++++++++- 2 files changed, 89 insertions(+), 15 deletions(-) diff --git a/charts/wandb-base/templates/cronjob b/charts/wandb-base/templates/cronjob index 7275a0cf..00e2ce2e 100644 --- a/charts/wandb-base/templates/cronjob +++ b/charts/wandb-base/templates/cronjob @@ -2,9 +2,9 @@ apiVersion: batch/v1 kind: CronJob metadata: - name: {{ printf "%s-%s" .Release.Name $cronJobName }} + name: {{ printf "%s-%s" $.Release.Name $cronJobName }} labels: - {{- include "wandb-base.labels" . | nindent 4 }} + {{- include "wandb-base.labels" $ | nindent 4 }} spec: schedule: "{{ $cronJob.schedule }}" jobTemplate: @@ -13,43 +13,43 @@ spec: metadata: {{- with $cronJob.podAnnotations }} annotations: - {{- toYaml . | nindent 8 }} + {{- toYaml . | nindent 12 }} {{- end }} labels: - {{- include "wandb-base.labels" . | nindent 8 }} + {{- include "wandb-base.labels" $ | nindent 12 }} {{- with $cronJob.podLabels }} - {{- toYaml . | nindent 8 }} + {{- toYaml . | nindent 12 }} {{- end }} spec: {{- with $.Values.imagePullSecrets }} imagePullSecrets: - {{- toYaml . | nindent 8 }} + {{- toYaml . | nindent 12 }} {{- end }} - serviceAccountName: {{ include "wandb-base.serviceAccountName" . }} + serviceAccountName: {{ include "wandb-base.serviceAccountName" $ }} securityContext: - {{- toYaml $.Values.podSecurityContext | nindent 8 }} + {{- toYaml $.Values.podSecurityContext | nindent 12 }} {{- if $cronJob.initContainers }} initContainers: - {{- include "wandb-base.containers" (dict "containers" $cronJob.initContainers "root" $) | nindent 8 }} + {{- include "wandb-base.containers" (dict "containers" $cronJob.initContainers "root" $) | nindent 12 }} {{- end }} containers: - {{- include "wandb-base.containers" (dict "containers" $cronJob.containers "root" $) | nindent 8 }} + {{- include "wandb-base.containers" (dict "containers" $cronJob.containers "root" $) | nindent 12 }} restartPolicy: Never {{/* TODO: enable this as needed volumes: - {{- tpl (toYaml . | nindent 8) $ }} + {{- tpl (toYaml . | nindent 12) $ }} {{- end }} {{- with .Values.nodeSelector }} nodeSelector: - {{- toYaml . | nindent 8 }} + {{- toYaml . | nindent 12 }} {{- end }} {{- with .Values.affinity }} affinity: - {{- toYaml . | nindent 8 }} + {{- toYaml . | nindent 12 }} {{- end }} {{- with .Values.tolerations }} tolerations: - {{- toYaml . | nindent 8 }} + {{- toYaml . | nindent 12 }} {{- end }} */}} --- diff --git a/charts/wandb-base/values.yaml b/charts/wandb-base/values.yaml index cf0a7066..c3ab213d 100644 --- a/charts/wandb-base/values.yaml +++ b/charts/wandb-base/values.yaml @@ -50,7 +50,7 @@ securityContext: initContainers: [] containers: - - name: nginx + nginx: command: [] args: [] env: {} @@ -82,6 +82,80 @@ containers: memory: 128Mi volumeMounts: [] +jobs: {} +# example: +# annotations: +# "helm.sh/hook": post-install +# containers: +# nginx: +# command: [ ] +# args: [ ] +# env: { } +# envFrom: { } +# securityContext: { } +# image: { } +# ports: +# - containerPort: 80 +# name: http +# livenessProbe: +# httpGet: +# path: / +# port: http +# readinessProbe: +# httpGet: +# path: / +# port: http +# startupProbe: +# httpGet: +# path: / +# port: http +# lifecycle: { } +# resources: +# limits: +# cpu: 100m +# memory: 128Mi +# requests: +# cpu: 100m +# memory: 128Mi +# volumeMounts: [ ] + +cronJobs: {} +# example: +# schedule: "*/5 * * * *" +# annotations: { } +# containers: +# nginx: +# command: [ ] +# args: [ ] +# env: { } +# envFrom: { } +# securityContext: { } +# image: { } +# ports: +# - containerPort: 80 +# name: http +# livenessProbe: +# httpGet: +# path: / +# port: http +# readinessProbe: +# httpGet: +# path: / +# port: http +# startupProbe: +# httpGet: +# path: / +# port: http +# lifecycle: { } +# resources: +# limits: +# cpu: 100m +# memory: 128Mi +# requests: +# cpu: 100m +# memory: 128Mi +# volumeMounts: [ ] + # This is for setting up a service more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/ service: enabled: true From 94b30b534dda97de5fb068d15be5e1b0d015e40f Mon Sep 17 00:00:00 2001 From: Daniel Panzella Date: Thu, 26 Dec 2024 11:51:56 -0800 Subject: [PATCH 3/4] fix: bump chart version --- charts/wandb-base/Chart.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/wandb-base/Chart.yaml b/charts/wandb-base/Chart.yaml index 7d791b5b..6b94c6c4 100644 --- a/charts/wandb-base/Chart.yaml +++ b/charts/wandb-base/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 name: wandb-base description: A generic helm chart for deploying services to kubernetes type: application -version: 0.1.1 +version: 0.2.0 icon: https://wandb.ai/logo.svg maintainers: From e1c928f97e093604f3bf49041777bb39c5b46a6c Mon Sep 17 00:00:00 2001 From: Daniel Panzella Date: Thu, 26 Dec 2024 13:31:25 -0800 Subject: [PATCH 4/4] fix: multiple containers and default values --- charts/operator-wandb/Chart.lock | 6 +- charts/operator-wandb/values.yaml | 2 +- charts/wandb-base/templates/_containers.tpl | 18 +++--- charts/wandb-base/values.yaml | 64 ++++++++++----------- 4 files changed, 45 insertions(+), 45 deletions(-) diff --git a/charts/operator-wandb/Chart.lock b/charts/operator-wandb/Chart.lock index b2941e87..eb0985d9 100644 --- a/charts/operator-wandb/Chart.lock +++ b/charts/operator-wandb/Chart.lock @@ -55,6 +55,6 @@ dependencies: version: 0.1.0 - name: wandb-base repository: file://../wandb-base - version: 0.1.1 -digest: sha256:3c02029e1921428d7f45866291a8c42b79894505ee47864c54f34fcd847b2793 -generated: "2024-12-19T11:00:55.672581+05:30" + version: 0.2.0 +digest: sha256:4a8dbdef20db07f9ed7e39f3353aa265a310b025637b15e19d3f149f601894e0 +generated: "2024-12-26T13:14:12.979282-08:00" diff --git a/charts/operator-wandb/values.yaml b/charts/operator-wandb/values.yaml index bffd0908..39d96f4d 100644 --- a/charts/operator-wandb/values.yaml +++ b/charts/operator-wandb/values.yaml @@ -496,7 +496,7 @@ glue: "{{ .Release.Name }}-glue-secret": "secretRef" "{{ .Release.Name }}-glue-configmap": "configMapRef" containers: - - name: glue + glue: args: ["glue"] env: {} envFrom: {} diff --git a/charts/wandb-base/templates/_containers.tpl b/charts/wandb-base/templates/_containers.tpl index ac7545fb..adab8a42 100644 --- a/charts/wandb-base/templates/_containers.tpl +++ b/charts/wandb-base/templates/_containers.tpl @@ -2,8 +2,8 @@ wandb-base.containers should be passed a dict with key `containers` containing the map of containers and a key `root` containing the . from the calling context */}} -{{- define "wandb-base.containers" }} -{{- range $containerName, $containerSource := .containers}} +{{- define "wandb-base.containers" -}} +{{- range $containerName, $containerSource := .containers -}} {{- $container := dict }} {{- $_ := deepCopy $containerSource | merge $container }} {{- $_ = set $container "name" $containerName }} @@ -16,7 +16,7 @@ {{- end }} {{- end }} -{{- define "wandb-base.container" -}} +{{- define "wandb-base.container" }} - name: {{ .name }} {{- if .command }} command: @@ -70,19 +70,19 @@ {{- end }} {{- end }} -{{- define "wandb-base.env" }} -{{- range $key, $value := .env }} +{{- define "wandb-base.env" -}} +{{- range $key, $value := .env -}} {{- if kindIs "string" $value }} - name: {{ $key }} value: {{ $value | quote }} {{- else }} - name: {{ $key }} {{- toYaml $value | nindent 2 }} -{{- end }} -{{- end }} -{{- end }} +{{- end -}} +{{- end -}} +{{- end -}} -{{- define "wandb-base.envFrom" }} +{{- define "wandb-base.envFrom" -}} {{- range $key, $value := .envFrom }} - {{ $value }}: name: {{ $key }} diff --git a/charts/wandb-base/values.yaml b/charts/wandb-base/values.yaml index c3ab213d..ee646270 100644 --- a/charts/wandb-base/values.yaml +++ b/charts/wandb-base/values.yaml @@ -49,38 +49,38 @@ securityContext: initContainers: [] -containers: - nginx: - command: [] - args: [] - env: {} - envFrom: {} - securityContext: {} - image: {} - ports: - - containerPort: 80 - name: http - livenessProbe: - httpGet: - path: / - port: http - readinessProbe: - httpGet: - path: / - port: http - startupProbe: - httpGet: - path: / - port: http - lifecycle: {} - resources: - limits: - cpu: 100m - memory: 128Mi - requests: - cpu: 100m - memory: 128Mi - volumeMounts: [] +containers: {} +# nginx: +# command: [] +# args: [] +# env: {} +# envFrom: {} +# securityContext: {} +# image: {} +# ports: +# - containerPort: 80 +# name: http +# livenessProbe: +# httpGet: +# path: / +# port: http +# readinessProbe: +# httpGet: +# path: / +# port: http +# startupProbe: +# httpGet: +# path: / +# port: http +# lifecycle: {} +# resources: +# limits: +# cpu: 100m +# memory: 128Mi +# requests: +# cpu: 100m +# memory: 128Mi +# volumeMounts: [] jobs: {} # example: