Skip to content

Commit 1ee4263

Browse files
authored
feat(helm): added CRON jobs to helm charts (#1107)
1 parent 60c4668 commit 1ee4263

File tree

3 files changed

+228
-0
lines changed

3 files changed

+228
-0
lines changed

helm/sim/README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,42 @@ The following table lists the configurable parameters and their default values.
314314
| `migrations.podSecurityContext` | Migrations pod security context | `fsGroup: 1001` |
315315
| `migrations.securityContext` | Migrations container security context | `runAsNonRoot: true, runAsUser: 1001` |
316316

317+
### CronJob Parameters
318+
319+
| Parameter | Description | Default |
320+
|-----------|-------------|---------|
321+
| `cronjobs.enabled` | Enable all scheduled cron jobs | `true` |
322+
| `cronjobs.image.repository` | CronJob image repository for HTTP requests | `curlimages/curl` |
323+
| `cronjobs.image.tag` | CronJob image tag | `8.5.0` |
324+
| `cronjobs.image.pullPolicy` | CronJob image pull policy | `IfNotPresent` |
325+
| `cronjobs.resources` | CronJob resource limits and requests | See values.yaml |
326+
| `cronjobs.restartPolicy` | CronJob pod restart policy | `OnFailure` |
327+
| `cronjobs.activeDeadlineSeconds` | CronJob active deadline in seconds | `300` |
328+
| `cronjobs.startingDeadlineSeconds` | CronJob starting deadline in seconds | `60` |
329+
| `cronjobs.podSecurityContext` | CronJob pod security context | `fsGroup: 1001` |
330+
| `cronjobs.securityContext` | CronJob container security context | `runAsNonRoot: true, runAsUser: 1001` |
331+
| `cronjobs.jobs.scheduleExecution.enabled` | Enable schedule execution cron job | `true` |
332+
| `cronjobs.jobs.scheduleExecution.name` | Schedule execution job name | `schedule-execution` |
333+
| `cronjobs.jobs.scheduleExecution.schedule` | Schedule execution cron schedule | `"*/1 * * * *"` |
334+
| `cronjobs.jobs.scheduleExecution.path` | Schedule execution API path | `"/api/schedules/execute"` |
335+
| `cronjobs.jobs.scheduleExecution.concurrencyPolicy` | Schedule execution concurrency policy | `Forbid` |
336+
| `cronjobs.jobs.scheduleExecution.successfulJobsHistoryLimit` | Schedule execution successful jobs history | `3` |
337+
| `cronjobs.jobs.scheduleExecution.failedJobsHistoryLimit` | Schedule execution failed jobs history | `1` |
338+
| `cronjobs.jobs.gmailWebhookPoll.enabled` | Enable Gmail webhook polling cron job | `true` |
339+
| `cronjobs.jobs.gmailWebhookPoll.name` | Gmail webhook polling job name | `gmail-webhook-poll` |
340+
| `cronjobs.jobs.gmailWebhookPoll.schedule` | Gmail webhook polling cron schedule | `"*/1 * * * *"` |
341+
| `cronjobs.jobs.gmailWebhookPoll.path` | Gmail webhook polling API path | `"/api/webhooks/poll/gmail"` |
342+
| `cronjobs.jobs.gmailWebhookPoll.concurrencyPolicy` | Gmail webhook polling concurrency policy | `Forbid` |
343+
| `cronjobs.jobs.gmailWebhookPoll.successfulJobsHistoryLimit` | Gmail webhook polling successful jobs history | `3` |
344+
| `cronjobs.jobs.gmailWebhookPoll.failedJobsHistoryLimit` | Gmail webhook polling failed jobs history | `1` |
345+
| `cronjobs.jobs.outlookWebhookPoll.enabled` | Enable Outlook webhook polling cron job | `true` |
346+
| `cronjobs.jobs.outlookWebhookPoll.name` | Outlook webhook polling job name | `outlook-webhook-poll` |
347+
| `cronjobs.jobs.outlookWebhookPoll.schedule` | Outlook webhook polling cron schedule | `"*/1 * * * *"` |
348+
| `cronjobs.jobs.outlookWebhookPoll.path` | Outlook webhook polling API path | `"/api/webhooks/poll/outlook"` |
349+
| `cronjobs.jobs.outlookWebhookPoll.concurrencyPolicy` | Outlook webhook polling concurrency policy | `Forbid` |
350+
| `cronjobs.jobs.outlookWebhookPoll.successfulJobsHistoryLimit` | Outlook webhook polling successful jobs history | `3` |
351+
| `cronjobs.jobs.outlookWebhookPoll.failedJobsHistoryLimit` | Outlook webhook polling failed jobs history | `1` |
352+
317353
### Shared Storage Parameters
318354

319355
| Parameter | Description | Default |
@@ -509,6 +545,46 @@ This creates network policies that:
509545
- Permit DNS resolution and HTTPS egress
510546
- Support custom ingress/egress rules
511547
548+
### CronJobs for Scheduled Tasks
549+
550+
Enable automated scheduled tasks functionality:
551+
552+
```yaml
553+
cronjobs:
554+
enabled: true
555+
556+
# Customize individual jobs
557+
jobs:
558+
scheduleExecution:
559+
enabled: true
560+
schedule: "*/1 * * * *" # Every minute
561+
562+
gmailWebhookPoll:
563+
enabled: true
564+
schedule: "*/1 * * * *" # Every minute
565+
566+
outlookWebhookPoll:
567+
enabled: true
568+
schedule: "*/1 * * * *" # Every minute
569+
570+
571+
# Global job configuration
572+
resources:
573+
limits:
574+
memory: "256Mi"
575+
cpu: "200m"
576+
requests:
577+
memory: "128Mi"
578+
cpu: "100m"
579+
```
580+
581+
This creates Kubernetes CronJob resources that:
582+
- Execute HTTP requests to your application's API endpoints
583+
- Handle retries and error logging automatically
584+
- Use minimal resources with curl-based containers
585+
- Support individual enable/disable per job
586+
- Follow Kubernetes security best practices
587+
512588
### High Availability
513589
514590
Configure pod disruption budgets and anti-affinity:

helm/sim/templates/cronjobs.yaml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
{{- if .Values.cronjobs.enabled }}
2+
{{- range $jobKey, $jobConfig := .Values.cronjobs.jobs }}
3+
{{- if $jobConfig.enabled }}
4+
---
5+
apiVersion: batch/v1
6+
kind: CronJob
7+
metadata:
8+
name: {{ include "sim.fullname" $ }}-{{ $jobConfig.name }}
9+
labels:
10+
{{- include "sim.labels" $ | nindent 4 }}
11+
app.kubernetes.io/component: cronjob-{{ $jobConfig.name }}
12+
spec:
13+
schedule: {{ $jobConfig.schedule | quote }}
14+
concurrencyPolicy: {{ $jobConfig.concurrencyPolicy | default "Forbid" }}
15+
successfulJobsHistoryLimit: {{ $jobConfig.successfulJobsHistoryLimit | default 3 }}
16+
failedJobsHistoryLimit: {{ $jobConfig.failedJobsHistoryLimit | default 1 }}
17+
{{- with $.Values.cronjobs.startingDeadlineSeconds }}
18+
startingDeadlineSeconds: {{ . }}
19+
{{- end }}
20+
jobTemplate:
21+
spec:
22+
{{- with $.Values.cronjobs.activeDeadlineSeconds }}
23+
activeDeadlineSeconds: {{ . }}
24+
{{- end }}
25+
template:
26+
metadata:
27+
labels:
28+
{{- include "sim.selectorLabels" $ | nindent 12 }}
29+
app.kubernetes.io/component: cronjob-{{ $jobConfig.name }}
30+
spec:
31+
restartPolicy: {{ $.Values.cronjobs.restartPolicy | default "OnFailure" }}
32+
{{- with $.Values.cronjobs.podSecurityContext }}
33+
securityContext:
34+
{{- toYaml . | nindent 12 }}
35+
{{- end }}
36+
containers:
37+
- name: {{ $jobConfig.name }}
38+
image: "{{ $.Values.cronjobs.image.repository }}:{{ $.Values.cronjobs.image.tag }}"
39+
imagePullPolicy: {{ $.Values.cronjobs.image.pullPolicy }}
40+
{{- with $.Values.cronjobs.securityContext }}
41+
securityContext:
42+
{{- toYaml . | nindent 14 }}
43+
{{- end }}
44+
command:
45+
- /bin/sh
46+
- -c
47+
args:
48+
- |
49+
echo "Starting cron job: {{ $jobConfig.name }}"
50+
echo "Making HTTP request to {{ $jobConfig.path }}"
51+
52+
# Determine the service URL (use internal service regardless of ingress)
53+
SERVICE_URL="http://{{ include "sim.fullname" $ }}-app:{{ $.Values.app.service.port }}"
54+
55+
# Make the HTTP request with timeout and retry logic
56+
for i in $(seq 1 3); do
57+
echo "Attempt $i/3"
58+
if curl -f -s -S --max-time 60 --retry 2 --retry-delay 5 \
59+
-H "Content-Type: application/json" \
60+
-H "User-Agent: Kubernetes-CronJob/{{ $jobConfig.name }}" \
61+
"$SERVICE_URL{{ $jobConfig.path }}"; then
62+
echo "Success: HTTP request completed"
63+
exit 0
64+
fi
65+
echo "Attempt $i failed, retrying..."
66+
sleep 10
67+
done
68+
echo "Error: All attempts failed"
69+
exit 1
70+
resources:
71+
{{- toYaml $.Values.cronjobs.resources | nindent 14 }}
72+
{{- with $.Values.global.imagePullSecrets }}
73+
imagePullSecrets:
74+
{{- toYaml . | nindent 12 }}
75+
{{- end }}
76+
{{- with $.Values.app.nodeSelector }}
77+
nodeSelector:
78+
{{- toYaml . | nindent 12 }}
79+
{{- end }}
80+
{{- with $.Values.affinity }}
81+
affinity:
82+
{{- toYaml . | nindent 12 }}
83+
{{- end }}
84+
{{- with $.Values.tolerations }}
85+
tolerations:
86+
{{- toYaml . | nindent 12 }}
87+
{{- end }}
88+
{{- end }}
89+
{{- end }}
90+
{{- end }}

helm/sim/values.yaml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,68 @@ affinity: {}
582582
# Tolerations for scheduling on tainted nodes
583583
tolerations: []
584584

585+
# CronJob configuration for scheduled tasks
586+
cronjobs:
587+
# Enable/disable all cron jobs
588+
enabled: true
589+
590+
# Individual job configurations
591+
jobs:
592+
scheduleExecution:
593+
enabled: true
594+
name: schedule-execution
595+
schedule: "*/1 * * * *"
596+
path: "/api/schedules/execute"
597+
concurrencyPolicy: Forbid
598+
successfulJobsHistoryLimit: 3
599+
failedJobsHistoryLimit: 1
600+
601+
gmailWebhookPoll:
602+
enabled: true
603+
name: gmail-webhook-poll
604+
schedule: "*/1 * * * *"
605+
path: "/api/webhooks/poll/gmail"
606+
concurrencyPolicy: Forbid
607+
successfulJobsHistoryLimit: 3
608+
failedJobsHistoryLimit: 1
609+
610+
outlookWebhookPoll:
611+
enabled: true
612+
name: outlook-webhook-poll
613+
schedule: "*/1 * * * *"
614+
path: "/api/webhooks/poll/outlook"
615+
concurrencyPolicy: Forbid
616+
successfulJobsHistoryLimit: 3
617+
failedJobsHistoryLimit: 1
618+
619+
620+
# Global CronJob settings
621+
image:
622+
repository: curlimages/curl
623+
tag: 8.5.0
624+
pullPolicy: IfNotPresent
625+
626+
resources:
627+
limits:
628+
memory: "128Mi"
629+
cpu: "100m"
630+
requests:
631+
memory: "64Mi"
632+
cpu: "50m"
633+
634+
restartPolicy: OnFailure
635+
activeDeadlineSeconds: 300
636+
startingDeadlineSeconds: 60
637+
638+
# Pod security context
639+
podSecurityContext:
640+
fsGroup: 1001
641+
642+
# Container security context
643+
securityContext:
644+
runAsNonRoot: true
645+
runAsUser: 1001
646+
585647
# Observability and telemetry configuration
586648
telemetry:
587649
# Enable/disable telemetry collection

0 commit comments

Comments
 (0)