Skip to content

Commit

Permalink
Fix merge string string map function + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adracus committed Oct 6, 2021
1 parent a6df6fa commit cb70d34
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 4 deletions.
6 changes: 5 additions & 1 deletion config/samples/matryoshka_v1alpha1_kubeapiserver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,8 @@ spec:
anonymous: true
bootstrapToken: true
tokenSecret:
name: apiserver-token-sample
name: apiserver-token-sample
overlay:
metadata:
labels:
foo: bar
4 changes: 4 additions & 0 deletions config/samples/matryoshka_v1alpha1_kubecontrollermanager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,7 @@ spec:
name: apiserver-cert-and-key
privateKeySecret:
name: apiserver-cert-and-key
overlay:
metadata:
labels:
foo: bar
2 changes: 1 addition & 1 deletion controllers/matryoshka/internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 14 additions & 1 deletion controllers/matryoshka/kubeapiserver_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(
Expand Down
15 changes: 14 additions & 1 deletion controllers/matryoshka/kubecontrollermanager_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit cb70d34

Please sign in to comment.