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: support cronjob specification through values.yaml #24

Merged
Merged
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
2 changes: 1 addition & 1 deletion stack/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ If release name contains chart name it will be used as a full name.
{{- end }}

{{- define "service.fullname" -}}
{{ include "stack.fullname" . }}-{{ include "service.name" . }}
{{ include "stack.fullname" . | lower }}-{{ include "service.name" . | lower }}
{{- end }}

{{/*
Expand Down
51 changes: 51 additions & 0 deletions stack/templates/cronjob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{{ $global := . }}
{{ range $cronJobName, $cronJobValues := .Values.cronJobs }}
{{- $globalValuesDict := $global.Values.global | toYaml -}}
{{- $values := fromYaml $globalValuesDict -}}
{{- $values = set $values "name" $cronJobName -}}
{{- $values := mergeOverwrite $values $cronJobValues -}}
{{- $cronJob := dict "Chart" $global.Chart "Release" $global.Release "Capabilities" $global.Capabilities "Values" $values -}}
{{- with $cronJob -}}
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: {{ include "service.fullname" . }}
spec:
schedule: "{{ .Values.schedule }}"
jobTemplate:
spec:
template:
spec:
{{- if .Values.concurrencyPolicy }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a downside to having the user full control of the entire spec? that way, we don't have keep changing the template if they want support for something like multiple container cronjobs for instance

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont think that is possible with the way we generate some things for them. eg: Argus secrets injection, service accounts, image specification

concurrencyPolicy: {{ .Values.concurrencyPolicy }}
{{- end }}
serviceAccountName: {{ include "service.serviceAccountName" . }}
containers:
- name: {{ include "service.fullname" . }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- if and .Values.args (ne (len .Values.args) 0) }}
args:
{{- toYaml .Values.args | nindent 14 }}
{{- end }}
{{- if and .Values.command (ne (len .Values.command) 0) }}
command:
{{- toYaml .Values.command | nindent 14 }}
{{- end }}
resources:
{{- toYaml .Values.resources | nindent 14 }}
{{- include "service.configuration" . | nindent 12 }}
{{- $env := concat $global.Values.global.env (fromYaml (include "service.nonsensitiveEnvVars" .)).env }}
{{- if $env }}
env:
{{- toYaml (uniq $env) | nindent 14 }}
{{- end }}
restartPolicy: OnFailure
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 12 }}
{{- end }}
---
{{- end }}
{{- end }}
11 changes: 11 additions & 0 deletions stack/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,14 @@ services: {}
# image: sidecar3:latest
# - name: sidecar4
# image: sidecar4:latest

cronJobs: {}
# cronJob1:
# concurrencyPolicy: Forbid
# schedule: "* * * * *"
# image:
# repository: nginx
# pullPolicy: IfNotPresent
# tag: "latest"
# command: ["command1", "command2"]
# args: ["arg1", "arg2"]
Loading