Skip to content

Commit 6bfdcb9

Browse files
committed
chore: add validation for cron schedule
Signed-off-by: Artem Bortnikov <brongineer747@gmail.com>
1 parent b9e7989 commit 6bfdcb9

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

api/v1alpha1/etcdbackupschedule_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ type EtcdBackupScheduleSpec struct {
3535
// Destination defines where the backup will be stored.
3636
Destination BackupDestination `json:"destination"`
3737
// SuccessfulJobsHistoryLimit is the number of successful finished CronJob children to retain.
38+
// +kubebuilder:validation:Minimum=0
3839
// +optional
3940
SuccessfulJobsHistoryLimit *int32 `json:"successfulJobsHistoryLimit,omitempty"`
4041
// FailedJobsHistoryLimit is the number of failed finished CronJob children to retain.
42+
// +kubebuilder:validation:Minimum=0
4143
// +optional
4244
FailedJobsHistoryLimit *int32 `json:"failedJobsHistoryLimit,omitempty"`
4345
// ActiveBackupJobDeadline is the duration in seconds that each scheduled

api/v1alpha1/etcdbackupschedule_webhook.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package v1alpha1
1818

1919
import (
2020
"fmt"
21+
"strings"
2122

2223
"github.com/robfig/cron/v3"
2324
"k8s.io/apimachinery/pkg/api/errors"
@@ -119,6 +120,12 @@ func (r *EtcdBackupSchedule) validateSpec() field.ErrorList {
119120
field.NewPath("spec", "schedule"),
120121
"schedule is required",
121122
))
123+
} else if strings.HasPrefix(r.Spec.Schedule, "@every ") {
124+
allErrors = append(allErrors, field.Invalid(
125+
field.NewPath("spec", "schedule"),
126+
r.Spec.Schedule,
127+
"@every expressions are not supported by Kubernetes CronJobs",
128+
))
122129
} else if _, err := cronParser.Parse(r.Spec.Schedule); err != nil {
123130
allErrors = append(allErrors, field.Invalid(
124131
field.NewPath("spec", "schedule"),

config/crd/bases/etcd.aenix.io_etcdbackupschedules.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ spec:
145145
description: FailedJobsHistoryLimit is the number of failed finished
146146
CronJob children to retain.
147147
format: int32
148+
minimum: 0
148149
type: integer
149150
finishedBackupJobsTTL:
150151
default: 600
@@ -162,6 +163,7 @@ spec:
162163
description: SuccessfulJobsHistoryLimit is the number of successful
163164
finished CronJob children to retain.
164165
format: int32
166+
minimum: 0
165167
type: integer
166168
required:
167169
- clusterRef

0 commit comments

Comments
 (0)