Skip to content

Commit

Permalink
feat: 0.5.0 add basic support for crons
Browse files Browse the repository at this point in the history
  • Loading branch information
Wojciech Międzybrodzki committed Jan 13, 2025
1 parent 2aeb2f8 commit 45b64da
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ appVersion: 1.0.0

dependencies:
- name: app
version: 0.4.0
version: 0.5.0
repository: https://wojciechem.github.io/platformex
```
For values please see [values-example.yaml](charts/app/values-example.yaml)
## TODO:
- Chart
- [ ] Mimimal stable v1.0.0
- [ ] Minimal stable v1.0.0
- [ ] Tests
- [Ingress routes](charts/app/templates/_ingressroute.tpl)
- [ ] custom service definitions for traefik ingressroutes (see https://doc.traefik.io/traefik/routing/providers/kubernetes-crd/#kind-ingressroute)
Expand Down
2 changes: 1 addition & 1 deletion charts/app/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: Flexible helm chart to deploy your apps to kubernetes cluster.
type: application

# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.4.0
version: 0.5.0

appVersion: 1.0.0

5 changes: 5 additions & 0 deletions charts/app/templates/_cron.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{- define "platformex.cron.suspend" }}
{{- if eq .instance.enableCrons false }}
suspend: "true"
{{- end }}
{{- end }}
47 changes: 47 additions & 0 deletions charts/app/templates/cronjob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
apiVersion: v1
kind: List
items:
{{- range $iname, $instance := .Values.instances }}
{{- range $cname, $cron := $instance.crons }}
{{- $cronContext := dict "iname" $iname "instance" $instance "name" $cname "deployment" $cron "root" $ }}
- apiVersion: batch/v1
kind: CronJob
metadata:
name: {{ $iname }}-{{$cname}}
labels:
{{- include "platformex.kubernetesAppLabels" $cronContext | indent 10 }}
{{- include "platformex.globalLabels" $ | indent 10 }}
spec:
concurrencyPolicy: {{ $cron.concurrencyPolicy | default "Forbid" }}
failedJobsHistoryLimit: {{ $cron.failedJobsHistoryLimit | default 2 }}
schedule: {{ required "schedule is required!" $cron.schedule | quote }}
timeZone: {{ $cron.timezone | default "UTC" }}
{{- include "platformex.cron.suspend" $cronContext | indent 6 }}
startingDeadlineSeconds: {{ $cron.startingDeadlineSeconds | default 10 }}
successfulJobsHistoryLimit: {{ $cron.successfulJobsHistoryLimit | default 2 }}
jobTemplate:
spec:
backoffLimit: {{ $cron.jobTemplate.backoffLimit | default 2 }}
template:
metadata:
labels:
{{- include "platformex.kubernetesAppLabels" $cronContext | indent 16 }}
spec:
{{- include "platformex.deployment.volumes" $cronContext | indent 14 }}
{{- include "platformex.deployment.nodeSelector" $cronContext | indent 14 }}
{{- include "platformex.deployment.imagePullSecrets" $cronContext | indent 14 }}
restartPolicy: {{ $cron.restartPolicy | default "OnFailure" }}
{{- if $cron.initContainers }}
initContainers:
{{- range $icName, $initContainer := $cron.initContainers }}
{{- $icContext := dict "iname" $iname "instance" $instance "name" $icName "container" $initContainer "root" $ }}
- {{- include "platformex.containerFull" $icContext | indent 14 }}
{{- end }}
{{- end }}
containers:
{{- range $cName, $container := $cron.containers }}
{{- $containerContext := dict "iname" $iname "instance" $instance "name" $cName "container" $container "root" $ }}
- {{- include "platformex.containerFull" $cronContext | indent 14 }}
{{- end }}
{{- end }}
{{- end }}
File renamed without changes.
9 changes: 8 additions & 1 deletion charts/app/values-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ instances:
default:
enableCrons: true
enableWorkers: true
crons: { }
crons:
legendary-cron-at-midnight:
concurrencyPolicy: "Replace"
failedJobsHistoryLimit: 2
schedule: "0 0 * * *"
timezone: "Europe/Warsaw"
jobTemplate: { }
containers: { }
deployments:
consumer-xyz:
worker: true
Expand Down
15 changes: 4 additions & 11 deletions charts/app/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,7 @@
},
"Cron": {
"type": "object",
"additionalProperties": false,
"properties": {
"CRON_MODE": {
"type": "string",
"format": "integer"
}
},
"required": [
"CRON_MODE"
],
"additionalProperties": true,
"title": "Cron"
},
"Global": {
Expand Down Expand Up @@ -158,7 +149,9 @@
},
"Crons": {
"type": "object",
"additionalProperties": false,
"additionalProperties": {
"$ref": "#/definitions/Cron"
},
"title": "Crons"
},
"Deployments": {
Expand Down

0 comments on commit 45b64da

Please sign in to comment.