Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for Jobs #297

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions charts/operator-wandb/Chart.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion charts/operator-wandb/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ glue:
"{{ .Release.Name }}-glue-secret": "secretRef"
"{{ .Release.Name }}-glue-configmap": "configMapRef"
containers:
- name: glue
glue:
args: ["glue"]
env: {}
envFrom: {}
Expand Down
2 changes: 1 addition & 1 deletion charts/wandb-base/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
48 changes: 20 additions & 28 deletions charts/wandb-base/templates/_containers.tpl
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
{{- define "wandb-base.containers" }}
{{- range .Values.containers}}
{{/*
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 -}}
{{- $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.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 }}
{{- $_ := 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 }}

Expand Down Expand Up @@ -78,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 }}
Expand Down
56 changes: 56 additions & 0 deletions charts/wandb-base/templates/cronjob
Original file line number Diff line number Diff line change
@@ -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 12 }}
{{- end }}
labels:
{{- include "wandb-base.labels" $ | nindent 12 }}
{{- with $cronJob.podLabels }}
{{- toYaml . | nindent 12 }}
{{- end }}
spec:
{{- with $.Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 12 }}
{{- end }}
serviceAccountName: {{ include "wandb-base.serviceAccountName" $ }}
securityContext:
{{- toYaml $.Values.podSecurityContext | nindent 12 }}
{{- if $cronJob.initContainers }}
initContainers:
{{- include "wandb-base.containers" (dict "containers" $cronJob.initContainers "root" $) | nindent 12 }}
{{- end }}
containers:
{{- include "wandb-base.containers" (dict "containers" $cronJob.containers "root" $) | nindent 12 }}
restartPolicy: Never
{{/* TODO: enable this as needed
volumes:
{{- tpl (toYaml . | nindent 12) $ }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 12 }}
{{- end }}
*/}}
---
{{- end }}
4 changes: 2 additions & 2 deletions charts/wandb-base/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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) $ }}
Expand Down
57 changes: 57 additions & 0 deletions charts/wandb-base/templates/job.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
32 changes: 5 additions & 27 deletions charts/wandb-base/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
Loading
Loading