Repository: kumahq/kuma
Pull request #3285 (2021-11-23 12:01:45)

chore(kuma-cp) remove dp token from xds metadata (backport #3282)
This is an automatic backport of pull request #3282 done by [Mergify](https://mergify.com).


---


<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.com/) you can:

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

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



Patch:
diff --git a/pkg/core/xds/metadata.go b/pkg/core/xds/metadata.go
index 5ad9b791d..4dafb55b2 100644
--- a/pkg/core/xds/metadata.go
+++ b/pkg/core/xds/metadata.go
@@ -18,7 +18,6 @@ var metadataLog = core.Log.WithName("xds-server").WithName("metadata-tracker")
 const (
 	// Supported Envoy node metadata fields.
 
-	fieldDataplaneToken             = "dataplane.token"
 	fieldDataplaneAdminPort         = "dataplane.admin.port"
 	fieldDataplaneDNSPort           = "dataplane.dns.port"
 	fieldDataplaneDNSEmptyPort      = "dataplane.dns.empty.port"
@@ -43,7 +42,6 @@ const (
 // This way, xDS server will be able to use Envoy node metadata
 // to generate xDS resources that depend on environment-specific configuration.
 type DataplaneMetadata struct {
-	DataplaneToken  string
 	Resource        model.Resource
 	AdminPort       uint32
 	DNSPort         uint32
@@ -53,13 +51,6 @@ type DataplaneMetadata struct {
 	Version         *mesh_proto.Version
 }
 
-func (m *DataplaneMetadata) GetDataplaneToken() string {
-	if m == nil {
-		return ""
-	}
-	return m.DataplaneToken
-}
-
 // GetDataplaneResource returns the underlying DataplaneResource, if present.
 // If the resource is of a different type, it returns nil.
 func (m *DataplaneMetadata) GetDataplaneResource() *core_mesh.DataplaneResource {
@@ -131,9 +122,6 @@ func DataplaneMetadataFromXdsMetadata(xdsMetadata *structpb.Struct) *DataplaneMe
 	if xdsMetadata == nil {
 		return &metadata
 	}
-	if field := xdsMetadata.Fields[fieldDataplaneToken]; field != nil {
-		metadata.DataplaneToken = field.GetStringValue()
-	}
 	if field := xdsMetadata.Fields[fieldDataplaneProxyType]; field != nil {
 		metadata.ProxyType = mesh_proto.ProxyType(field.GetStringValue())
 	}
diff --git a/pkg/xds/bootstrap/template_v3.go b/pkg/xds/bootstrap/template_v3.go
index 4b8509c5c..7b309195c 100644
--- a/pkg/xds/bootstrap/template_v3.go
+++ b/pkg/xds/bootstrap/template_v3.go
@@ -232,7 +232,6 @@ func genConfig(parameters configParameters) (*envoy_bootstrap_v3.Bootstrap, erro
 	}
 
 	if parameters.DataplaneToken != "" {
-		res.Node.Metadata.Fields["dataplane.token"] = util_proto.MustNewValueForStruct(parameters.DataplaneToken)
 		if res.HdsConfig != nil {
 			for _, n := range res.HdsConfig.GrpcServices {
 				n.InitialMetadata = []*envoy_core_v3.HeaderValue{


Test patch:
diff --git a/pkg/xds/bootstrap/testdata/bootstrap.k8s.golden.yaml b/pkg/xds/bootstrap/testdata/bootstrap.k8s.golden.yaml
index 6780f004b..1647666a2 100644
--- a/pkg/xds/bootstrap/testdata/bootstrap.k8s.golden.yaml
+++ b/pkg/xds/bootstrap/testdata/bootstrap.k8s.golden.yaml
@@ -37,7 +37,6 @@ node:
   id: default.dp-1.default
   metadata:
     dataplane.proxyType: dataplane
-    dataplane.token: token
     version:
       envoy:
         build: hash/1.15.0/RELEASE
diff --git a/pkg/xds/bootstrap/testdata/bootstrap.overridden.golden.yaml b/pkg/xds/bootstrap/testdata/bootstrap.overridden.golden.yaml
index e1cbe6817..fe6c4d4ad 100644
--- a/pkg/xds/bootstrap/testdata/bootstrap.overridden.golden.yaml
+++ b/pkg/xds/bootstrap/testdata/bootstrap.overridden.golden.yaml
@@ -44,7 +44,6 @@ node:
   metadata:
     dataplane.admin.port: "1234"
     dataplane.proxyType: dataplane
-    dataplane.token: token
     version:
       envoy:
         build: hash/1.15.0/RELEASE
diff --git a/pkg/xds/bootstrap/testdata/bootstrap.universal.golden.yaml b/pkg/xds/bootstrap/testdata/bootstrap.universal.golden.yaml
index ddcadb3d2..273de1999 100644
--- a/pkg/xds/bootstrap/testdata/bootstrap.universal.golden.yaml
+++ b/pkg/xds/bootstrap/testdata/bootstrap.universal.golden.yaml
@@ -37,7 +37,6 @@ node:
   id: default.dp-1
   metadata:
     dataplane.proxyType: dataplane
-    dataplane.token: token
     version:
       envoy:
         build: hash/1.15.0/RELEASE
diff --git a/pkg/xds/bootstrap/testdata/generator.custom-config.golden.yaml b/pkg/xds/bootstrap/testdata/generator.custom-config.golden.yaml
index 8992a6316..f569444b7 100644
--- a/pkg/xds/bootstrap/testdata/generator.custom-config.golden.yaml
+++ b/pkg/xds/bootstrap/testdata/generator.custom-config.golden.yaml
@@ -66,7 +66,6 @@ node:
           ]
         }
       }
-    dataplane.token: token
     dynamicMetadata:
       test: value
     version:
diff --git a/pkg/xds/bootstrap/testdata/generator.default-config.golden.yaml b/pkg/xds/bootstrap/testdata/generator.default-config.golden.yaml
index bd27dadd2..29df59b42 100644
--- a/pkg/xds/bootstrap/testdata/generator.default-config.golden.yaml
+++ b/pkg/xds/bootstrap/testdata/generator.default-config.golden.yaml
@@ -46,7 +46,6 @@ node:
     dataplane.dns.empty.port: "53002"
     dataplane.dns.port: "53001"
     dataplane.proxyType: dataplane
-    dataplane.token: token
     version:
       envoy:
         build: hash/1.15.0/RELEASE
diff --git a/pkg/xds/bootstrap/testdata/generator.default-config.kubernetes.golden.yaml b/pkg/xds/bootstrap/testdata/generator.default-config.kubernetes.golden.yaml
index 47da98b56..07aa3eb6f 100644
--- a/pkg/xds/bootstrap/testdata/generator.default-config.kubernetes.golden.yaml
+++ b/pkg/xds/bootstrap/testdata/generator.default-config.kubernetes.golden.yaml
@@ -34,7 +34,6 @@ node:
   metadata:
     dataplane.admin.port: "1234"
     dataplane.proxyType: dataplane
-    dataplane.token: token
     version:
       envoy:
         build: hash/1.15.0/RELEASE
diff --git a/pkg/xds/bootstrap/testdata/generator.default-config.kubernetes.ipv6.golden.yaml b/pkg/xds/bootstrap/testdata/generator.default-config.kubernetes.ipv6.golden.yaml
index 529502403..fa6c9ad2f 100644
--- a/pkg/xds/bootstrap/testdata/generator.default-config.kubernetes.ipv6.golden.yaml
+++ b/pkg/xds/bootstrap/testdata/generator.default-config.kubernetes.ipv6.golden.yaml
@@ -34,7 +34,6 @@ node:
   metadata:
     dataplane.admin.port: "1234"
     dataplane.proxyType: dataplane
-    dataplane.token: token
     version:
       envoy:
         build: hash/1.15.0/RELEASE
diff --git a/pkg/xds/envoy/clusters/v3/client_side_mtls_configurer_test.go b/pkg/xds/envoy/clusters/v3/client_side_mtls_configurer_test.go
index 067ba4e1b..8491dd4d3 100644
--- a/pkg/xds/envoy/clusters/v3/client_side_mtls_configurer_test.go
+++ b/pkg/xds/envoy/clusters/v3/client_side_mtls_configurer_test.go
@@ -7,7 +7,6 @@ import (
 
 	mesh_proto "github.com/kumahq/kuma/api/mesh/v1alpha1"
 	core_mesh "github.com/kumahq/kuma/pkg/core/resources/apis/mesh"
-	core_xds "github.com/kumahq/kuma/pkg/core/xds"
 	test_model "github.com/kumahq/kuma/pkg/test/resources/model"
 	util_proto "github.com/kumahq/kuma/pkg/util/proto"
 	xds_context "github.com/kumahq/kuma/pkg/xds/context"
@@ -22,7 +21,6 @@ var _ = Describe("EdsClusterConfigurer", func() {
 		clientService string
 		tags          []envoy.Tags
 		ctx           xds_context.Context
-		metadata      *core_xds.DataplaneMetadata
 		expected      string
 	}
 
@@ -212,9 +210,6 @@ var _ = Describe("EdsClusterConfigurer", func() {
 					},
 				},
 			},
-			metadata: &core_xds.DataplaneMetadata{
-				DataplaneToken: "token",
-			},
 			tags: []envoy.Tags{
 				{
 					"kuma.io/service": "backend",
diff --git a/pkg/xds/server/callbacks/dataplane_metadata_tracker_test.go b/pkg/xds/server/callbacks/dataplane_metadata_tracker_test.go
index 1e7bbb5ba..d04f52f70 100644
--- a/pkg/xds/server/callbacks/dataplane_metadata_tracker_test.go
+++ b/pkg/xds/server/callbacks/dataplane_metadata_tracker_test.go
@@ -26,9 +26,9 @@ var _ = Describe("Dataplane Metadata Tracker", func() {
 			Id: "default.example",
 			Metadata: &structpb.Struct{
 				Fields: map[string]*structpb.Value{
-					"dataplane.token": {
+					"dataplane.dns.port": {
 						Kind: &structpb.Value_StringValue{
-							StringValue: "token",
+							StringValue: "9090",
 						},
 					},
 				},
@@ -48,7 +48,7 @@ var _ = Describe("Dataplane Metadata Tracker", func() {
 		metadata := tracker.Metadata(dpKey)
 
 		// then
-		Expect(metadata.GetDataplaneToken()).To(Equal("token"))
+		Expect(metadata.GetDNSPort()).To(Equal(uint32(9090)))
 
 		// when
 		callbacks.OnStreamClosed(streamId)
@@ -75,6 +75,6 @@ var _ = Describe("Dataplane Metadata Tracker", func() {
 		metadata := tracker.Metadata(dpKey)
 
 		// then
-		Expect(metadata.GetDataplaneToken()).To(Equal("token"))
+		Expect(metadata.GetDNSPort()).To(Equal(uint32(9090)))
 	})
 })