mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-11-01 22:34:14 +00:00
batch: add suspended job
Signed-off-by: Adhityaa Chandrasekar <adtac@google.com>
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
batchv1 "k8s.io/api/batch/v1"
|
||||
"k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@@ -27,7 +28,7 @@ import (
|
||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||
_ "k8s.io/kubernetes/pkg/apis/batch/install"
|
||||
_ "k8s.io/kubernetes/pkg/apis/core/install"
|
||||
utilpointer "k8s.io/utils/pointer"
|
||||
"k8s.io/utils/pointer"
|
||||
|
||||
. "k8s.io/kubernetes/pkg/apis/batch/v1"
|
||||
)
|
||||
@@ -49,15 +50,36 @@ func TestSetDefaultJob(t *testing.T) {
|
||||
},
|
||||
expected: &batchv1.Job{
|
||||
Spec: batchv1.JobSpec{
|
||||
Completions: utilpointer.Int32Ptr(1),
|
||||
Parallelism: utilpointer.Int32Ptr(1),
|
||||
BackoffLimit: utilpointer.Int32Ptr(6),
|
||||
Completions: pointer.Int32Ptr(1),
|
||||
Parallelism: pointer.Int32Ptr(1),
|
||||
BackoffLimit: pointer.Int32Ptr(6),
|
||||
CompletionMode: batchv1.NonIndexedCompletion,
|
||||
Suspend: pointer.BoolPtr(false),
|
||||
},
|
||||
},
|
||||
expectLabels: true,
|
||||
},
|
||||
"All unspecified -> all integers are defaulted and no default labels": {
|
||||
"suspend set, everything else is defaulted": {
|
||||
original: &batchv1.Job{
|
||||
Spec: batchv1.JobSpec{
|
||||
Suspend: pointer.BoolPtr(true),
|
||||
Template: v1.PodTemplateSpec{
|
||||
ObjectMeta: metav1.ObjectMeta{Labels: defaultLabels},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: &batchv1.Job{
|
||||
Spec: batchv1.JobSpec{
|
||||
Completions: pointer.Int32Ptr(1),
|
||||
Parallelism: pointer.Int32Ptr(1),
|
||||
BackoffLimit: pointer.Int32Ptr(6),
|
||||
CompletionMode: batchv1.NonIndexedCompletion,
|
||||
Suspend: pointer.BoolPtr(true),
|
||||
},
|
||||
},
|
||||
expectLabels: true,
|
||||
},
|
||||
"All unspecified -> all pointers, CompletionMode are defaulted and no default labels": {
|
||||
original: &batchv1.Job{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Labels: map[string]string{"mylabel": "myvalue"},
|
||||
@@ -70,17 +92,18 @@ func TestSetDefaultJob(t *testing.T) {
|
||||
},
|
||||
expected: &batchv1.Job{
|
||||
Spec: batchv1.JobSpec{
|
||||
Completions: utilpointer.Int32Ptr(1),
|
||||
Parallelism: utilpointer.Int32Ptr(1),
|
||||
BackoffLimit: utilpointer.Int32Ptr(6),
|
||||
Completions: pointer.Int32Ptr(1),
|
||||
Parallelism: pointer.Int32Ptr(1),
|
||||
BackoffLimit: pointer.Int32Ptr(6),
|
||||
CompletionMode: batchv1.NonIndexedCompletion,
|
||||
Suspend: pointer.BoolPtr(false),
|
||||
},
|
||||
},
|
||||
},
|
||||
"WQ: Parallelism explicitly 0 and completions unset -> BackoffLimit is defaulted": {
|
||||
original: &batchv1.Job{
|
||||
Spec: batchv1.JobSpec{
|
||||
Parallelism: utilpointer.Int32Ptr(0),
|
||||
Parallelism: pointer.Int32Ptr(0),
|
||||
Template: v1.PodTemplateSpec{
|
||||
ObjectMeta: metav1.ObjectMeta{Labels: defaultLabels},
|
||||
},
|
||||
@@ -88,9 +111,10 @@ func TestSetDefaultJob(t *testing.T) {
|
||||
},
|
||||
expected: &batchv1.Job{
|
||||
Spec: batchv1.JobSpec{
|
||||
Parallelism: utilpointer.Int32Ptr(0),
|
||||
BackoffLimit: utilpointer.Int32Ptr(6),
|
||||
Parallelism: pointer.Int32Ptr(0),
|
||||
BackoffLimit: pointer.Int32Ptr(6),
|
||||
CompletionMode: batchv1.NonIndexedCompletion,
|
||||
Suspend: pointer.BoolPtr(false),
|
||||
},
|
||||
},
|
||||
expectLabels: true,
|
||||
@@ -98,7 +122,7 @@ func TestSetDefaultJob(t *testing.T) {
|
||||
"WQ: Parallelism explicitly 2 and completions unset -> BackoffLimit is defaulted": {
|
||||
original: &batchv1.Job{
|
||||
Spec: batchv1.JobSpec{
|
||||
Parallelism: utilpointer.Int32Ptr(2),
|
||||
Parallelism: pointer.Int32Ptr(2),
|
||||
Template: v1.PodTemplateSpec{
|
||||
ObjectMeta: metav1.ObjectMeta{Labels: defaultLabels},
|
||||
},
|
||||
@@ -106,9 +130,10 @@ func TestSetDefaultJob(t *testing.T) {
|
||||
},
|
||||
expected: &batchv1.Job{
|
||||
Spec: batchv1.JobSpec{
|
||||
Parallelism: utilpointer.Int32Ptr(2),
|
||||
BackoffLimit: utilpointer.Int32Ptr(6),
|
||||
Parallelism: pointer.Int32Ptr(2),
|
||||
BackoffLimit: pointer.Int32Ptr(6),
|
||||
CompletionMode: batchv1.NonIndexedCompletion,
|
||||
Suspend: pointer.BoolPtr(false),
|
||||
},
|
||||
},
|
||||
expectLabels: true,
|
||||
@@ -116,7 +141,7 @@ func TestSetDefaultJob(t *testing.T) {
|
||||
"Completions explicitly 2 and others unset -> parallelism and BackoffLimit are defaulted": {
|
||||
original: &batchv1.Job{
|
||||
Spec: batchv1.JobSpec{
|
||||
Completions: utilpointer.Int32Ptr(2),
|
||||
Completions: pointer.Int32Ptr(2),
|
||||
Template: v1.PodTemplateSpec{
|
||||
ObjectMeta: metav1.ObjectMeta{Labels: defaultLabels},
|
||||
},
|
||||
@@ -124,10 +149,11 @@ func TestSetDefaultJob(t *testing.T) {
|
||||
},
|
||||
expected: &batchv1.Job{
|
||||
Spec: batchv1.JobSpec{
|
||||
Completions: utilpointer.Int32Ptr(2),
|
||||
Parallelism: utilpointer.Int32Ptr(1),
|
||||
BackoffLimit: utilpointer.Int32Ptr(6),
|
||||
Completions: pointer.Int32Ptr(2),
|
||||
Parallelism: pointer.Int32Ptr(1),
|
||||
BackoffLimit: pointer.Int32Ptr(6),
|
||||
CompletionMode: batchv1.NonIndexedCompletion,
|
||||
Suspend: pointer.BoolPtr(false),
|
||||
},
|
||||
},
|
||||
expectLabels: true,
|
||||
@@ -135,7 +161,7 @@ func TestSetDefaultJob(t *testing.T) {
|
||||
"BackoffLimit explicitly 5 and others unset -> parallelism and completions are defaulted": {
|
||||
original: &batchv1.Job{
|
||||
Spec: batchv1.JobSpec{
|
||||
BackoffLimit: utilpointer.Int32Ptr(5),
|
||||
BackoffLimit: pointer.Int32Ptr(5),
|
||||
Template: v1.PodTemplateSpec{
|
||||
ObjectMeta: metav1.ObjectMeta{Labels: defaultLabels},
|
||||
},
|
||||
@@ -143,10 +169,11 @@ func TestSetDefaultJob(t *testing.T) {
|
||||
},
|
||||
expected: &batchv1.Job{
|
||||
Spec: batchv1.JobSpec{
|
||||
Completions: utilpointer.Int32Ptr(1),
|
||||
Parallelism: utilpointer.Int32Ptr(1),
|
||||
BackoffLimit: utilpointer.Int32Ptr(5),
|
||||
Completions: pointer.Int32Ptr(1),
|
||||
Parallelism: pointer.Int32Ptr(1),
|
||||
BackoffLimit: pointer.Int32Ptr(5),
|
||||
CompletionMode: batchv1.NonIndexedCompletion,
|
||||
Suspend: pointer.BoolPtr(false),
|
||||
},
|
||||
},
|
||||
expectLabels: true,
|
||||
@@ -154,10 +181,11 @@ func TestSetDefaultJob(t *testing.T) {
|
||||
"All set -> no change": {
|
||||
original: &batchv1.Job{
|
||||
Spec: batchv1.JobSpec{
|
||||
Completions: utilpointer.Int32Ptr(8),
|
||||
Parallelism: utilpointer.Int32Ptr(9),
|
||||
BackoffLimit: utilpointer.Int32Ptr(10),
|
||||
Completions: pointer.Int32Ptr(8),
|
||||
Parallelism: pointer.Int32Ptr(9),
|
||||
BackoffLimit: pointer.Int32Ptr(10),
|
||||
CompletionMode: batchv1.NonIndexedCompletion,
|
||||
Suspend: pointer.BoolPtr(true),
|
||||
Template: v1.PodTemplateSpec{
|
||||
ObjectMeta: metav1.ObjectMeta{Labels: defaultLabels},
|
||||
},
|
||||
@@ -165,10 +193,11 @@ func TestSetDefaultJob(t *testing.T) {
|
||||
},
|
||||
expected: &batchv1.Job{
|
||||
Spec: batchv1.JobSpec{
|
||||
Completions: utilpointer.Int32Ptr(8),
|
||||
Parallelism: utilpointer.Int32Ptr(9),
|
||||
BackoffLimit: utilpointer.Int32Ptr(10),
|
||||
Completions: pointer.Int32Ptr(8),
|
||||
Parallelism: pointer.Int32Ptr(9),
|
||||
BackoffLimit: pointer.Int32Ptr(10),
|
||||
CompletionMode: batchv1.NonIndexedCompletion,
|
||||
Suspend: pointer.BoolPtr(true),
|
||||
Template: v1.PodTemplateSpec{
|
||||
ObjectMeta: metav1.ObjectMeta{Labels: defaultLabels},
|
||||
},
|
||||
@@ -179,10 +208,11 @@ func TestSetDefaultJob(t *testing.T) {
|
||||
"All set, flipped -> no change": {
|
||||
original: &batchv1.Job{
|
||||
Spec: batchv1.JobSpec{
|
||||
Completions: utilpointer.Int32Ptr(11),
|
||||
Parallelism: utilpointer.Int32Ptr(10),
|
||||
BackoffLimit: utilpointer.Int32Ptr(9),
|
||||
Completions: pointer.Int32Ptr(11),
|
||||
Parallelism: pointer.Int32Ptr(10),
|
||||
BackoffLimit: pointer.Int32Ptr(9),
|
||||
CompletionMode: batchv1.IndexedCompletion,
|
||||
Suspend: pointer.BoolPtr(true),
|
||||
Template: v1.PodTemplateSpec{
|
||||
ObjectMeta: metav1.ObjectMeta{Labels: defaultLabels},
|
||||
},
|
||||
@@ -190,10 +220,11 @@ func TestSetDefaultJob(t *testing.T) {
|
||||
},
|
||||
expected: &batchv1.Job{
|
||||
Spec: batchv1.JobSpec{
|
||||
Completions: utilpointer.Int32Ptr(11),
|
||||
Parallelism: utilpointer.Int32Ptr(10),
|
||||
BackoffLimit: utilpointer.Int32Ptr(9),
|
||||
Completions: pointer.Int32Ptr(11),
|
||||
Parallelism: pointer.Int32Ptr(10),
|
||||
BackoffLimit: pointer.Int32Ptr(9),
|
||||
CompletionMode: batchv1.IndexedCompletion,
|
||||
Suspend: pointer.BoolPtr(true),
|
||||
},
|
||||
},
|
||||
expectLabels: true,
|
||||
@@ -211,6 +242,9 @@ func TestSetDefaultJob(t *testing.T) {
|
||||
t.Fatalf("Unexpected object: %v", actual)
|
||||
}
|
||||
|
||||
if diff := cmp.Diff(expected.Spec.Suspend, actual.Spec.Suspend); diff != "" {
|
||||
t.Errorf(".spec.suspend does not match; -want,+got:\n%s", diff)
|
||||
}
|
||||
validateDefaultInt32(t, "Completions", actual.Spec.Completions, expected.Spec.Completions)
|
||||
validateDefaultInt32(t, "Parallelism", actual.Spec.Parallelism, expected.Spec.Parallelism)
|
||||
validateDefaultInt32(t, "BackoffLimit", actual.Spec.BackoffLimit, expected.Spec.BackoffLimit)
|
||||
@@ -271,8 +305,8 @@ func TestSetDefaultCronJob(t *testing.T) {
|
||||
Spec: batchv1.CronJobSpec{
|
||||
ConcurrencyPolicy: batchv1.AllowConcurrent,
|
||||
Suspend: newBool(false),
|
||||
SuccessfulJobsHistoryLimit: utilpointer.Int32Ptr(3),
|
||||
FailedJobsHistoryLimit: utilpointer.Int32Ptr(1),
|
||||
SuccessfulJobsHistoryLimit: pointer.Int32Ptr(3),
|
||||
FailedJobsHistoryLimit: pointer.Int32Ptr(1),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -281,16 +315,16 @@ func TestSetDefaultCronJob(t *testing.T) {
|
||||
Spec: batchv1.CronJobSpec{
|
||||
ConcurrencyPolicy: batchv1.ForbidConcurrent,
|
||||
Suspend: newBool(true),
|
||||
SuccessfulJobsHistoryLimit: utilpointer.Int32Ptr(5),
|
||||
FailedJobsHistoryLimit: utilpointer.Int32Ptr(5),
|
||||
SuccessfulJobsHistoryLimit: pointer.Int32Ptr(5),
|
||||
FailedJobsHistoryLimit: pointer.Int32Ptr(5),
|
||||
},
|
||||
},
|
||||
expected: &batchv1.CronJob{
|
||||
Spec: batchv1.CronJobSpec{
|
||||
ConcurrencyPolicy: batchv1.ForbidConcurrent,
|
||||
Suspend: newBool(true),
|
||||
SuccessfulJobsHistoryLimit: utilpointer.Int32Ptr(5),
|
||||
FailedJobsHistoryLimit: utilpointer.Int32Ptr(5),
|
||||
SuccessfulJobsHistoryLimit: pointer.Int32Ptr(5),
|
||||
FailedJobsHistoryLimit: pointer.Int32Ptr(5),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user