mirror of
https://github.com/kubernetes/kubernetes.git
synced 2026-06-30 20:36:30 +00:00
batch: add declarative validation tests for toleration key
Job and CronJob; prefixed and unprefixed keys.
This commit is contained in:
@@ -66,6 +66,18 @@ func testDeclarativeValidate(t *testing.T, apiVersion string) {
|
||||
tweakJobTemplateBackoffLimitPerIndex(ptr.To[int32](1)),
|
||||
),
|
||||
},
|
||||
"tolerations: valid key": {
|
||||
input: mkCronJob(tweakTolerations(api.Toleration{Key: "example.com/valid-key", Operator: api.TolerationOpExists})),
|
||||
},
|
||||
"tolerations: valid key without prefix": {
|
||||
input: mkCronJob(tweakTolerations(api.Toleration{Key: "simple-key", Operator: api.TolerationOpExists})),
|
||||
},
|
||||
"tolerations: invalid key format": {
|
||||
input: mkCronJob(tweakTolerations(api.Toleration{Key: "invalid key", Operator: api.TolerationOpExists})),
|
||||
expectedErrs: field.ErrorList{
|
||||
field.Invalid(field.NewPath("spec", "jobTemplate", "spec", "template", "spec", "tolerations").Index(0).Child("key"), nil, "").WithOrigin("format=k8s-label-key").MarkAlpha(),
|
||||
},
|
||||
},
|
||||
}
|
||||
for k, tc := range testCases {
|
||||
t.Run(k, func(t *testing.T) {
|
||||
@@ -146,6 +158,12 @@ func tweakJobTemplateBackoffLimitPerIndex(v *int32) func(*batch.CronJob) {
|
||||
}
|
||||
}
|
||||
|
||||
func tweakTolerations(tolerations ...api.Toleration) func(*batch.CronJob) {
|
||||
return func(job *batch.CronJob) {
|
||||
job.Spec.JobTemplate.Spec.Template.Spec.Tolerations = tolerations
|
||||
}
|
||||
}
|
||||
|
||||
var validCronjobSpec = batch.CronJobSpec{
|
||||
Schedule: "5 5 * * ?",
|
||||
ConcurrencyPolicy: batch.AllowConcurrent,
|
||||
|
||||
@@ -46,6 +46,9 @@ func testDeclarativeValidate(t *testing.T, apiVersion string) {
|
||||
input batch.Job
|
||||
expectedErrs field.ErrorList
|
||||
}{
|
||||
"valid": {
|
||||
input: mkJob(),
|
||||
},
|
||||
"maxFailedIndexes and backoffLimitPerIndex both set": {
|
||||
input: mkJob(
|
||||
tweakMaxFailedIndexes(ptr.To[int32](5)),
|
||||
@@ -58,6 +61,18 @@ func testDeclarativeValidate(t *testing.T, apiVersion string) {
|
||||
field.Required(field.NewPath("spec", "backoffLimitPerIndex"), "").WithOrigin("dependentRequired").MarkAlpha(),
|
||||
},
|
||||
},
|
||||
"valid toleration key": {
|
||||
input: mkJob(tweakTolerations(api.Toleration{Key: "example.com/valid-key", Operator: api.TolerationOpExists})),
|
||||
},
|
||||
"valid toleration key without prefix": {
|
||||
input: mkJob(tweakTolerations(api.Toleration{Key: "simple-key", Operator: api.TolerationOpExists})),
|
||||
},
|
||||
"invalid toleration key format": {
|
||||
input: mkJob(tweakTolerations(api.Toleration{Key: "invalid key", Operator: api.TolerationOpExists})),
|
||||
expectedErrs: field.ErrorList{
|
||||
field.Invalid(field.NewPath("spec", "template", "spec", "tolerations").Index(0).Child("key"), nil, "").WithOrigin("format=k8s-label-key").MarkAlpha(),
|
||||
},
|
||||
},
|
||||
}
|
||||
for k, tc := range testCases {
|
||||
t.Run(k, func(t *testing.T) {
|
||||
@@ -93,6 +108,12 @@ func tweakBackoffLimitPerIndex(v *int32) func(*batch.Job) {
|
||||
}
|
||||
}
|
||||
|
||||
func tweakTolerations(tolerations ...api.Toleration) func(*batch.Job) {
|
||||
return func(job *batch.Job) {
|
||||
job.Spec.Template.Spec.Tolerations = tolerations
|
||||
}
|
||||
}
|
||||
|
||||
var validJobLabels = map[string]string{
|
||||
batch.ControllerUidLabel: "1a2b3c",
|
||||
batch.LegacyControllerUidLabel: "1a2b3c",
|
||||
|
||||
Reference in New Issue
Block a user