Skip to content

Commit

Permalink
Add dnsmasq nodeSelector tests
Browse files Browse the repository at this point in the history
  • Loading branch information
olliewalsh committed Nov 20, 2024
1 parent 0dea211 commit ca8d569
Showing 1 changed file with 106 additions and 0 deletions.
106 changes: 106 additions & 0 deletions tests/functional/dnsmasq_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,110 @@ var _ = Describe("DNSMasq controller", func() {
})
})
})

When("A DNSMasq is created with nodeSelector", func() {
BeforeEach(func() {
spec := GetDefaultDNSMasqSpec()
spec["nodeSelector"] = map[string]interface{}{
"foo": "bar",
}
instance := CreateDNSMasq(namespace, spec)
dnsMasqName = types.NamespacedName{
Name: instance.GetName(),
Namespace: namespace,
}
dnsMasqServiceAccountName = types.NamespacedName{
Namespace: namespace,
Name: "dnsmasq-" + dnsMasqName.Name,
}
dnsMasqRoleName = types.NamespacedName{
Namespace: namespace,
Name: dnsMasqServiceAccountName.Name + "-role",
}
dnsMasqRoleBindingName = types.NamespacedName{
Namespace: namespace,
Name: dnsMasqServiceAccountName.Name + "-rolebinding",
}
deploymentName = types.NamespacedName{
Namespace: namespace,
Name: "dnsmasq-" + dnsMasqName.Name,
}

dnsDataCM = types.NamespacedName{
Namespace: namespace,
Name: "some-dnsdata",
}

th.CreateConfigMap(dnsDataCM, map[string]interface{}{
dnsDataCM.Name: "172.20.0.80 keystone-internal.openstack.svc",
})
cm := th.GetConfigMap(dnsDataCM)
cm.Labels = util.MergeStringMaps(cm.Labels, map[string]string{
"dnsmasqhosts": "dnsdata",
})
Expect(th.K8sClient.Update(ctx, cm)).Should(Succeed())

DeferCleanup(th.DeleteConfigMap, dnsDataCM)
DeferCleanup(th.DeleteInstance, instance)
th.SimulateLoadBalancerServiceIP(deploymentName)
})

It("sets nodeSelector in resource specs", func() {
Eventually(func(g Gomega) {
g.Expect(th.GetDeployment(deploymentName).Spec.Template.Spec.NodeSelector).To(Equal(map[string]string{"foo": "bar"}))
}, timeout, interval).Should(Succeed())
})

It("updates nodeSelector in resource specs when changed", func() {
Eventually(func(g Gomega) {
g.Expect(th.GetDeployment(deploymentName).Spec.Template.Spec.NodeSelector).To(Equal(map[string]string{"foo": "bar"}))
}, timeout, interval).Should(Succeed())

Eventually(func(g Gomega) {
dnsmasq := GetDNSMasq(dnsMasqName)
newNodeSelector := map[string]string{
"foo2": "bar2",
}
dnsmasq.Spec.NodeSelector = &newNodeSelector
g.Expect(k8sClient.Update(ctx, dnsmasq)).Should(Succeed())
}, timeout, interval).Should(Succeed())

Eventually(func(g Gomega) {
g.Expect(th.GetDeployment(deploymentName).Spec.Template.Spec.NodeSelector).To(Equal(map[string]string{"foo2": "bar2"}))
}, timeout, interval).Should(Succeed())
})

It("removes nodeSelector from resource specs when cleared", func() {
Eventually(func(g Gomega) {
g.Expect(th.GetDeployment(deploymentName).Spec.Template.Spec.NodeSelector).To(Equal(map[string]string{"foo": "bar"}))
}, timeout, interval).Should(Succeed())

Eventually(func(g Gomega) {
dnsmasq := GetDNSMasq(dnsMasqName)
emptyNodeSelector := map[string]string{}
dnsmasq.Spec.NodeSelector = &emptyNodeSelector
g.Expect(k8sClient.Update(ctx, dnsmasq)).Should(Succeed())
}, timeout, interval).Should(Succeed())

Eventually(func(g Gomega) {
g.Expect(th.GetDeployment(deploymentName).Spec.Template.Spec.NodeSelector).To(BeNil())
}, timeout, interval).Should(Succeed())
})

It("removes nodeSelector from resource specs when nilled", func() {
Eventually(func(g Gomega) {
g.Expect(th.GetDeployment(deploymentName).Spec.Template.Spec.NodeSelector).To(Equal(map[string]string{"foo": "bar"}))
}, timeout, interval).Should(Succeed())

Eventually(func(g Gomega) {
dnsmasq := GetDNSMasq(dnsMasqName)
dnsmasq.Spec.NodeSelector = nil
g.Expect(k8sClient.Update(ctx, dnsmasq)).Should(Succeed())
}, timeout, interval).Should(Succeed())

Eventually(func(g Gomega) {
g.Expect(th.GetDeployment(deploymentName).Spec.Template.Spec.NodeSelector).To(BeNil())
}, timeout, interval).Should(Succeed())
})
})
})

0 comments on commit ca8d569

Please sign in to comment.