Default replica controller nodeSelector using pod template.

Add default labels from pod if not present.
This commit is contained in:
Brendan Burns
2015-04-08 22:13:59 -07:00
parent e44ec497ed
commit fded23a777
9 changed files with 341 additions and 5 deletions

View File

@@ -46,6 +46,102 @@ 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: &current.ReplicationController{
DesiredState: current.ReplicationControllerState{
PodTemplate: current.PodTemplate{
Labels: map[string]string{
"foo": "bar",
},
},
},
},
expectLabels: true,
expectSelector: true,
},
{
rc: &current.ReplicationController{
Labels: map[string]string{
"bar": "foo",
},
DesiredState: current.ReplicationControllerState{
PodTemplate: current.PodTemplate{
Labels: map[string]string{
"foo": "bar",
},
},
},
},
expectLabels: false,
expectSelector: true,
},
{
rc: &current.ReplicationController{
Labels: map[string]string{
"bar": "foo",
},
DesiredState: current.ReplicationControllerState{
ReplicaSelector: map[string]string{
"some": "other",
},
PodTemplate: current.PodTemplate{
Labels: map[string]string{
"foo": "bar",
},
},
},
},
expectLabels: false,
expectSelector: false,
},
{
rc: &current.ReplicationController{
DesiredState: current.ReplicationControllerState{
ReplicaSelector: map[string]string{
"some": "other",
},
PodTemplate: current.PodTemplate{
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.DesiredState.ReplicaSelector, rc2.DesiredState.PodTemplate.Labels) {
if test.expectSelector {
t.Errorf("expected: %v, got: %v", rc2.DesiredState.PodTemplate.Labels, rc2.DesiredState.ReplicaSelector)
} else {
t.Errorf("unexpected equality: %v", rc2.DesiredState.PodTemplate.Labels)
}
}
if test.expectLabels != reflect.DeepEqual(rc2.Labels, rc2.DesiredState.PodTemplate.Labels) {
if test.expectLabels {
t.Errorf("expected: %v, got: %v", rc2.DesiredState.PodTemplate.Labels, rc2.Labels)
} else {
t.Errorf("unexpected equality: %v", rc2.DesiredState.PodTemplate.Labels)
}
}
}
}
func TestSetDefaultService(t *testing.T) {
svc := &current.Service{}
obj2 := roundTrip(t, runtime.Object(svc))