Repository: kumahq/kuma
Pull request #3089 (2021-11-04 14:23:22)

feat(disableipv6) don't add v6 in DNS when v6 is disabled
If there's no port forward for v6 we shouldn't add v6 ips in the config

### Backwards compatibility

- [x] Add `backport-to-stable` label if the code is backwards compatible. Otherwise, list breaking changes.



Patch:
diff --git a/pkg/xds/generator/dns_generator.go b/pkg/xds/generator/dns_generator.go
index 2352641b1..93f7d9ac8 100644
--- a/pkg/xds/generator/dns_generator.go
+++ b/pkg/xds/generator/dns_generator.go
@@ -24,13 +24,16 @@ func (g DNSGenerator) Generate(ctx xds_context.Context, proxy *core_xds.Proxy) (
 	if proxy.Dataplane.Spec.GetNetworking().GetTransparentProxying() == nil {
 		return nil, nil // DNS only makes sense when transparent proxy is used
 	}
+	ipV6Enabled := proxy.Dataplane.Spec.GetNetworking().GetTransparentProxying().GetRedirectPortInboundV6() != 0
 
 	vips := map[string][]string{}
 	for _, dnsOutbound := range proxy.Routing.VipDomains {
 		for _, domain := range dnsOutbound.Domains {
-			vips[domain] = []string{dnsOutbound.Address}
 			v6 := util_net.ToV6(dnsOutbound.Address)
-			if v6 != dnsOutbound.Address { // It's already a v6
+			if v6 != dnsOutbound.Address { // The address passed is not already v6
+				vips[domain] = []string{dnsOutbound.Address}
+			}
+			if ipV6Enabled {
 				vips[domain] = append(vips[domain], v6)
 			}
 		}


Test patch:
diff --git a/pkg/xds/generator/dns_generator_test.go b/pkg/xds/generator/dns_generator_test.go
index 3122f33ec..2a21008a6 100644
--- a/pkg/xds/generator/dns_generator_test.go
+++ b/pkg/xds/generator/dns_generator_test.go
@@ -89,5 +89,9 @@ var _ = Describe("DNSGenerator", func() {
 			dataplaneFile: "2-dataplane.input.yaml",
 			expected:      "2-envoy-config.golden.yaml",
 		}),
+		Entry("03. DNS enabled no ipv6", testCase{
+			dataplaneFile: "3-dataplane.input.yaml",
+			expected:      "3-envoy-config.golden.yaml",
+		}),
 	)
 })
diff --git a/pkg/xds/generator/testdata/dns/1-dataplane.input.yaml b/pkg/xds/generator/testdata/dns/1-dataplane.input.yaml
index 3316ad8aa..2e8a49992 100644
--- a/pkg/xds/generator/testdata/dns/1-dataplane.input.yaml
+++ b/pkg/xds/generator/testdata/dns/1-dataplane.input.yaml
@@ -9,4 +9,6 @@ networking:
       tags:
         kuma.io/service: httpbin
   transparentProxying:
-    redirectPort: 15001
+    redirectPortOutbound: 15001
+    redirectPortInboundV6: 15002
+    redirectPortInbound: 15003
diff --git a/pkg/xds/generator/testdata/dns/3-dataplane.input.yaml b/pkg/xds/generator/testdata/dns/3-dataplane.input.yaml
new file mode 100644
index 000000000..23b5caa3a
--- /dev/null
+++ b/pkg/xds/generator/testdata/dns/3-dataplane.input.yaml
@@ -0,0 +1,13 @@
+networking:
+  outbound:
+    - port: 80
+      address: 240.0.0.0
+      tags:
+        kuma.io/service: backend_test-ns_svc_8080
+    - port: 80
+      address: 240.0.0.1
+      tags:
+        kuma.io/service: httpbin
+  transparentProxying:
+    redirectPortOutbound: 15001
+    redirectPortInbound: 15003
diff --git a/pkg/xds/generator/testdata/dns/3-envoy-config.golden.yaml b/pkg/xds/generator/testdata/dns/3-envoy-config.golden.yaml
new file mode 100644
index 000000000..3629f71e7
--- /dev/null
+++ b/pkg/xds/generator/testdata/dns/3-envoy-config.golden.yaml
@@ -0,0 +1,48 @@
+resources:
+- name: kuma:dns
+  resource:
+    '@type': type.googleapis.com/envoy.config.listener.v3.Listener
+    address:
+      socketAddress:
+        address: 127.0.0.1
+        portValue: 53001
+        protocol: UDP
+    listenerFilters:
+    - name: envoy.filters.udp.dns_filter
+      typedConfig:
+        '@type': type.googleapis.com/envoy.extensions.filters.udp.dns_filter.v3alpha.DnsFilterConfig
+        clientConfig:
+          maxPendingLookups: "256"
+          upstreamResolvers:
+          - socketAddress:
+              address: 127.0.0.1
+              portValue: 53002
+        serverConfig:
+          inlineDnsTable:
+            knownSuffixes:
+            - safeRegex:
+                googleRe2: {}
+                regex: .*
+            virtualDomains:
+            - answerTtl: 30s
+              endpoint:
+                addressList:
+                  address:
+                  - 240.0.0.0
+              name: backend.test-ns.svc.8080.mesh
+            - answerTtl: 30s
+              endpoint:
+                addressList:
+                  address:
+                  - 240.0.0.0
+              name: backend_test-ns_svc_8080.mesh
+            - answerTtl: 30s
+              endpoint:
+                addressList:
+                  address:
+                  - 240.0.0.1
+              name: httpbin.mesh
+        statPrefix: kuma_dns
+    name: kuma:dns
+    reusePort: true
+    trafficDirection: INBOUND
diff --git a/pkg/xds/generator/testdata/tracing/zipkin.envoy-config-https.golden.yaml b/pkg/xds/generator/testdata/tracing/zipkin.envoy-config-https.golden.yaml
index b36bceb50..52984ab2f 100644
--- a/pkg/xds/generator/testdata/tracing/zipkin.envoy-config-https.golden.yaml
+++ b/pkg/xds/generator/testdata/tracing/zipkin.envoy-config-https.golden.yaml
@@ -14,10 +14,10 @@ resources:
                 address: zipkin.us
                 portValue: 9090
     name: tracing:zipkin
-    type: STRICT_DNS
     transportSocket:
-          name: envoy.transport_sockets.tls
-          typedConfig:
-            '@type': type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
-            allowRenegotiation: true
-            sni: zipkin.us
+      name: envoy.transport_sockets.tls
+      typedConfig:
+        '@type': type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
+        allowRenegotiation: true
+        sni: zipkin.us
+    type: STRICT_DNS