This commit is contained in:
Laszlo Fogas
2020-10-14 11:27:08 +02:00
parent 4e380769d5
commit 6de2265969
20 changed files with 385 additions and 13 deletions
+12
View File
@@ -3,6 +3,7 @@ all: lint kubeval test package
lint:
helm lint charts/onechart/
helm lint charts/cron-job/
kubeval:
rm -rf manifests && true
@@ -11,10 +12,21 @@ kubeval:
find manifests/ -name '*.yaml' | xargs kubeval --ignore-missing-schemas -v 1.13.0
find manifests/ -name '*.yaml' | xargs kubeval --ignore-missing-schemas -v 1.18.0
rm -rf manifests && true
mkdir manifests
helm template charts/cron-job --output-dir manifests
find manifests/ -name '*.yaml' | xargs kubeval --ignore-missing-schemas -v 1.13.0
find manifests/ -name '*.yaml' | xargs kubeval --ignore-missing-schemas -v 1.18.0
test:
helm unittest charts/onechart
helm unittest charts/cron-job
package:
helm package charts/onechart
mv onechart*.tgz docs
helm package charts/cron-job
mv cron-job*.tgz docs
helm repo index docs --url https://chart.onechart.dev
+1
View File
@@ -0,0 +1 @@
tests
+18
View File
@@ -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
+1
View File
@@ -0,0 +1 @@
TODO intro text
+63
View File
@@ -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 }}
+13
View File
@@ -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 }}
+66
View File
@@ -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 }}
+15
View File
@@ -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 }}
+15
View File
@@ -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
+15
View File
@@ -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
+24
View File
@@ -0,0 +1,24 @@
image:
repository: debian
tag: stable-slim
nameOverride: ""
fullnameOverride: ""
podAnnotations: {}
podSecurityContext:
fsGroup: 999
securityContext: {}
resources: {}
nodeSelector: {}
tolerations: []
affinity: {}
secret:
enabled: false
+4 -1
View File
@@ -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 }}
Binary file not shown.
+22 -11
View File
@@ -1,8 +1,19 @@
apiVersion: v1
entries:
cron-job:
- apiVersion: v2
created: "2020-10-14T11:25:32.418324186+02:00"
description: One chart to rule them all. A generic Helm chart for your application
deployments. Because no-one can remember the Kubernetes yaml syntax.
digest: 01f9fa40c1c4085d7688474ab00c9e9d21bd1d0793db6b75f2edda0e18456282
name: cron-job
type: application
urls:
- https://chart.onechart.dev/cron-job-0.1.0.tgz
version: 0.1.0
onechart:
- apiVersion: v2
created: "2020-10-14T09:34:06.230060461+02:00"
created: "2020-10-14T11:25:32.421423716+02:00"
description: One chart to rule them all. A generic Helm chart for your application
deployments. Because no-one can remember the Kubernetes yaml syntax.
digest: 908cfb08f208b6e70c40ba3a3b25a4110ee8a544c850dd29452252f3629673d8
@@ -12,7 +23,7 @@ entries:
- https://chart.onechart.dev/onechart-0.5.1.tgz
version: 0.5.1
- apiVersion: v2
created: "2020-10-14T09:34:06.229759152+02:00"
created: "2020-10-14T11:25:32.421155288+02:00"
description: One chart to rule them all. A generic Helm chart for your application
deployments. Because no-one can remember the Kubernetes yaml syntax.
digest: adf3c2cf3a27e58ec75620599e0e1c2031a7410a061a590317beeff6d8a9ad69
@@ -22,7 +33,7 @@ entries:
- https://chart.onechart.dev/onechart-0.5.0.tgz
version: 0.5.0
- apiVersion: v2
created: "2020-10-14T09:34:06.229500315+02:00"
created: "2020-10-14T11:25:32.420862678+02:00"
description: One chart to rule them all. A generic Helm chart for your application
deployments. Because no-one can remember the Kubernetes yaml syntax.
digest: 8dab33263c4e632aeb4656c666871440b589497b70e76a1d6c3a5e3db1a30bba
@@ -32,7 +43,7 @@ entries:
- https://chart.onechart.dev/onechart-0.4.0.tgz
version: 0.4.0
- apiVersion: v2
created: "2020-10-14T09:34:06.229230124+02:00"
created: "2020-10-14T11:25:32.420579859+02:00"
description: A generic Helm chart for your application deployments
digest: fbaf6139e0ef8ad9a87cc1e41a97c7d25fdcf7ea17fa6364952f1a851a87480a
name: onechart
@@ -41,7 +52,7 @@ entries:
- https://chart.onechart.dev/onechart-0.3.2.tgz
version: 0.3.2
- apiVersion: v2
created: "2020-10-14T09:34:06.228816205+02:00"
created: "2020-10-14T11:25:32.420325378+02:00"
description: A generic Helm chart for your application deployments
digest: bd6f5b1865ab9b05fc6925c163ab8045235bd2723dba31f09d5083d24322d1f8
name: onechart
@@ -50,7 +61,7 @@ entries:
- https://chart.onechart.dev/onechart-0.3.1.tgz
version: 0.3.1
- apiVersion: v2
created: "2020-10-14T09:34:06.228132759+02:00"
created: "2020-10-14T11:25:32.420090272+02:00"
description: A generic Helm chart for your application deployments
digest: c79cef21eceab948144a289298cdf1e20e77a0782a883d7d65f9e709ccbbc271
name: onechart
@@ -59,7 +70,7 @@ entries:
- https://chart.onechart.dev/onechart-0.3.0.tgz
version: 0.3.0
- apiVersion: v2
created: "2020-10-14T09:34:06.227886145+02:00"
created: "2020-10-14T11:25:32.41985697+02:00"
description: A generic Helm chart for your application deployments
digest: dd814ac5d08d5e6163a1b769df6803f5cb0f09d906045086dfcc5be522bb1ec3
name: onechart
@@ -68,7 +79,7 @@ entries:
- https://chart.onechart.dev/onechart-0.2.0.tgz
version: 0.2.0
- apiVersion: v2
created: "2020-10-14T09:34:06.227640669+02:00"
created: "2020-10-14T11:25:32.41961541+02:00"
description: A generic Helm chart for your application deployments
digest: e46062df8053840cbfbba26c0a66a843a79f15a0b43a145ed019327513bd5098
name: onechart
@@ -77,7 +88,7 @@ entries:
- https://chart.onechart.dev/onechart-0.1.2.tgz
version: 0.1.2
- apiVersion: v2
created: "2020-10-14T09:34:06.227399043+02:00"
created: "2020-10-14T11:25:32.419338908+02:00"
description: A generic Helm chart for your application deployments
digest: a7bbc8b7dcc008e89156cd1830282b7d39c0592e82ccdcefb77a25a42eca2a3d
name: onechart
@@ -86,7 +97,7 @@ entries:
- https://chart.onechart.dev/onechart-0.1.1.tgz
version: 0.1.1
- apiVersion: v2
created: "2020-10-14T09:34:06.227153075+02:00"
created: "2020-10-14T11:25:32.418735142+02:00"
description: A generic Helm chart for your application deployments
digest: 1ed8c0645abdae6c950526e9c5410dc056847a11700dc7def5f1c55eb7de0cd4
name: onechart
@@ -94,4 +105,4 @@ entries:
urls:
- https://chart.onechart.dev/onechart-0.1.0.tgz
version: 0.1.0
generated: "2020-10-14T09:34:06.226773674+02:00"
generated: "2020-10-14T11:25:32.417959233+02:00"
+1 -1
View File
@@ -18,7 +18,7 @@ image:
repository: debian
tag: stable-slim
schedule: "0 1 0 0 0"
schedule: "*/1 * * * *"
command: |
echo "hello"
EOF