diff --git a/config/samples/matryoshka_v1alpha1_kubeapiserver.yaml b/config/samples/matryoshka_v1alpha1_kubeapiserver.yaml index 8addb2a..ae6f0a3 100644 --- a/config/samples/matryoshka_v1alpha1_kubeapiserver.yaml +++ b/config/samples/matryoshka_v1alpha1_kubeapiserver.yaml @@ -163,4 +163,8 @@ spec: anonymous: true bootstrapToken: true tokenSecret: - name: apiserver-token-sample \ No newline at end of file + name: apiserver-token-sample + overlay: + metadata: + labels: + foo: bar \ No newline at end of file diff --git a/config/samples/matryoshka_v1alpha1_kubecontrollermanager.yaml b/config/samples/matryoshka_v1alpha1_kubecontrollermanager.yaml index 13aaf3f..3cd2d82 100644 --- a/config/samples/matryoshka_v1alpha1_kubecontrollermanager.yaml +++ b/config/samples/matryoshka_v1alpha1_kubecontrollermanager.yaml @@ -71,3 +71,7 @@ spec: name: apiserver-cert-and-key privateKeySecret: name: apiserver-cert-and-key + overlay: + metadata: + labels: + foo: bar diff --git a/controllers/matryoshka/internal/utils/utils.go b/controllers/matryoshka/internal/utils/utils.go index 4dcec15..d1324c8 100644 --- a/controllers/matryoshka/internal/utils/utils.go +++ b/controllers/matryoshka/internal/utils/utils.go @@ -133,7 +133,7 @@ func ComputeMountableChecksum(secrets []corev1.Secret, configMaps []corev1.Confi func MergeStringStringMaps(ms ...map[string]string) map[string]string { var res map[string]string for _, m := range ms { - if m != nil { + if m != nil && res == nil { res = make(map[string]string) } for k, v := range m { diff --git a/controllers/matryoshka/kubeapiserver_controller_test.go b/controllers/matryoshka/kubeapiserver_controller_test.go index 0479968..aa4cc64 100644 --- a/controllers/matryoshka/kubeapiserver_controller_test.go +++ b/controllers/matryoshka/kubeapiserver_controller_test.go @@ -19,6 +19,9 @@ import ( "fmt" "time" + "github.com/onmetal/matryoshka/controllers/matryoshka/internal/utils" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + matryoshkav1alpha1 "github.com/onmetal/matryoshka/apis/matryoshka/v1alpha1" "github.com/onmetal/matryoshka/controllers/matryoshka/internal/kubeapiserver" . "github.com/onsi/ginkgo" @@ -49,10 +52,20 @@ var _ = Describe("KubeAPIServerController", func() { return k8sClient.Get(ctx, client.ObjectKey{Namespace: ns.Name, Name: "apiserver-sample"}, deployment) }, 3*time.Second).Should(Succeed()) + By("inspecting the deployment") + Expect(deployment.Spec.Selector).To(Equal(&metav1.LabelSelector{ + MatchLabels: map[string]string{ + "matryoshka.onmetal.de/app": "kubeapiserver-apiserver-sample", + }, + })) + By("inspecting the deployment template") template := deployment.Spec.Template Expect(template.Labels).NotTo(BeEmpty()) - Expect(deployment.Spec.Selector.MatchLabels).To(Equal(template.Labels)) + Expect(template.Labels).To(Equal(utils.MergeStringStringMaps( + deployment.Spec.Selector.MatchLabels, + map[string]string{"foo": "bar"}, + ))) By("inspecting the volumes") Expect(template.Spec.Volumes).To(ConsistOf( diff --git a/controllers/matryoshka/kubecontrollermanager_controller_test.go b/controllers/matryoshka/kubecontrollermanager_controller_test.go index bf659ff..ce71fd8 100644 --- a/controllers/matryoshka/kubecontrollermanager_controller_test.go +++ b/controllers/matryoshka/kubecontrollermanager_controller_test.go @@ -19,6 +19,9 @@ import ( "fmt" "time" + "github.com/onmetal/matryoshka/controllers/matryoshka/internal/utils" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + matryoshkav1alpha1 "github.com/onmetal/matryoshka/apis/matryoshka/v1alpha1" "github.com/onmetal/matryoshka/controllers/matryoshka/internal/kubecontrollermanager" @@ -52,10 +55,20 @@ var _ = Describe("KubeControllerManagerController", func() { return k8sClient.Get(ctx, client.ObjectKey{Namespace: ns.Name, Name: "kubecontrollermanager-sample"}, deployment) }, 3*time.Second).Should(Succeed()) + By("inspecting the deployment") + Expect(deployment.Spec.Selector).To(Equal(&metav1.LabelSelector{ + MatchLabels: map[string]string{ + "matryoshka.onmetal.de/app": "kubecontrollermanager-kubecontrollermanager-sample", + }, + })) + By("inspecting the deployment template") template := deployment.Spec.Template Expect(template.Labels).NotTo(BeEmpty()) - Expect(deployment.Spec.Selector.MatchLabels).To(Equal(template.Labels)) + Expect(template.Labels).To(Equal(utils.MergeStringStringMaps( + deployment.Spec.Selector.MatchLabels, + map[string]string{"foo": "bar"}, + ))) By("inspecting the volumes") Expect(template.Spec.Volumes).To(ConsistOf(