Repository: kumahq/kuma
Pull request #3090 (2021-11-04 14:53:24)

feat(disableipv6) don't add v6 in DNS when v6 is disabled (backport #3089)
This is an automatic backport of pull request #3089 done by [Mergify](https://mergify.io).
Cherry-pick of 1f507fd10de8299fae0d740d664979de42688a4b has failed:
```
On branch mergify/bp/release-1.3/pr-3089
Your branch is up to date with 'origin/release-1.3'.

You are currently cherry-picking commit 1f507fd1.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   pkg/xds/generator/dns_generator.go
	modified:   pkg/xds/generator/dns_generator_test.go
	modified:   pkg/xds/generator/testdata/dns/1-dataplane.input.yaml
	new file:   pkg/xds/generator/testdata/dns/3-dataplane.input.yaml
	new file:   pkg/xds/generator/testdata/dns/3-envoy-config.golden.yaml

Unmerged paths:
  (use "git add/rm <file>..." as appropriate to mark resolution)
	deleted by us:   pkg/xds/generator/testdata/tracing/zipkin.envoy-config-https.golden.yaml

```


To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/github/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

---


<details>
<summary>Mergify commands and options</summary>

<br />

More conditions and actions can be found in the [documentation](https://docs.mergify.com/).

You can also trigger Mergify actions by commenting on this pull request:

- `@Mergifyio refresh` will re-evaluate the rules
- `@Mergifyio rebase` will rebase this PR on its base branch
- `@Mergifyio update` will merge the base branch into this PR
- `@Mergifyio backport <destination>` will backport this PR on `<destination>` branch

Additionally, on Mergify [dashboard](https://dashboard.mergify.io/) you can:

- look at your merge queues
- generate the Mergify configuration with the config editor.

Finally, you can contact us on https://mergify.io/
</details>


codecov-commenter: # [Codecov](https://codecov.io/gh/kumahq/kuma/pull/3090?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kumahq) Report
> Merging [#3090](https://codecov.io/gh/kumahq/kuma/pull/3090?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kumahq) (1f507fd) into [release-1.3](https://codecov.io/gh/kumahq/kuma/commit/7ad7f1b0c657a3d9a9d8c05caefc38f8516f2223?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kumahq) (7ad7f1b) will **increase** coverage by `0.59%`.
> The diff coverage is `32.80%`.

> :exclamation: Current head 1f507fd differs from pull request most recent head aa794f8. Consider uploading reports for the commit aa794f8 to get more accurate results
[![Impacted file tree graph](https://codecov.io/gh/kumahq/kuma/pull/3090/graphs/tree.svg?width=650&height=150&src=pr&token=D7Yvqs6rwV&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kumahq)](https://codecov.io/gh/kumahq/kuma/pull/3090?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kumahq)

```diff
@@               Coverage Diff               @@
##           release-1.3    #3090      +/-   ##
===============================================
+ Coverage        51.75%   52.35%   +0.59%     
===============================================
  Files              887      919      +32     
  Lines            52057    53208    +1151     
===============================================
+ Hits             26944    27855     +911     
- Misses           22982    23124     +142     
- Partials          2131     2229      +98     
```


| [Impacted Files](https://codecov.io/gh/kumahq/kuma/pull/3090?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kumahq) | Coverage Δ | |
|---|---|---|
| [api/mesh/v1alpha1/dataplane\_helpers.go](https://codecov.io/gh/kumahq/kuma/pull/3090/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kumahq#diff-YXBpL21lc2gvdjFhbHBoYTEvZGF0YXBsYW5lX2hlbHBlcnMuZ28=) | `80.91% <ø> (ø)` | |
| [api/mesh/v1alpha1/virtual\_outbound.pb.go](https://codecov.io/gh/kumahq/kuma/pull/3090/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kumahq#diff-YXBpL21lc2gvdjFhbHBoYTEvdmlydHVhbF9vdXRib3VuZC5wYi5nbw==) | `34.72% <ø> (ø)` | |
| [api/mesh/v1alpha1/zone\_ingress.pb.go](https://codecov.io/gh/kumahq/kuma/pull/3090/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kumahq#diff-YXBpL21lc2gvdjFhbHBoYTEvem9uZV9pbmdyZXNzLnBiLmdv) | `45.16% <ø> (ø)` | |
| [app/kuma-dp/pkg/config/validate.go](https://codecov.io/gh/kumahq/kuma/pull/3090/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kumahq#diff-YXBwL2t1bWEtZHAvcGtnL2NvbmZpZy92YWxpZGF0ZS5nbw==) | `77.77% <ø> (ø)` | |
| [app/kuma-dp/pkg/dataplane/dnsserver/dnsserver.go](https://codecov.io/gh/kumahq/kuma/pull/3090/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kumahq#diff-YXBwL2t1bWEtZHAvcGtnL2RhdGFwbGFuZS9kbnNzZXJ2ZXIvZG5zc2VydmVyLmdv) | `71.42% <ø> (ø)` | |
| [app/kumactl/cmd/apply/apply.go](https://codecov.io/gh/kumahq/kuma/pull/3090/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kumahq#diff-YXBwL2t1bWFjdGwvY21kL2FwcGx5L2FwcGx5Lmdv) | `75.00% <ø> (ø)` | |
| [app/kumactl/cmd/completion/completion.go](https://codecov.io/gh/kumahq/kuma/pull/3090/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kumahq#diff-YXBwL2t1bWFjdGwvY21kL2NvbXBsZXRpb24vY29tcGxldGlvbi5nbw==) | `100.00% <ø> (ø)` | |
| [...pp/kumactl/cmd/config/config\_control\_planes\_add.go](https://codecov.io/gh/kumahq/kuma/pull/3090/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kumahq#diff-YXBwL2t1bWFjdGwvY21kL2NvbmZpZy9jb25maWdfY29udHJvbF9wbGFuZXNfYWRkLmdv) | `81.94% <ø> (+2.91%)` | :arrow_up: |
| [...p/kumactl/cmd/config/config\_control\_planes\_list.go](https://codecov.io/gh/kumahq/kuma/pull/3090/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kumahq#diff-YXBwL2t1bWFjdGwvY21kL2NvbmZpZy9jb25maWdfY29udHJvbF9wbGFuZXNfbGlzdC5nbw==) | `100.00% <ø> (ø)` | |
| [...kumactl/cmd/config/config\_control\_planes\_remove.go](https://codecov.io/gh/kumahq/kuma/pull/3090/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kumahq#diff-YXBwL2t1bWFjdGwvY21kL2NvbmZpZy9jb25maWdfY29udHJvbF9wbGFuZXNfcmVtb3ZlLmdv) | `91.66% <ø> (ø)` | |
| ... and [208 more](https://codecov.io/gh/kumahq/kuma/pull/3090/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kumahq) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/kumahq/kuma/pull/3090?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kumahq).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kumahq)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/kumahq/kuma/pull/3090?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kumahq). Last update [7ad7f1b...aa794f8](https://codecov.io/gh/kumahq/kuma/pull/3090?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kumahq). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kumahq).


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