Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pkg/sdk/resources/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ func (b *ResourceBuilder) WithOperatorLabels(labels map[string]string) map[strin

// CreateOperatorDeployment creates deployment
func (b *ResourceBuilder) CreateOperatorDeployment(name, namespace, matchKey, matchValue, serviceAccount string, numReplicas int32, podSpec corev1.PodSpec) *appsv1.Deployment {
labels := WithLabels(map[string]string{matchKey: matchValue}, b.operatorLabels)
return CreateDeployment(name, namespace, labels, labels, numReplicas, podSpec, serviceAccount, nil)
selectorLabels := WithLabels(map[string]string{matchKey: matchValue}, b.operatorLabels)
podLabels := WithLabels(map[string]string{matchKey: matchValue}, b.operatorLabels)
return CreateDeployment(name, namespace, selectorLabels, podLabels, numReplicas, podSpec, serviceAccount, nil)
}

// CreateDeployment creates deployment
Expand Down
13 changes: 13 additions & 0 deletions pkg/sdk/resources/resources_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package resources

import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

func TestResources(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Resources Suite")
}
32 changes: 32 additions & 0 deletions pkg/sdk/resources/resources_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package resources

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

corev1 "k8s.io/api/core/v1"
)

var _ = Describe("CreateOperatorDeployment", func() {
It("should use distinct maps for selector and pod template labels", func() {
builder := NewResourceBuilder(
map[string]string{"common": "label"},
map[string]string{"operator": "label"},
)

deployment := builder.CreateOperatorDeployment(
"test-operator", "test-ns",
"app", "my-operator",
"sa", 1, corev1.PodSpec{},
)

selectorLabels := deployment.Spec.Selector.MatchLabels
podLabels := deployment.Spec.Template.Labels

Expect(selectorLabels).To(Equal(podLabels))

podLabels["extra-pod-label"] = "should-not-leak"

Expect(selectorLabels).ToNot(HaveKey("extra-pod-label"))
})
})