mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 23:47:50 +00:00
Remove extensions/v1beta1 Job
This commit is contained in:
@@ -286,278 +286,6 @@ func TestSetDefaultDeployment(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDefaultJob(t *testing.T) {
|
||||
defaultLabels := map[string]string{"default": "default"}
|
||||
tests := map[string]struct {
|
||||
original *Job
|
||||
expected *Job
|
||||
expectLabels bool
|
||||
}{
|
||||
"both unspecified -> sets both to 1": {
|
||||
original: &Job{
|
||||
Spec: JobSpec{
|
||||
Template: v1.PodTemplateSpec{
|
||||
ObjectMeta: v1.ObjectMeta{Labels: defaultLabels},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: &Job{
|
||||
Spec: JobSpec{
|
||||
Completions: newInt32(1),
|
||||
Parallelism: newInt32(1),
|
||||
},
|
||||
},
|
||||
expectLabels: true,
|
||||
},
|
||||
"both unspecified -> sets both to 1 and no default labels": {
|
||||
original: &Job{
|
||||
ObjectMeta: v1.ObjectMeta{
|
||||
Labels: map[string]string{"mylabel": "myvalue"},
|
||||
},
|
||||
Spec: JobSpec{
|
||||
Template: v1.PodTemplateSpec{
|
||||
ObjectMeta: v1.ObjectMeta{Labels: defaultLabels},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: &Job{
|
||||
Spec: JobSpec{
|
||||
Completions: newInt32(1),
|
||||
Parallelism: newInt32(1),
|
||||
},
|
||||
},
|
||||
},
|
||||
"WQ: Parallelism explicitly 0 and completions unset -> no change": {
|
||||
original: &Job{
|
||||
Spec: JobSpec{
|
||||
Parallelism: newInt32(0),
|
||||
Template: v1.PodTemplateSpec{
|
||||
ObjectMeta: v1.ObjectMeta{Labels: defaultLabels},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: &Job{
|
||||
Spec: JobSpec{
|
||||
Parallelism: newInt32(0),
|
||||
},
|
||||
},
|
||||
expectLabels: true,
|
||||
},
|
||||
"WQ: Parallelism explicitly 2 and completions unset -> no change": {
|
||||
original: &Job{
|
||||
Spec: JobSpec{
|
||||
Parallelism: newInt32(2),
|
||||
Template: v1.PodTemplateSpec{
|
||||
ObjectMeta: v1.ObjectMeta{Labels: defaultLabels},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: &Job{
|
||||
Spec: JobSpec{
|
||||
Parallelism: newInt32(2),
|
||||
},
|
||||
},
|
||||
expectLabels: true,
|
||||
},
|
||||
"Completions explicitly 2 and parallelism unset -> parallelism is defaulted": {
|
||||
original: &Job{
|
||||
Spec: JobSpec{
|
||||
Completions: newInt32(2),
|
||||
Template: v1.PodTemplateSpec{
|
||||
ObjectMeta: v1.ObjectMeta{Labels: defaultLabels},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: &Job{
|
||||
Spec: JobSpec{
|
||||
Completions: newInt32(2),
|
||||
Parallelism: newInt32(1),
|
||||
},
|
||||
},
|
||||
expectLabels: true,
|
||||
},
|
||||
"Both set -> no change": {
|
||||
original: &Job{
|
||||
Spec: JobSpec{
|
||||
Completions: newInt32(10),
|
||||
Parallelism: newInt32(11),
|
||||
Template: v1.PodTemplateSpec{
|
||||
ObjectMeta: v1.ObjectMeta{Labels: defaultLabels},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: &Job{
|
||||
Spec: JobSpec{
|
||||
Completions: newInt32(10),
|
||||
Parallelism: newInt32(11),
|
||||
Template: v1.PodTemplateSpec{
|
||||
ObjectMeta: v1.ObjectMeta{Labels: defaultLabels},
|
||||
},
|
||||
},
|
||||
},
|
||||
expectLabels: true,
|
||||
},
|
||||
"Both set, flipped -> no change": {
|
||||
original: &Job{
|
||||
Spec: JobSpec{
|
||||
Completions: newInt32(11),
|
||||
Parallelism: newInt32(10),
|
||||
Template: v1.PodTemplateSpec{
|
||||
ObjectMeta: v1.ObjectMeta{Labels: defaultLabels},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: &Job{
|
||||
Spec: JobSpec{
|
||||
Completions: newInt32(11),
|
||||
Parallelism: newInt32(10),
|
||||
},
|
||||
},
|
||||
expectLabels: true,
|
||||
},
|
||||
}
|
||||
|
||||
for name, test := range tests {
|
||||
original := test.original
|
||||
expected := test.expected
|
||||
obj2 := roundTrip(t, runtime.Object(original))
|
||||
actual, ok := obj2.(*Job)
|
||||
if !ok {
|
||||
t.Errorf("%s: unexpected object: %v", name, actual)
|
||||
t.FailNow()
|
||||
}
|
||||
if (actual.Spec.Completions == nil) != (expected.Spec.Completions == nil) {
|
||||
t.Errorf("%s: got different *completions than expected: %v %v", name, actual.Spec.Completions, expected.Spec.Completions)
|
||||
}
|
||||
if actual.Spec.Completions != nil && expected.Spec.Completions != nil {
|
||||
if *actual.Spec.Completions != *expected.Spec.Completions {
|
||||
t.Errorf("%s: got different completions than expected: %d %d", name, *actual.Spec.Completions, *expected.Spec.Completions)
|
||||
}
|
||||
}
|
||||
if (actual.Spec.Parallelism == nil) != (expected.Spec.Parallelism == nil) {
|
||||
t.Errorf("%s: got different *Parallelism than expected: %v %v", name, actual.Spec.Parallelism, expected.Spec.Parallelism)
|
||||
}
|
||||
if actual.Spec.Parallelism != nil && expected.Spec.Parallelism != nil {
|
||||
if *actual.Spec.Parallelism != *expected.Spec.Parallelism {
|
||||
t.Errorf("%s: got different parallelism than expected: %d %d", name, *actual.Spec.Parallelism, *expected.Spec.Parallelism)
|
||||
}
|
||||
}
|
||||
if test.expectLabels != reflect.DeepEqual(actual.Labels, actual.Spec.Template.Labels) {
|
||||
if test.expectLabels {
|
||||
t.Errorf("%s: expected: %v, got: %v", name, actual.Spec.Template.Labels, actual.Labels)
|
||||
} else {
|
||||
t.Errorf("%s: unexpected equality: %v", name, actual.Labels)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDefaultJobSelector(t *testing.T) {
|
||||
tests := []struct {
|
||||
original *Job
|
||||
expectedSelector *metav1.LabelSelector
|
||||
}{
|
||||
// selector set explicitly, nil autoSelector
|
||||
{
|
||||
original: &Job{
|
||||
Spec: JobSpec{
|
||||
Selector: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{"job": "selector"},
|
||||
},
|
||||
},
|
||||
},
|
||||
expectedSelector: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{"job": "selector"},
|
||||
},
|
||||
},
|
||||
// selector set explicitly, autoSelector=true
|
||||
{
|
||||
original: &Job{
|
||||
Spec: JobSpec{
|
||||
Selector: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{"job": "selector"},
|
||||
},
|
||||
AutoSelector: newBool(true),
|
||||
},
|
||||
},
|
||||
expectedSelector: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{"job": "selector"},
|
||||
},
|
||||
},
|
||||
// selector set explicitly, autoSelector=false
|
||||
{
|
||||
original: &Job{
|
||||
Spec: JobSpec{
|
||||
Selector: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{"job": "selector"},
|
||||
},
|
||||
AutoSelector: newBool(false),
|
||||
},
|
||||
},
|
||||
expectedSelector: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{"job": "selector"},
|
||||
},
|
||||
},
|
||||
// selector from template labels
|
||||
{
|
||||
original: &Job{
|
||||
Spec: JobSpec{
|
||||
Template: v1.PodTemplateSpec{
|
||||
ObjectMeta: v1.ObjectMeta{
|
||||
Labels: map[string]string{"job": "selector"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expectedSelector: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{"job": "selector"},
|
||||
},
|
||||
},
|
||||
// selector from template labels, autoSelector=false
|
||||
{
|
||||
original: &Job{
|
||||
Spec: JobSpec{
|
||||
Template: v1.PodTemplateSpec{
|
||||
ObjectMeta: v1.ObjectMeta{
|
||||
Labels: map[string]string{"job": "selector"},
|
||||
},
|
||||
},
|
||||
AutoSelector: newBool(false),
|
||||
},
|
||||
},
|
||||
expectedSelector: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{"job": "selector"},
|
||||
},
|
||||
},
|
||||
// selector not copied from template labels, autoSelector=true
|
||||
{
|
||||
original: &Job{
|
||||
Spec: JobSpec{
|
||||
Template: v1.PodTemplateSpec{
|
||||
ObjectMeta: v1.ObjectMeta{
|
||||
Labels: map[string]string{"job": "selector"},
|
||||
},
|
||||
},
|
||||
AutoSelector: newBool(true),
|
||||
},
|
||||
},
|
||||
expectedSelector: nil,
|
||||
},
|
||||
}
|
||||
|
||||
for i, testcase := range tests {
|
||||
obj2 := roundTrip(t, runtime.Object(testcase.original))
|
||||
got, ok := obj2.(*Job)
|
||||
if !ok {
|
||||
t.Errorf("%d: unexpected object: %v", i, got)
|
||||
t.FailNow()
|
||||
}
|
||||
if !reflect.DeepEqual(got.Spec.Selector, testcase.expectedSelector) {
|
||||
t.Errorf("%d: got different selectors %#v %#v", i, got.Spec.Selector, testcase.expectedSelector)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDefaultReplicaSet(t *testing.T) {
|
||||
tests := []struct {
|
||||
rs *ReplicaSet
|
||||
|
||||
Reference in New Issue
Block a user