Cronjob
This commit is contained in:
@@ -0,0 +1 @@
|
||||
tests
|
||||
@@ -0,0 +1,18 @@
|
||||
apiVersion: v2
|
||||
name: cron-job
|
||||
description: One chart to rule them all. A generic Helm chart for your application deployments. Because no-one can remember the Kubernetes yaml syntax.
|
||||
|
||||
# A chart can be either an 'application' or a 'library' chart.
|
||||
#
|
||||
# Application charts are a collection of templates that can be packaged into versioned archives
|
||||
# to be deployed.
|
||||
#
|
||||
# Library charts provide useful utilities or functions for the chart developer. They're included as
|
||||
# a dependency of application charts to inject those utilities and functions into the rendering
|
||||
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
|
||||
type: application
|
||||
|
||||
# This is the chart version. This version number should be incremented each time you make changes
|
||||
# to the chart and its templates, including the app version.
|
||||
# Versions are expected to follow Semantic Versioning (https://semver.org/)
|
||||
version: 0.1.0
|
||||
@@ -0,0 +1 @@
|
||||
TODO intro text
|
||||
@@ -0,0 +1,63 @@
|
||||
{{/* vim: set filetype=mustache: */}}
|
||||
{{/*
|
||||
Expand the name of the chart.
|
||||
*/}}
|
||||
{{- define "helm-chart.name" -}}
|
||||
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
|
||||
{{- end }}
|
||||
|
||||
{{/*
|
||||
Create a default fully qualified app name.
|
||||
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
|
||||
If release name contains chart name it will be used as a full name.
|
||||
*/}}
|
||||
{{- define "helm-chart.fullname" -}}
|
||||
{{- if .Values.fullnameOverride }}
|
||||
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
|
||||
{{- else }}
|
||||
{{- $name := default .Chart.Name .Values.nameOverride }}
|
||||
{{- if contains $name .Release.Name }}
|
||||
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
|
||||
{{- else }}
|
||||
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
{{/*
|
||||
Create chart name and version as used by the chart label.
|
||||
*/}}
|
||||
{{- define "helm-chart.chart" -}}
|
||||
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
|
||||
{{- end }}
|
||||
|
||||
{{/*
|
||||
Common labels
|
||||
*/}}
|
||||
{{- define "helm-chart.labels" -}}
|
||||
helm.sh/chart: {{ include "helm-chart.chart" . }}
|
||||
{{ include "helm-chart.selectorLabels" . }}
|
||||
{{- if .Chart.AppVersion }}
|
||||
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
|
||||
{{- end }}
|
||||
app.kubernetes.io/managed-by: {{ .Release.Service }}
|
||||
{{- end }}
|
||||
|
||||
{{/*
|
||||
Selector labels
|
||||
*/}}
|
||||
{{- define "helm-chart.selectorLabels" -}}
|
||||
app.kubernetes.io/name: {{ include "helm-chart.name" . }}
|
||||
app.kubernetes.io/instance: {{ .Release.Name }}
|
||||
{{- end }}
|
||||
|
||||
{{/*
|
||||
Create the name of the service account to use
|
||||
*/}}
|
||||
{{- define "helm-chart.serviceAccountName" -}}
|
||||
{{- if .Values.serviceAccount.create }}
|
||||
{{- default (include "helm-chart.fullname" .) .Values.serviceAccount.name }}
|
||||
{{- else }}
|
||||
{{- default "default" .Values.serviceAccount.name }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
@@ -0,0 +1,13 @@
|
||||
{{- if .Values.vars }}
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: {{ .Release.Name }}
|
||||
namespace: {{ .Release.Namespace }}
|
||||
labels:
|
||||
{{- include "helm-chart.labels" . | nindent 4 }}
|
||||
data:
|
||||
{{- range $key, $val := .Values.vars }}
|
||||
{{ $key }}: {{ $val | quote }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
@@ -0,0 +1,66 @@
|
||||
apiVersion: batch/v1beta1
|
||||
kind: CronJob
|
||||
metadata:
|
||||
name: {{ .Release.Name }}
|
||||
namespace: {{ .Release.Namespace }}
|
||||
labels:
|
||||
{{ include "helm-chart.labels" . | nindent 4 }}
|
||||
spec:
|
||||
schedule: {{ .Values.schedule }}
|
||||
successfulJobsHistoryLimit: 1
|
||||
failedJobsHistoryLimit: 1
|
||||
concurrencyPolicy: Forbid
|
||||
startingDeadlineSeconds: 120
|
||||
jobTemplate:
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
{{- with .Values.imagePullSecrets }}
|
||||
imagePullSecrets:
|
||||
{{- toYaml . | nindent 12 }}
|
||||
{{- end }}
|
||||
restartPolicy: Never
|
||||
containers:
|
||||
- name: {{ .Release.Name }}
|
||||
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
|
||||
{{- if .Values.vars }}
|
||||
imagePullPolicy: {{ .Values.image.pullPolicy }}
|
||||
{{- end }}
|
||||
command:
|
||||
- {{ .Values.shell | default "/bin/sh" }}
|
||||
- -c
|
||||
- {{ .Values.command | default "echo I'm alive" | quote }}
|
||||
envFrom:
|
||||
{{- if .Values.vars }}
|
||||
- configMapRef:
|
||||
name: {{ .Release.Name }}
|
||||
{{- end }}
|
||||
{{- if .Values.secret.enabled }}
|
||||
- secretRef:
|
||||
name: {{ .Release.Name }}
|
||||
{{- end }}
|
||||
volumeMounts:
|
||||
{{- range .Values.volumes }}
|
||||
- name: {{ .name }}
|
||||
mountPath: {{ .path }}
|
||||
{{- end }}
|
||||
resources:
|
||||
{{ toYaml .Values.resources | nindent 16 }}
|
||||
volumes:
|
||||
{{- range .Values.volumes }}
|
||||
- name: {{ .name }}
|
||||
persistentVolumeClaim:
|
||||
claimName: {{ printf "%s-%s" $.Release.Name .name }}
|
||||
{{- 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 }}
|
||||
@@ -0,0 +1,15 @@
|
||||
{{- range .Values.volumes }}
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: {{ printf "%s-%s" $.Release.Name .name }}
|
||||
namespace: {{ $.Release.Namespace }}
|
||||
spec:
|
||||
accessModes:
|
||||
- {{ .accessMode | default "ReadWriteOnce" }}
|
||||
storageClassName: {{ .storageClass | default "local-path" }}
|
||||
resources:
|
||||
requests:
|
||||
storage: {{ .size | default "1Gi" }}
|
||||
{{- end }}
|
||||
@@ -0,0 +1,15 @@
|
||||
suite: test cron job
|
||||
templates:
|
||||
- configmap.yaml
|
||||
tests:
|
||||
- it: Should put vars in ConfigMap
|
||||
set:
|
||||
vars:
|
||||
var1: value1
|
||||
var2: value2
|
||||
asserts:
|
||||
- equal:
|
||||
path: data
|
||||
value:
|
||||
var1: value1
|
||||
var2: value2
|
||||
@@ -0,0 +1,20 @@
|
||||
suite: test cron job
|
||||
templates:
|
||||
- cronJob.yaml
|
||||
- configmap.yaml
|
||||
tests:
|
||||
- it: Should set command
|
||||
set:
|
||||
command: "while true; do date; sleep 2; done"
|
||||
asserts:
|
||||
- equal:
|
||||
path: spec.jobTemplate.spec.template.spec.containers[0].command
|
||||
value: ['/bin/sh', '-c', 'while true; do date; sleep 2; done']
|
||||
- it: Should set shell and command
|
||||
set:
|
||||
command: "while true; do date; sleep 2; done"
|
||||
shell: "/bin/ash"
|
||||
asserts:
|
||||
- equal:
|
||||
path: spec.jobTemplate.spec.template.spec.containers[0].command
|
||||
value: ['/bin/ash', '-c','while true; do date; sleep 2; done']
|
||||
@@ -0,0 +1,20 @@
|
||||
suite: test deployment
|
||||
templates:
|
||||
- cronJob.yaml
|
||||
- configmap.yaml
|
||||
tests:
|
||||
- it: Should reference configmap if vars are set
|
||||
set:
|
||||
vars:
|
||||
var1: value1
|
||||
var2: value2
|
||||
asserts:
|
||||
- contains:
|
||||
path: spec.jobTemplate.spec.template.spec.containers[0].envFrom
|
||||
content:
|
||||
configMapRef:
|
||||
name: RELEASE-NAME
|
||||
- it: Should not reference configmap if vars are not set
|
||||
asserts:
|
||||
- isNull:
|
||||
path: spec.jobTemplate.spec.template.spec.containers[0].envFrom
|
||||
@@ -0,0 +1,22 @@
|
||||
suite: test cron job
|
||||
templates:
|
||||
- cronJob.yaml
|
||||
- configmap.yaml
|
||||
tests:
|
||||
- it: Should set image and tag
|
||||
set:
|
||||
image.repository: nginx
|
||||
image.tag: x.y.z
|
||||
asserts:
|
||||
- equal:
|
||||
path: spec.jobTemplate.spec.template.spec.containers[0].image
|
||||
value: nginx:x.y.z
|
||||
- it: Should set an ImagePullSecret
|
||||
set:
|
||||
imagePullSecrets:
|
||||
- name: regcred
|
||||
asserts:
|
||||
- equal:
|
||||
path: spec.jobTemplate.spec.template.spec.imagePullSecrets
|
||||
value:
|
||||
- name: regcred
|
||||
@@ -0,0 +1,20 @@
|
||||
suite: test cron job
|
||||
templates:
|
||||
- cronJob.yaml
|
||||
- configmap.yaml
|
||||
tests:
|
||||
- it: Should reference secret if secret is enabled
|
||||
set:
|
||||
secret.enabled: true
|
||||
asserts:
|
||||
- contains:
|
||||
path: spec.jobTemplate.spec.template.spec.containers[0].envFrom
|
||||
content:
|
||||
secretRef:
|
||||
name: RELEASE-NAME
|
||||
- it: Should not reference secret if secret is disabled
|
||||
set:
|
||||
secret.enabled: false
|
||||
asserts:
|
||||
- isNull:
|
||||
path: spec.jobTemplate.spec.template.spec.containers[0].envFrom
|
||||
@@ -0,0 +1,33 @@
|
||||
suite: test cron job
|
||||
templates:
|
||||
- cronJob.yaml
|
||||
- configmap.yaml
|
||||
- pvc.yaml
|
||||
tests:
|
||||
- it: Should mount volume
|
||||
set:
|
||||
volumes:
|
||||
- name: data
|
||||
path: /var/lib/1clickinfra/data
|
||||
size: 10Gi
|
||||
storageClass: default
|
||||
asserts:
|
||||
- equal:
|
||||
path: spec.jobTemplate.spec.template.spec.containers[0].volumeMounts
|
||||
value:
|
||||
- name: data
|
||||
mountPath: /var/lib/1clickinfra/data
|
||||
- it: Should reference volume
|
||||
set:
|
||||
volumes:
|
||||
- name: data
|
||||
path: /var/lib/1clickinfra/data
|
||||
size: 10Gi
|
||||
storageClass: default
|
||||
asserts:
|
||||
- equal:
|
||||
path: spec.jobTemplate.spec.template.spec.volumes
|
||||
value:
|
||||
- name: data
|
||||
persistentVolumeClaim:
|
||||
claimName: RELEASE-NAME-data
|
||||
@@ -0,0 +1,15 @@
|
||||
suite: test cron job
|
||||
templates:
|
||||
- pvc.yaml
|
||||
tests:
|
||||
- it: Should create PVC
|
||||
set:
|
||||
volumes:
|
||||
- name: data
|
||||
path: /var/lib/1clickinfra/data
|
||||
size: 10Gi
|
||||
storageClass: default
|
||||
asserts:
|
||||
- equal:
|
||||
path: spec.storageClassName
|
||||
value: default
|
||||
@@ -0,0 +1,24 @@
|
||||
image:
|
||||
repository: debian
|
||||
tag: stable-slim
|
||||
|
||||
nameOverride: ""
|
||||
fullnameOverride: ""
|
||||
|
||||
podAnnotations: {}
|
||||
|
||||
podSecurityContext:
|
||||
fsGroup: 999
|
||||
|
||||
securityContext: {}
|
||||
|
||||
resources: {}
|
||||
|
||||
nodeSelector: {}
|
||||
|
||||
tolerations: []
|
||||
|
||||
affinity: {}
|
||||
|
||||
secret:
|
||||
enabled: false
|
||||
@@ -33,7 +33,10 @@ spec:
|
||||
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
|
||||
imagePullPolicy: {{ .Values.image.pullPolicy }}
|
||||
{{- if .Values.command }}
|
||||
command: ['{{ .Values.shell | default "/bin/sh" }}', "-c", {{ .Values.command | quote }}]
|
||||
command:
|
||||
- {{ .Values.shell | default "/bin/sh" }}
|
||||
- -c
|
||||
- {{ .Values.command | quote }}
|
||||
{{- end }}
|
||||
envFrom:
|
||||
{{- if .Values.vars }}
|
||||
|
||||
Reference in New Issue
Block a user