@@ -25,6 +25,7 @@ import (
2525 corev1 "k8s.io/api/core/v1"
2626 "k8s.io/apimachinery/pkg/types"
2727
28+ networkv1 "github.com/openstack-k8s-operators/infra-operator/apis/network/v1beta1"
2829 topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
2930 condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
3031 "github.com/openstack-k8s-operators/lib-common/modules/common/util"
@@ -141,6 +142,8 @@ var _ = Describe("DNSMasq controller", func() {
141142 ContainSubstring ("server=1.1.1.1" ))
142143 Expect (configData .Data [dnsMasqName .Name ]).Should (
143144 ContainSubstring ("no-negcache\n " ))
145+ Expect (configData .Data [dnsMasqName .Name ]).Should (
146+ ContainSubstring (fmt .Sprintf ("local=/%s.svc/" , namespace )))
144147 Expect (configData .Labels ["dnsmasq.openstack.org/name" ]).To (Equal (dnsMasqName .Name ))
145148 })
146149
@@ -273,6 +276,64 @@ var _ = Describe("DNSMasq controller", func() {
273276 })
274277 })
275278
279+ When ("A DNSMasq is created with a custom local option" , func () {
280+ BeforeEach (func () {
281+ spec := GetDefaultDNSMasqSpec ()
282+ spec ["options" ] = any ([]networkv1.DNSMasqOption {
283+ {
284+ Key : "server" ,
285+ Values : []string {"1.1.1.1" },
286+ },
287+ {
288+ Key : "no-negcache" ,
289+ Values : []string {},
290+ },
291+ {
292+ Key : "local" ,
293+ Values : []string {"/custom.svc/" },
294+ },
295+ })
296+ instance := CreateDNSMasq (namespace , spec )
297+ dnsMasqName = types.NamespacedName {
298+ Name : instance .GetName (),
299+ Namespace : namespace ,
300+ }
301+
302+ dnsDataCM = types.NamespacedName {
303+ Namespace : namespace ,
304+ Name : "some-dnsdata" ,
305+ }
306+
307+ th .CreateConfigMap (dnsDataCM , map [string ]any {
308+ dnsDataCM .Name : "172.20.0.80 keystone-internal.openstack.svc" ,
309+ })
310+ cm := th .GetConfigMap (dnsDataCM )
311+ cm .Labels = util .MergeStringMaps (cm .Labels , map [string ]string {
312+ "dnsmasqhosts" : "dnsdata" ,
313+ })
314+ Expect (th .K8sClient .Update (ctx , cm )).Should (Succeed ())
315+
316+ DeferCleanup (th .DeleteConfigMap , dnsDataCM )
317+ DeferCleanup (th .DeleteInstance , instance )
318+ })
319+
320+ It ("uses the custom local value and does not add the default" , func () {
321+ th .ExpectCondition (
322+ dnsMasqName ,
323+ ConditionGetterFunc (DNSMasqConditionGetter ),
324+ condition .ServiceConfigReadyCondition ,
325+ corev1 .ConditionTrue ,
326+ )
327+
328+ configData := th .GetConfigMap (dnsMasqName )
329+ Expect (configData ).ShouldNot (BeNil ())
330+ Expect (configData .Data [dnsMasqName .Name ]).Should (
331+ ContainSubstring ("local=/custom.svc/" ))
332+ Expect (configData .Data [dnsMasqName .Name ]).ShouldNot (
333+ ContainSubstring (fmt .Sprintf ("local=/%s.svc/" , namespace )))
334+ })
335+ })
336+
276337 When ("Deployment rollout is progressing" , func () {
277338 BeforeEach (func () {
278339 instance := CreateDNSMasq (namespace , GetDefaultDNSMasqSpec ())
0 commit comments