Update defaults (successful|failed)JobsHistoryLimit in batch/v1beta1

This commit is contained in:
Maciej Szulik 2017-09-15 12:36:02 +02:00
parent 93ddb7be5f
commit 7e96fc66e1
No known key found for this signature in database
GPG Key ID: F15E55D276FA84C4
4 changed files with 38 additions and 14 deletions

View File

@ -53,14 +53,10 @@ var Funcs = func(codecs runtimeserializer.CodecFactory) []interface{} {
sds := int64(c.RandUint64())
sj.StartingDeadlineSeconds = &sds
sj.Schedule = c.RandString()
if hasSuccessLimit := c.RandBool(); hasSuccessLimit {
successfulJobsHistoryLimit := int32(c.Rand.Int31())
sj.SuccessfulJobsHistoryLimit = &successfulJobsHistoryLimit
}
if hasFailedLimit := c.RandBool(); hasFailedLimit {
failedJobsHistoryLimit := int32(c.Rand.Int31())
sj.FailedJobsHistoryLimit = &failedJobsHistoryLimit
}
successfulJobsHistoryLimit := int32(c.Rand.Int31())
sj.SuccessfulJobsHistoryLimit = &successfulJobsHistoryLimit
failedJobsHistoryLimit := int32(c.Rand.Int31())
sj.FailedJobsHistoryLimit = &failedJobsHistoryLimit
},
func(cp *batch.ConcurrencyPolicy, c fuzz.Continue) {
policies := []batch.ConcurrencyPolicy{batch.AllowConcurrent, batch.ForbidConcurrent, batch.ReplaceConcurrent}

View File

@ -32,4 +32,12 @@ func SetDefaults_CronJob(obj *batchv1beta1.CronJob) {
if obj.Spec.Suspend == nil {
obj.Spec.Suspend = new(bool)
}
if obj.Spec.SuccessfulJobsHistoryLimit == nil {
obj.Spec.SuccessfulJobsHistoryLimit = new(int32)
*obj.Spec.SuccessfulJobsHistoryLimit = 3
}
if obj.Spec.FailedJobsHistoryLimit == nil {
obj.Spec.FailedJobsHistoryLimit = new(int32)
*obj.Spec.FailedJobsHistoryLimit = 1
}
}

View File

@ -38,22 +38,28 @@ func TestSetDefaultCronJob(t *testing.T) {
original: &batchv1beta1.CronJob{},
expected: &batchv1beta1.CronJob{
Spec: batchv1beta1.CronJobSpec{
ConcurrencyPolicy: batchv1beta1.AllowConcurrent,
Suspend: newBool(false),
ConcurrencyPolicy: batchv1beta1.AllowConcurrent,
Suspend: newBool(false),
SuccessfulJobsHistoryLimit: newInt32(3),
FailedJobsHistoryLimit: newInt32(1),
},
},
},
"set fields should not be defaulted": {
original: &batchv1beta1.CronJob{
Spec: batchv1beta1.CronJobSpec{
ConcurrencyPolicy: batchv1beta1.ForbidConcurrent,
Suspend: newBool(true),
ConcurrencyPolicy: batchv1beta1.ForbidConcurrent,
Suspend: newBool(true),
SuccessfulJobsHistoryLimit: newInt32(5),
FailedJobsHistoryLimit: newInt32(5),
},
},
expected: &batchv1beta1.CronJob{
Spec: batchv1beta1.CronJobSpec{
ConcurrencyPolicy: batchv1beta1.ForbidConcurrent,
Suspend: newBool(true),
ConcurrencyPolicy: batchv1beta1.ForbidConcurrent,
Suspend: newBool(true),
SuccessfulJobsHistoryLimit: newInt32(5),
FailedJobsHistoryLimit: newInt32(5),
},
},
},
@ -74,6 +80,12 @@ func TestSetDefaultCronJob(t *testing.T) {
if *actual.Spec.Suspend != *expected.Spec.Suspend {
t.Errorf("%s: got different suspend than expected: %v %v", name, *actual.Spec.Suspend, *expected.Spec.Suspend)
}
if *actual.Spec.SuccessfulJobsHistoryLimit != *expected.Spec.SuccessfulJobsHistoryLimit {
t.Errorf("%s: got different successfulJobsHistoryLimit than expected: %v %v", name, *actual.Spec.SuccessfulJobsHistoryLimit, *expected.Spec.SuccessfulJobsHistoryLimit)
}
if *actual.Spec.FailedJobsHistoryLimit != *expected.Spec.FailedJobsHistoryLimit {
t.Errorf("%s: got different failedJobsHistoryLimit than expected: %v %v", name, *actual.Spec.FailedJobsHistoryLimit, *expected.Spec.FailedJobsHistoryLimit)
}
}
}
@ -102,3 +114,9 @@ func newBool(val bool) *bool {
*p = val
return p
}
func newInt32(val int32) *int32 {
p := new(int32)
*p = val
return p
}

View File

@ -114,11 +114,13 @@ type CronJobSpec struct {
// The number of successful finished jobs to retain.
// This is a pointer to distinguish between explicit zero and not specified.
// Defaults to 3.
// +optional
SuccessfulJobsHistoryLimit *int32 `json:"successfulJobsHistoryLimit,omitempty" protobuf:"varint,6,opt,name=successfulJobsHistoryLimit"`
// The number of failed finished jobs to retain.
// This is a pointer to distinguish between explicit zero and not specified.
// Defaults to 1.
// +optional
FailedJobsHistoryLimit *int32 `json:"failedJobsHistoryLimit,omitempty" protobuf:"varint,7,opt,name=failedJobsHistoryLimit"`
}