Skip to content

Commit

Permalink
api: also propagate labels to svc
Browse files Browse the repository at this point in the history
  • Loading branch information
morpheu committed Sep 4, 2023
1 parent 4ceeb2d commit 50e9635
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions api/v1alpha1/rpaasinstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions api/v1alpha1/rpaasinstance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 50e9635

Please sign in to comment.