Repository: envoyproxy/gateway
Pull request #4352 (2024-09-27 19:00:21)

set invalid Listener.SupportedKinds to empty list
Fixes: https://github.com/envoyproxy/gateway/issues/4216

Relates to https://kubernetes.slack.com/archives/CR0H13KGA/p1727457195236889

arkodg: ```
apiVersion: v1
items:
- apiVersion: gateway.networking.k8s.io/v1
  kind: Gateway
  metadata:
    annotations:
      cert-manager.io/cluster-issuer: letsencrypt-production
      kubectl.kubernetes.io/last-applied-configuration: |
        {"apiVersion":"gateway.networking.k8s.io/v1","kind":"Gateway","metadata":{"annotations":{"cert-manager.io/cluster-issuer":"letsencrypt-production"},"name":"https","namespace":"default"},"spec":{"gatewayClassName":"envoy-proxy","listeners":[{"allowedRoutes":{"namespaces":{"from":"All"}},"hostname":"grpc.example.com","name":"grpc.example.com","port":443,"protocol":"GRPC"}]}}
    creationTimestamp: "2024-09-27T18:39:12Z"
    generation: 1
    name: https
    namespace: default
    resourceVersion: "767"
    uid: 70692347-eab4-4051-bd72-5ec5c31d7093
  spec:
    gatewayClassName: envoy-proxy
    listeners:
    - allowedRoutes:
        namespaces:
          from: All
      hostname: grpc.example.com
      name: grpc.example.com
      port: 443
      protocol: GRPC
  status:
    conditions:
    - lastTransitionTime: "2024-09-27T18:39:13Z"
      message: The Gateway has been scheduled by Envoy Gateway
      observedGeneration: 1
      reason: Accepted
      status: "True"
      type: Accepted
    - lastTransitionTime: "2024-09-27T18:39:13Z"
      message: No addresses have been assigned to the Gateway
      observedGeneration: 1
      reason: AddressNotAssigned
      status: "False"
      type: Programmed
    listeners:
    - attachedRoutes: 0
      conditions:
      - lastTransitionTime: "2024-09-27T18:39:13Z"
        message: Protocol GRPC is unsupported, must be HTTP, HTTPS, TCP or UDP.
        observedGeneration: 1
        reason: UnsupportedProtocol
        status: "False"
        type: Accepted
      - lastTransitionTime: "2024-09-27T18:39:13Z"
        message: Listener is invalid, see other Conditions for details.
        observedGeneration: 1
        reason: Invalid
        status: "False"
        type: Programmed
      - lastTransitionTime: "2024-09-27T18:39:13Z"
        message: Listener references have been resolved
        observedGeneration: 1
        reason: ResolvedRefs
        status: "True"
        type: ResolvedRefs
      name: grpc.example.com
      supportedKinds: []
kind: List
metadata:
  resourceVersion: ""
```
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/envoyproxy/gateway/pull/4352?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=envoyproxy) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 65.98%. Comparing base [(`d895da3`)](https://app.codecov.io/gh/envoyproxy/gateway/commit/d895da32f8e42d518195e2f2a46309525964c099?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=envoyproxy) to head [(`d916dc4`)](https://app.codecov.io/gh/envoyproxy/gateway/commit/d916dc40f35de859046993b2d3c3e173f8e2d96d?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=envoyproxy).

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##             main    #4352      +/-   ##
==========================================
- Coverage   66.00%   65.98%   -0.02%     
==========================================
  Files         197      197              
  Lines       23964    23966       +2     
==========================================
- Hits        15817    15814       -3     
- Misses       7021     7026       +5     
  Partials     1126     1126              
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/envoyproxy/gateway/pull/4352?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=envoyproxy).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=envoyproxy).

zirain: /retest

Patch:
diff --git a/api/v1alpha1/tracing_types.go b/api/v1alpha1/tracing_types.go
index 55fd63ef4..293664cdd 100644
--- a/api/v1alpha1/tracing_types.go
+++ b/api/v1alpha1/tracing_types.go
@@ -26,6 +26,7 @@ type TracingProviderType string
 const (
 	TracingProviderTypeOpenTelemetry TracingProviderType = "OpenTelemetry"
 	TracingProviderTypeZipkin        TracingProviderType = "Zipkin"
+	TracingProviderTypeDatadog       TracingProviderType = "Datadog"
 )
 
 // TracingProvider defines the tracing provider configuration.
@@ -37,7 +38,7 @@ const (
 type TracingProvider struct {
 	BackendCluster `json:",inline"`
 	// Type defines the tracing provider type.
-	// +kubebuilder:validation:Enum=OpenTelemetry;Zipkin
+	// +kubebuilder:validation:Enum=OpenTelemetry;Zipkin;Datadog
 	// +kubebuilder:default=OpenTelemetry
 	Type TracingProviderType `json:"type"`
 	// Host define the provider service hostname.
diff --git a/charts/gateway-helm/crds/generated/gateway.envoyproxy.io_envoyproxies.yaml b/charts/gateway-helm/crds/generated/gateway.envoyproxy.io_envoyproxies.yaml
index 8410c05c8..1b18890cd 100644
--- a/charts/gateway-helm/crds/generated/gateway.envoyproxy.io_envoyproxies.yaml
+++ b/charts/gateway-helm/crds/generated/gateway.envoyproxy.io_envoyproxies.yaml
@@ -14220,6 +14220,7 @@ spec:
                             enum:
                             - OpenTelemetry
                             - Zipkin
+                            - Datadog
                             type: string
                           zipkin:
                             description: Zipkin defines the Zipkin tracing provider
diff --git a/internal/gatewayapi/contexts.go b/internal/gatewayapi/contexts.go
index 7d6aee73d..fbd4c588f 100644
--- a/internal/gatewayapi/contexts.go
+++ b/internal/gatewayapi/contexts.go
@@ -76,7 +76,8 @@ type ListenerContext struct {
 }
 
 func (l *ListenerContext) SetSupportedKinds(kinds ...gwapiv1.RouteGroupKind) {
-	l.gateway.Status.Listeners[l.listenerStatusIdx].SupportedKinds = kinds
+	l.gateway.Status.Listeners[l.listenerStatusIdx].SupportedKinds = make([]gwapiv1.RouteGroupKind, 0, len(kinds))
+	l.gateway.Status.Listeners[l.listenerStatusIdx].SupportedKinds = append(l.gateway.Status.Listeners[l.listenerStatusIdx].SupportedKinds, kinds...)
 }
 
 func (l *ListenerContext) IncrementAttachedRoutes() {
diff --git a/internal/gatewayapi/listener.go b/internal/gatewayapi/listener.go
index 724e835eb..0c69d7b30 100644
--- a/internal/gatewayapi/listener.go
+++ b/internal/gatewayapi/listener.go
@@ -74,7 +74,7 @@ func (t *Translator) ProcessListeners(gateways []*GatewayContext, xdsIR resource
 			case gwapiv1.UDPProtocolType:
 				t.validateAllowedRoutes(listener, resource.KindUDPRoute)
 			default:
-				listener.SetSupportedKinds(gwapiv1.RouteGroupKind{Kind: "InvalidKind"})
+				listener.SetSupportedKinds()
 				status.SetGatewayListenerStatusCondition(listener.gateway.Gateway,
 					listener.listenerStatusIdx,
 					gwapiv1.ListenerConditionAccepted,
diff --git a/internal/xds/translator/tracing.go b/internal/xds/translator/tracing.go
index ad9a3ecc0..c7777f94b 100644
--- a/internal/xds/translator/tracing.go
+++ b/internal/xds/translator/tracing.go
@@ -28,6 +28,7 @@ import (
 const (
 	envoyOpenTelemetry = "envoy.tracers.opentelemetry"
 	envoyZipkin        = "envoy.traces.zipkin"
+	envoyDatadog       = "envoy.tracers.datadog"
 )
 
 type typConfigGen func() (*anypb.Any, error)
@@ -41,6 +42,16 @@ func buildHCMTracing(tracing *ir.Tracing) (*hcm.HttpConnectionManager_Tracing, e
 	var providerConfig typConfigGen
 
 	switch tracing.Provider.Type {
+	case egv1a1.TracingProviderTypeDatadog:
+		providerName = envoyDatadog
+
+		providerConfig = func() (*anypb.Any, error) {
+			config := &tracecfg.DatadogConfig{
+				ServiceName:      tracing.ServiceName,
+				CollectorCluster: tracing.Destination.Name,
+			}
+			return protocov.ToAnyWithError(config)
+		}
 	case egv1a1.TracingProviderTypeOpenTelemetry:
 		providerName = envoyOpenTelemetry
 


Test patch:
diff --git a/internal/gatewayapi/testdata/gateway-with-listener-with-unsupported-protocol.out.yaml b/internal/gatewayapi/testdata/gateway-with-listener-with-unsupported-protocol.out.yaml
index 373c2f894..0875ec245 100644
--- a/internal/gatewayapi/testdata/gateway-with-listener-with-unsupported-protocol.out.yaml
+++ b/internal/gatewayapi/testdata/gateway-with-listener-with-unsupported-protocol.out.yaml
@@ -34,8 +34,7 @@ gateways:
         status: "True"
         type: ResolvedRefs
       name: unsupported
-      supportedKinds:
-      - kind: InvalidKind
+      supportedKinds: []
 httpRoutes:
 - apiVersion: gateway.networking.k8s.io/v1
   kind: HTTPRoute
diff --git a/internal/xds/translator/testdata/in/xds-ir/tracing-datadog.yaml b/internal/xds/translator/testdata/in/xds-ir/tracing-datadog.yaml
new file mode 100644
index 000000000..1cc60f85e
--- /dev/null
+++ b/internal/xds/translator/testdata/in/xds-ir/tracing-datadog.yaml
@@ -0,0 +1,49 @@
+name: "tracing"
+tracing:
+  serviceName: "fake-name.fake-ns"
+  samplingRate: 90
+  customTags:
+    "literal1":
+      type: Literal
+      literal:
+        value: "value1"
+    "env1":
+      type: Environment
+      environment:
+        name: "env1"
+        defaultValue: "-"
+    "req1":
+      type: RequestHeader
+      requestHeader:
+        name: "X-Request-Id"
+        defaultValue: "-"
+  authority: "datadog-agent.default.svc.cluster.local"
+  destination:
+    name: "tracing-0"
+    settings:
+      - endpoints:
+          - host: "datadog-agent.default.svc.cluster.local"
+            port: 8126
+  provider:
+    type: Datadog
+http:
+  - name: "first-listener"
+    address: "0.0.0.0"
+    port: 10080
+    hostnames:
+      - "*"
+    path:
+      mergeSlashes: true
+      escapedSlashesAction: UnescapeAndRedirect
+    routes:
+      - name: "direct-route"
+        hostname: "*"
+        destination:
+          name: "direct-route-dest"
+          settings:
+            - endpoints:
+                - host: "1.2.3.4"
+                  port: 50000
+        directResponse:
+          body: "Unknown custom filter type: UnsupportedType"
+          statusCode: 500
diff --git a/internal/xds/translator/testdata/in/xds-ir/tracing-unknown-provider-type.yaml b/internal/xds/translator/testdata/in/xds-ir/tracing-unknown-provider-type.yaml
index 45f669ef6..02623bc0c 100644
--- a/internal/xds/translator/testdata/in/xds-ir/tracing-unknown-provider-type.yaml
+++ b/internal/xds/translator/testdata/in/xds-ir/tracing-unknown-provider-type.yaml
@@ -17,17 +17,17 @@ tracing:
       requestHeader:
         name: "X-Request-Id"
         defaultValue: "-"
-  authority: "datadog-agent.default.svc.cluster.local"
+  authority: "awesome-agent.default.svc.cluster.local"
   destination:
     name: "tracing-0"
     settings:
       - endpoints:
-          - host: "datadog-agent.default.svc.cluster.local"
-            port: 8126
+          - host: "awesome-agent.default.svc.cluster.local"
+            port: 1357
   provider:
-    host: datadog-agent.monitoring.svc.cluster.local
-    port: 8126
-    type: Datadog
+    host: awesome-agent.monitoring.svc.cluster.local
+    port: 1357
+    type: AwesomeTelemetry
 http:
   - name: "first-listener"
     address: "0.0.0.0"
diff --git a/internal/xds/translator/testdata/out/xds-ir/tracing-datadog.clusters.yaml b/internal/xds/translator/testdata/out/xds-ir/tracing-datadog.clusters.yaml
new file mode 100644
index 000000000..51ef59184
--- /dev/null
+++ b/internal/xds/translator/testdata/out/xds-ir/tracing-datadog.clusters.yaml
@@ -0,0 +1,44 @@
+- circuitBreakers:
+    thresholds:
+    - maxRetries: 1024
+  commonLbConfig:
+    localityWeightedLbConfig: {}
+  connectTimeout: 10s
+  dnsLookupFamily: V4_ONLY
+  edsClusterConfig:
+    edsConfig:
+      ads: {}
+      resourceApiVersion: V3
+    serviceName: direct-route-dest
+  lbPolicy: LEAST_REQUEST
+  name: direct-route-dest
+  outlierDetection: {}
+  perConnectionBufferLimitBytes: 32768
+  type: EDS
+- circuitBreakers:
+    thresholds:
+    - maxRetries: 1024
+  commonLbConfig:
+    localityWeightedLbConfig: {}
+  connectTimeout: 10s
+  dnsLookupFamily: V4_ONLY
+  dnsRefreshRate: 30s
+  lbPolicy: LEAST_REQUEST
+  loadAssignment:
+    clusterName: tracing-0
+    endpoints:
+    - lbEndpoints:
+      - endpoint:
+          address:
+            socketAddress:
+              address: datadog-agent.default.svc.cluster.local
+              portValue: 8126
+        loadBalancingWeight: 1
+      loadBalancingWeight: 1
+      locality:
+        region: tracing-0/backend/0
+  name: tracing-0
+  outlierDetection: {}
+  perConnectionBufferLimitBytes: 32768
+  respectDnsTtl: true
+  type: STRICT_DNS
diff --git a/internal/xds/translator/testdata/out/xds-ir/tracing-datadog.endpoints.yaml b/internal/xds/translator/testdata/out/xds-ir/tracing-datadog.endpoints.yaml
new file mode 100644
index 000000000..20c80b3aa
--- /dev/null
+++ b/internal/xds/translator/testdata/out/xds-ir/tracing-datadog.endpoints.yaml
@@ -0,0 +1,12 @@
+- clusterName: direct-route-dest
+  endpoints:
+  - lbEndpoints:
+    - endpoint:
+        address:
+          socketAddress:
+            address: 1.2.3.4
+            portValue: 50000
+      loadBalancingWeight: 1
+    loadBalancingWeight: 1
+    locality:
+      region: direct-route-dest/backend/0
diff --git a/internal/xds/translator/testdata/out/xds-ir/tracing-datadog.listeners.yaml b/internal/xds/translator/testdata/out/xds-ir/tracing-datadog.listeners.yaml
new file mode 100644
index 000000000..07a3d5815
--- /dev/null
+++ b/internal/xds/translator/testdata/out/xds-ir/tracing-datadog.listeners.yaml
@@ -0,0 +1,60 @@
+- address:
+    socketAddress:
+      address: 0.0.0.0
+      portValue: 10080
+  defaultFilterChain:
+    filters:
+    - name: envoy.filters.network.http_connection_manager
+      typedConfig:
+        '@type': type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
+        commonHttpProtocolOptions:
+          headersWithUnderscoresAction: REJECT_REQUEST
+        http2ProtocolOptions:
+          initialConnectionWindowSize: 1048576
+          initialStreamWindowSize: 65536
+          maxConcurrentStreams: 100
+        httpFilters:
+        - name: envoy.filters.http.router
+          typedConfig:
+            '@type': type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
+            suppressEnvoyHeaders: true
+        mergeSlashes: true
+        normalizePath: true
+        pathWithEscapedSlashesAction: UNESCAPE_AND_REDIRECT
+        rds:
+          configSource:
+            ads: {}
+            resourceApiVersion: V3
+          routeConfigName: first-listener
+        serverHeaderTransformation: PASS_THROUGH
+        statPrefix: http-10080
+        tracing:
+          clientSampling:
+            value: 100
+          customTags:
+          - environment:
+              defaultValue: '-'
+              name: env1
+            tag: env1
+          - literal:
+              value: value1
+            tag: literal1
+          - requestHeader:
+              defaultValue: '-'
+              name: X-Request-Id
+            tag: req1
+          overallSampling:
+            value: 100
+          provider:
+            name: envoy.tracers.datadog
+            typedConfig:
+              '@type': type.googleapis.com/envoy.config.trace.v3.DatadogConfig
+              collectorCluster: tracing-0
+              serviceName: fake-name.fake-ns
+          randomSampling:
+            value: 90
+          spawnUpstreamSpan: true
+        useRemoteAddress: true
+    name: first-listener
+  name: first-listener
+  perConnectionBufferLimitBytes: 32768
diff --git a/internal/xds/translator/testdata/out/xds-ir/tracing-datadog.routes.yaml b/internal/xds/translator/testdata/out/xds-ir/tracing-datadog.routes.yaml
new file mode 100644
index 000000000..b214e8b05
--- /dev/null
+++ b/internal/xds/translator/testdata/out/xds-ir/tracing-datadog.routes.yaml
@@ -0,0 +1,12 @@
+- ignorePortInHostMatching: true
+  name: first-listener
+  virtualHosts:
+  - domains:
+    - '*'
+    name: first-listener/*
+    routes:
+    - directResponse:
+        status: 500
+      match:
+        prefix: /
+      name: direct-route
diff --git a/internal/xds/translator/translator_test.go b/internal/xds/translator/translator_test.go
index e939ffb2b..4d41b865a 100644
--- a/internal/xds/translator/translator_test.go
+++ b/internal/xds/translator/translator_test.go
@@ -106,7 +106,7 @@ func TestTranslateXds(t *testing.T) {
 			errMsg: "validation failed for xds resource",
 		},
 		"tracing-unknown-provider-type": {
-			errMsg: "unknown tracing provider type: Datadog",
+			errMsg: "unknown tracing provider type: AwesomeTelemetry",
 		},
 	}
 
diff --git a/site/content/en/latest/api/extension_types.md b/site/content/en/latest/api/extension_types.md
index 6aaec3519..193e69872 100644
--- a/site/content/en/latest/api/extension_types.md
+++ b/site/content/en/latest/api/extension_types.md
@@ -3922,6 +3922,7 @@ _Appears in:_
 | `OpenTelemetry` |  | 
 | `OpenTelemetry` |  | 
 | `Zipkin` |  | 
+| `Datadog` |  | 
 
 
 #### TriggerEnum
diff --git a/site/content/zh/latest/api/extension_types.md b/site/content/zh/latest/api/extension_types.md
index 6aaec3519..193e69872 100644
--- a/site/content/zh/latest/api/extension_types.md
+++ b/site/content/zh/latest/api/extension_types.md
@@ -3922,6 +3922,7 @@ _Appears in:_
 | `OpenTelemetry` |  | 
 | `OpenTelemetry` |  | 
 | `Zipkin` |  | 
+| `Datadog` |  | 
 
 
 #### TriggerEnum