Skip to content

Commit

Permalink
Merge pull request #534 from kartverket/skipjob-tz
Browse files Browse the repository at this point in the history
SKIPJob[cron]: add support for timezone
  • Loading branch information
evenh authored Sep 12, 2024
2 parents 1811ebe + b4daa8d commit a70a43e
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 0 deletions.
8 changes: 8 additions & 0 deletions api/v1alpha1/skipjob_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@ type CronSettings struct {
//+kubebuilder:validation:Required
Schedule string `json:"schedule"`

// The time zone name for the given schedule, see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones. If not specified,
// this will default to the time zone of the cluster.
//
// Example: "Europe/Oslo"
//
// +kubebuilder:validation:Optional
TimeZone *string `json:"timeZone,omitempty"`

// Denotes the deadline in seconds for starting a job on its schedule, if for some reason the Job's controller was not ready upon the scheduled time.
// If unset, Jobs missing their deadline will be considered failed jobs and will not start.
//
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions config/crd/skiperator.kartverket.no_skipjobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,13 @@ spec:
If set to true, this tells Kubernetes to suspend this Job till the field is set to false. If the Job is active while this field is set to true,
all running Pods will be terminated.
type: boolean
timeZone:
description: |-
The time zone name for the given schedule, see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones. If not specified,
this will default to the time zone of the cluster.
Example: "Europe/Oslo"
type: string
required:
- schedule
type: object
Expand Down
1 change: 1 addition & 0 deletions pkg/resourcegenerator/job/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func Generate(r reconciliation.Reconciliation) error {
func getCronJobSpec(skipJob *skiperatorv1alpha1.SKIPJob, selector *metav1.LabelSelector, podLabels map[string]string, gcpIdentityConfigMap *corev1.ConfigMap) batchv1.CronJobSpec {
spec := batchv1.CronJobSpec{
Schedule: skipJob.Spec.Cron.Schedule,
TimeZone: skipJob.Spec.Cron.TimeZone,
StartingDeadlineSeconds: skipJob.Spec.Cron.StartingDeadlineSeconds,
ConcurrencyPolicy: skipJob.Spec.Cron.ConcurrencyPolicy,
Suspend: skipJob.Spec.Cron.Suspend,
Expand Down
14 changes: 14 additions & 0 deletions tests/skipjob/cron-job-timezone/chainsaw-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
name: cron-job-timezone
spec:
skip: false
concurrent: true
skipDelete: false
steps:
- try:
- apply:
file: skipjob.yaml
- assert:
file: skipjob-assert.yaml
64 changes: 64 additions & 0 deletions tests/skipjob/cron-job-timezone/skipjob-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: cron-job-timezone-skipjob
labels:
skiperator.kartverket.no/skipjob: "true"
skiperator.kartverket.no/skipjobName: cron-job-timezone
app.kubernetes.io/managed-by: "skiperator"
skiperator.kartverket.no/controller: "skipjob"
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: cron-job-timezone
labels:
skiperator.kartverket.no/skipjob: "true"
skiperator.kartverket.no/skipjobName: cron-job-timezone
app.kubernetes.io/managed-by: "skiperator"
skiperator.kartverket.no/controller: "skipjob"
ownerReferences:
- apiVersion: skiperator.kartverket.no/v1alpha1
blockOwnerDeletion: true
controller: true
kind: SKIPJob
name: cron-job-timezone
spec:
schedule: "* * * * *"
timeZone: "Europe/Oslo"
concurrencyPolicy: Allow
suspend: false
successfulJobsHistoryLimit: 3
failedJobsHistoryLimit: 1
jobTemplate:
metadata:
labels:
app: cron-job-timezone-skipjob
skiperator.kartverket.no/skipjob: "true"
skiperator.kartverket.no/skipjobName: cron-job-timezone
app.kubernetes.io/managed-by: "skiperator"
skiperator.kartverket.no/controller: "skipjob"
spec:
template:
metadata:
labels:
app: cron-job-timezone-skipjob
spec:
containers:
- name: cron-job-timezone-skipjob
image: "perl:5.34.0"
---
apiVersion: v1
kind: Pod
metadata:
labels:
app: cron-job-timezone-skipjob
app.kubernetes.io/managed-by: skiperator
skiperator.kartverket.no/controller: skipjob
skiperator.kartverket.no/skipjob: 'true'
skiperator.kartverket.no/skipjobName: cron-job-timezone
ownerReferences:
- apiVersion: batch/v1
kind: Job
controller: true
blockOwnerDeletion: true
15 changes: 15 additions & 0 deletions tests/skipjob/cron-job-timezone/skipjob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: skiperator.kartverket.no/v1alpha1
kind: SKIPJob
metadata:
name: cron-job-timezone
spec:
container:
image: "perl:5.34.0"
command:
- "perl"
- "-Mbignum=bpi"
- "-wle"
- "print bpi(2000)"
cron:
schedule: "* * * * *"
timeZone: "Europe/Oslo"

0 comments on commit a70a43e

Please sign in to comment.