diff --git a/api/v1alpha1/rpaasinstance.go b/api/v1alpha1/rpaasinstance.go index 5b983a72a..c48607a24 100644 --- a/api/v1alpha1/rpaasinstance.go +++ b/api/v1alpha1/rpaasinstance.go @@ -109,6 +109,9 @@ func (i *RpaasInstance) appendNewLabels(newLabels map[string]string) { i.Labels = mergeMap(i.Labels, newLabels) i.Annotations = mergeMap(i.Annotations, newLabels) i.Spec.PodTemplate.Labels = mergeMap(i.Spec.PodTemplate.Labels, newLabels) + if i.Spec.Service != nil { + i.Spec.Service.Labels = mergeMap(i.Spec.Service.Labels, newLabels) + } } func mergeMap(a, b map[string]string) map[string]string { diff --git a/api/v1alpha1/rpaasinstance_test.go b/api/v1alpha1/rpaasinstance_test.go index 3fe336d6f..b9437dca3 100644 --- a/api/v1alpha1/rpaasinstance_test.go +++ b/api/v1alpha1/rpaasinstance_test.go @@ -8,22 +8,26 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/tsuru/nginx-operator/api/v1alpha1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func Test_SetTeamOwner(t *testing.T) { instance := &RpaasInstance{} + instance.Spec.Service = &v1alpha1.NginxService{} instance.SetTeamOwner("team-one") expected := map[string]string{RpaasOperatorTeamOwnerLabelKey: "team-one"} assert.Equal(t, expected, instance.Labels) assert.Equal(t, expected, instance.Annotations) assert.Equal(t, expected, instance.Spec.PodTemplate.Labels) + assert.Equal(t, expected, instance.Spec.Service.Labels) instance.SetTeamOwner("team-two") expected = map[string]string{RpaasOperatorTeamOwnerLabelKey: "team-two"} assert.Equal(t, expected, instance.Labels) assert.Equal(t, expected, instance.Annotations) assert.Equal(t, expected, instance.Spec.PodTemplate.Labels) + assert.Equal(t, expected, instance.Spec.Service.Labels) } func Test_GetTeamOwner(t *testing.T) {