Skip to content

Commit

Permalink
Merge pull request #32 from WyriHaximusNet/add-cron-jobs-library-chart
Browse files Browse the repository at this point in the history
Add cron-jobs library chart
  • Loading branch information
WyriHaximus authored Oct 11, 2020
2 parents 1dc514d + b42dba8 commit 8fad22f
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/helm-charts-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ jobs:
installLocalPathProvisioner: true
# Only build a kind cluster if there are chart changes to test.

- name: Prepare library charts
run: |
cp charts/cron-jobs/library-ci/*.yaml charts/cron-jobs/templates/
sed -i 's/library/application/g' charts/cron-jobs/Chart.yaml
- name: Test charts
uses: helm/[email protected]
with:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Opinionated helm chats for my personal projects, and OSS Projects that either do

## Charts in this repository

* [`cron-jobs`](https://hub.helm.sh/charts/wyrihaximusnet/cron-jobs)
* [`default-backend`](https://hub.helm.sh/charts/wyrihaximusnet/default-backend)
* [`docker-hub-exporter`](https://hub.helm.sh/charts/wyrihaximusnet/docker-hub-exporter)
* [`redirect`](https://hub.helm.sh/charts/wyrihaximusnet/redirect)
Expand Down
22 changes: 22 additions & 0 deletions charts/cron-jobs/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
10 changes: 10 additions & 0 deletions charts/cron-jobs/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v2
name: cron-jobs
description: CronJobs library
home: https://github.com/wyrihaximusnet/helm-charts
icon: https://helm.wyrihaximus.net/images/charts/cron-jobs.png
type: library
version: 0.1.0
maintainers:
- name: WyriHaximus
email: [email protected]
48 changes: 48 additions & 0 deletions charts/cron-jobs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Cron Jobs

Opinionated helm library chart for easy creation of cron jobs.

# Example

Very basic example without any customization:

```gotemplate
{{- range $job := .Values.jobs }}
{{- include "cron-jobs.cronjob" $job -}}
{{- end }}
```

The following values will run a cronjob that sleeps for 1 second any minute

```yaml
jobs:
- name: sleep
schedule: "* * * * *"
labels:
cronjob:
key: value
jobTemplate:
key: value
container:
command: ["sleep"]
args: ["1"]
resources:
limits:
cpu: 1m
memory: 12Mi
requests:
cpu: 1m
memory: 12Mi
image:
repository: alpine
tag: 3.12
pullPolicy: IfNotPresent
```
## Opinionated decisions
* A history of `3` failed and `3` successful jobs are kept around for log checking.
* No restarts
* No concurrently
* A single container per cron job
* `cron` and `name` labels are set on each cron job with the name you give it
22 changes: 22 additions & 0 deletions charts/cron-jobs/ci/sleep-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
jobs:
- name: sleep
schedule: "* * * * *"
labels:
cronjob:
key: value
jobTemplate:
key: value
container:
command: ["sleep"]
args: ["1"]
resources:
limits:
cpu: 1m
memory: 12Mi
requests:
cpu: 1m
memory: 12Mi
image:
repository: alpine
tag: 3.12
pullPolicy: IfNotPresent
3 changes: 3 additions & 0 deletions charts/cron-jobs/library-ci/cronjob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{- range $job := .Values.jobs }}
{{- include "cron-jobs.cronjob" $job -}}
{{- end }}
40 changes: 40 additions & 0 deletions charts/cron-jobs/templates/_cronjob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{{- define "cron-jobs.cronjob" }}
---
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: "{{ .name }}"
labels:
name: {{ .name }}
cron: {{ .name }}
{{- with .labels.cronjob }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
schedule: {{ .schedule | quote }}
concurrencyPolicy: Forbid
failedJobsHistoryLimit: 3
successfulJobsHistoryLimit: 3
jobTemplate:
spec:
template:
metadata:
labels:
name: {{ .name }}
cron: {{ .name }}
{{- with .labels.jobTemplate }}
{{- toYaml . | nindent 12 }}
{{- end }}
spec:
{{- with .spec }}
{{- toYaml . | nindent 10 }}
{{- end }}
containers:
- name: {{ .name }}
image: "{{ .image.repository }}:{{ .image.tag }}"
imagePullPolicy: {{ .image.imagePullPolicy }}
{{- with .container }}
{{- toYaml . | nindent 12 }}
{{- end }}
restartPolicy: Never
{{- end }}
Empty file added charts/cron-jobs/values.yaml
Empty file.

0 comments on commit 8fad22f

Please sign in to comment.