mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 23:17:50 +00:00
Default replica controller nodeSelector using pod template.
Add default labels from pod if not present.
This commit is contained in:
@@ -46,6 +46,115 @@ func roundTrip(t *testing.T, obj runtime.Object) runtime.Object {
|
||||
return obj3
|
||||
}
|
||||
|
||||
func TestSetDefaultReplicationController(t *testing.T) {
|
||||
tests := []struct {
|
||||
rc *current.ReplicationController
|
||||
expectLabels bool
|
||||
expectSelector bool
|
||||
}{
|
||||
{
|
||||
rc: ¤t.ReplicationController{
|
||||
Spec: current.ReplicationControllerSpec{
|
||||
Template: ¤t.PodTemplateSpec{
|
||||
ObjectMeta: current.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expectLabels: true,
|
||||
expectSelector: true,
|
||||
},
|
||||
{
|
||||
rc: ¤t.ReplicationController{
|
||||
ObjectMeta: current.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"bar": "foo",
|
||||
},
|
||||
},
|
||||
Spec: current.ReplicationControllerSpec{
|
||||
Template: ¤t.PodTemplateSpec{
|
||||
ObjectMeta: current.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expectLabels: false,
|
||||
expectSelector: true,
|
||||
},
|
||||
{
|
||||
rc: ¤t.ReplicationController{
|
||||
ObjectMeta: current.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"bar": "foo",
|
||||
},
|
||||
},
|
||||
Spec: current.ReplicationControllerSpec{
|
||||
Selector: map[string]string{
|
||||
"some": "other",
|
||||
},
|
||||
Template: ¤t.PodTemplateSpec{
|
||||
ObjectMeta: current.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expectLabels: false,
|
||||
expectSelector: false,
|
||||
},
|
||||
{
|
||||
rc: ¤t.ReplicationController{
|
||||
Spec: current.ReplicationControllerSpec{
|
||||
Selector: map[string]string{
|
||||
"some": "other",
|
||||
},
|
||||
Template: ¤t.PodTemplateSpec{
|
||||
ObjectMeta: current.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expectLabels: true,
|
||||
expectSelector: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
rc := test.rc
|
||||
obj2 := roundTrip(t, runtime.Object(rc))
|
||||
rc2, ok := obj2.(*current.ReplicationController)
|
||||
if !ok {
|
||||
t.Errorf("unexpected object: %v", rc2)
|
||||
t.FailNow()
|
||||
}
|
||||
if test.expectSelector != reflect.DeepEqual(rc2.Spec.Selector, rc2.Spec.Template.Labels) {
|
||||
if test.expectSelector {
|
||||
t.Errorf("expected: %v, got: %v", rc2.Spec.Template.Labels, rc2.Spec.Selector)
|
||||
} else {
|
||||
t.Errorf("unexpected equality: %v", rc.Spec.Selector)
|
||||
}
|
||||
}
|
||||
if test.expectLabels != reflect.DeepEqual(rc2.Labels, rc2.Spec.Template.Labels) {
|
||||
if test.expectLabels {
|
||||
t.Errorf("expected: %v, got: %v", rc2.Spec.Template.Labels, rc2.Labels)
|
||||
} else {
|
||||
t.Errorf("unexpected equality: %v", rc.Labels)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDefaultService(t *testing.T) {
|
||||
svc := ¤t.Service{}
|
||||
obj2 := roundTrip(t, runtime.Object(svc))
|
||||
|
||||
Reference in New Issue
Block a user