fix the validation logic for Job/CronJob RestartPolicy field

This commit is contained in:
SataQiu
2020-11-11 14:16:36 +08:00
parent 0923b9abce
commit 961d062e9a
2 changed files with 55 additions and 4 deletions

View File

@@ -195,7 +195,7 @@ func TestValidateJob(t *testing.T) {
},
},
},
"spec.template.spec.restartPolicy: Unsupported value": {
"spec.template.spec.restartPolicy: Required value": {
ObjectMeta: metav1.ObjectMeta{
Name: "myjob",
Namespace: metav1.NamespaceDefault,
@@ -216,6 +216,27 @@ func TestValidateJob(t *testing.T) {
},
},
},
"spec.template.spec.restartPolicy: Unsupported value": {
ObjectMeta: metav1.ObjectMeta{
Name: "myjob",
Namespace: metav1.NamespaceDefault,
UID: types.UID("1a2b3c"),
},
Spec: batch.JobSpec{
Selector: validManualSelector,
ManualSelector: newBool(true),
Template: api.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: validManualSelector.MatchLabels,
},
Spec: api.PodSpec{
RestartPolicy: "Invalid",
DNSPolicy: api.DNSClusterFirst,
Containers: []api.Container{{Name: "abc", Image: "image", ImagePullPolicy: "IfNotPresent", TerminationMessagePolicy: api.TerminationMessageReadFile}},
},
},
},
},
}
for _, setFeature := range []bool{true, false} {
@@ -586,7 +607,7 @@ func TestValidateCronJob(t *testing.T) {
},
},
},
"spec.jobTemplate.spec.template.spec.restartPolicy: Unsupported value": {
"spec.jobTemplate.spec.template.spec.restartPolicy: Required value": {
ObjectMeta: metav1.ObjectMeta{
Name: "mycronjob",
Namespace: metav1.NamespaceDefault,
@@ -608,6 +629,28 @@ func TestValidateCronJob(t *testing.T) {
},
},
},
"spec.jobTemplate.spec.template.spec.restartPolicy: Unsupported value": {
ObjectMeta: metav1.ObjectMeta{
Name: "mycronjob",
Namespace: metav1.NamespaceDefault,
UID: types.UID("1a2b3c"),
},
Spec: batch.CronJobSpec{
Schedule: "* * * * ?",
ConcurrencyPolicy: batch.AllowConcurrent,
JobTemplate: batch.JobTemplateSpec{
Spec: batch.JobSpec{
Template: api.PodTemplateSpec{
Spec: api.PodSpec{
RestartPolicy: "Invalid",
DNSPolicy: api.DNSClusterFirst,
Containers: []api.Container{{Name: "abc", Image: "image", ImagePullPolicy: "IfNotPresent", TerminationMessagePolicy: api.TerminationMessageReadFile}},
},
},
},
},
},
},
}
if utilfeature.DefaultFeatureGate.Enabled(features.TTLAfterFinished) {
errorCases["spec.jobTemplate.spec.ttlSecondsAfterFinished:must be greater than or equal to 0"] = batch.CronJob{