Skip to content

Commit

Permalink
simple-cronjob: 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
elephantum committed Mar 13, 2024
1 parent 587c971 commit d1167c5
Show file tree
Hide file tree
Showing 15 changed files with 850 additions and 0 deletions.
23 changes: 23 additions & 0 deletions charts/simple-cronjob/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
19 changes: 19 additions & 0 deletions charts/simple-cronjob/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 0.1.4

* Synchonize volumes configuration between simple-app and simple-worker

# 0.1.3

* Synchronize fullname generation between simple-app and simple-worker

# 0.1.2

* Name container the same as release (helps to read logs in GCP)

# 0.1.1

* Add option to mount existing secrets and config maps as volume

# 0.1.0

* Initial release
24 changes: 24 additions & 0 deletions charts/simple-cronjob/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: simple-cronjob
description: A Helm chart for Kubernetes

# 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"

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.16.0"
4 changes: 4 additions & 0 deletions charts/simple-cronjob/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# helm plugin install https://github.com/helm-unittest/helm-unittest.git

test:
helm unittest .
Empty file.
57 changes: 57 additions & 0 deletions charts/simple-cronjob/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "simple-app.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 "simple-app.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "simple-app.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "simple-app.labels" -}}
helm.sh/chart: {{ include "simple-app.chart" . }}
{{ include "simple-app.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "simple-app.selectorLabels" -}}
app.kubernetes.io/name: {{ include "simple-app.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "simple-app.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "simple-app.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
13 changes: 13 additions & 0 deletions charts/simple-cronjob/templates/configs-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{ if .Values.configs }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "simple-app.fullname" . }}
labels:
{{- include "simple-app.labels" . | nindent 4 }}
data:
{{- range .Values.configs }}
{{ .name }}: |
{{- .value | nindent 4 }}
{{- end }}
{{ end }}
112 changes: 112 additions & 0 deletions charts/simple-cronjob/templates/cronjob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{{- $fullName := include "simple-app.fullname" . -}}

apiVersion: batch/v1
kind: CronJob
metadata:
name: {{ include "simple-app.fullname" . }}
labels:
{{- include "simple-app.labels" . | nindent 4 }}
spec:
schedule: "{{ .Values.schedule }}"
timeZone: "{{ .Values.timeZone }}"
concurrencyPolicy: "{{ .Values.concurrencyPolicy }}"
jobTemplate:
spec:
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 12 }}
{{- end }}
labels:
{{- include "simple-app.selectorLabels" . | nindent 12 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 12 }}
{{- end }}
serviceAccountName: {{ include "simple-app.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 12 }}
volumes:
{{- if .Values.shmSize }}
- name: shared-memory
emptyDir:
medium: Memory
sizeLimit: {{ .Values.shmSize }}
{{- end }}
{{- range .Values.volumes }}
- name: {{ .name }}
{{- if .emptyDir }}
emptyDir:
sizeLimit: {{ .size }}
{{- else if .size }}
persistentVolumeClaim:
claimName: {{ $fullName }}-{{ .name }}
{{- else if .configMap }}
configMap:
{{- .configMap | toYaml | nindent 16 }}
{{- else if .secret }}
secret:
{{- .secret | toYaml | nindent 16 }}
{{- end }}
{{- end }}
{{- range .Values.configs }}
- name: configs
configMap:
name: {{ $fullName }}
{{- end }}
restartPolicy: "OnFailure"
containers:
- name: {{ include "simple-app.fullname" . }}
securityContext:
{{- toYaml .Values.securityContext | nindent 16 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- if .Values.command }}
command:
{{- .Values.command | toYaml | nindent 16 }}
{{ end }}
{{- if .Values.env }}
env:
{{- .Values.env | toYaml | nindent 16 }}
{{ end }}
livenessProbe:
exec:
command:
- echo
- ok
readinessProbe:
exec:
command:
- echo
- ok
resources:
{{- toYaml .Values.resources | nindent 16 }}
volumeMounts:
{{- if .Values.shmSize }}
- name: shared-memory
mountPath: /dev/shm
{{- end }}
{{- range .Values.volumes }}
- name: {{ .name }}
mountPath: {{ .mountPath }}
{{- end }}
{{- range .Values.configs }}
- name: configs
mountPath: {{ if .mountPath }}"{{ .mountPath }}"{{ else }}"/configs/{{ .name }}"{{ end }}
subPath: {{ .name }}
readOnly: true
{{- 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 }}
21 changes: 21 additions & 0 deletions charts/simple-cronjob/templates/pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{{- $fullName := include "simple-app.fullname" . -}}
{{- $labels := include "simple-app.labels" . | nindent 4 -}}

{{ range .Values.volumes }}
{{- if not .emptyDir }}
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ $fullName }}-{{ .name }}
labels:
{{- $labels }}
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ .size }}

---
{{ end }}
{{ end }}
12 changes: 12 additions & 0 deletions charts/simple-cronjob/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "simple-app.serviceAccountName" . }}
labels:
{{- include "simple-app.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
81 changes: 81 additions & 0 deletions charts/simple-cronjob/tests/__snapshot__/simple_test.yaml.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
All manifests should match snapshot:
1: |
apiVersion: batch/v1
kind: CronJob
metadata:
labels:
app.kubernetes.io/instance: simple
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: simple-cronjob
app.kubernetes.io/version: 1.16.0
helm.sh/chart: simple-cronjob-0.0.0
name: simple
spec:
concurrencyPolicy: Forbid
jobTemplate:
spec:
template:
metadata:
labels:
app.kubernetes.io/instance: simple
app.kubernetes.io/name: simple-cronjob
spec:
containers:
- env:
- name: TEST
value: test
image: test:1.1.1
imagePullPolicy: IfNotPresent
livenessProbe:
exec:
command:
- echo
- ok
name: simple
readinessProbe:
exec:
command:
- echo
- ok
resources: {}
securityContext: {}
volumeMounts:
- mountPath: /data
name: data
restartPolicy: OnFailure
securityContext: {}
serviceAccountName: simple
volumes:
- name: data
persistentVolumeClaim:
claimName: simple-data
schedule: '*/1 * * * *'
timeZone: GMT
2: |
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
labels:
app.kubernetes.io/instance: simple
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: simple-cronjob
app.kubernetes.io/version: 1.16.0
helm.sh/chart: simple-cronjob-0.0.0
name: simple-data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
3: |
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
app.kubernetes.io/instance: simple
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: simple-cronjob
app.kubernetes.io/version: 1.16.0
helm.sh/chart: simple-cronjob-0.0.0
name: simple
14 changes: 14 additions & 0 deletions charts/simple-cronjob/tests/simple-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# yaml-language-server: $schema=../values.schema.json

image:
repository: test
tag: 1.1.1

env:
- name: TEST
value: test

volumes:
- name: data
size: 1Gi
mountPath: /data
Loading

0 comments on commit d1167c5

Please sign in to comment.