From 0bc3f7ecd8a27d5297fce879eb906e7a1ffe2104 Mon Sep 17 00:00:00 2001 From: qicz Date: Wed, 27 Dec 2023 17:36:54 +0800 Subject: [PATCH 1/2] refactor: update watch ns api & add tests Signed-off-by: qicz --- api/v1alpha1/envoygateway_types.go | 6 +-- internal/envoygateway/config/decoder_test.go | 49 +++++++++++++++++++ .../testdata/decoder/in/gateway-ns-watch.yaml | 12 +++++ .../decoder/in/gateway-nsselector-watch.yaml | 11 +++++ 4 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 internal/envoygateway/config/testdata/decoder/in/gateway-ns-watch.yaml create mode 100644 internal/envoygateway/config/testdata/decoder/in/gateway-nsselector-watch.yaml diff --git a/api/v1alpha1/envoygateway_types.go b/api/v1alpha1/envoygateway_types.go index d479d3f7f9e..66abfdec9c8 100644 --- a/api/v1alpha1/envoygateway_types.go +++ b/api/v1alpha1/envoygateway_types.go @@ -214,19 +214,19 @@ type KubernetesWatchMode struct { // KubernetesWatchModeTypeNamespaceSelectors are currently supported // By default, when this field is unset or empty, Envoy Gateway will watch for input namespaced resources // from all namespaces. - Type KubernetesWatchModeType + Type KubernetesWatchModeType `json:"type,omitempty"` // Namespaces holds the list of namespaces that Envoy Gateway will watch for namespaced scoped // resources such as Gateway, HTTPRoute and Service. // Note that Envoy Gateway will continue to reconcile relevant cluster scoped resources such as // GatewayClass that it is linked to. Precisely one of Namespaces and NamespaceSelectors must be set - Namespaces []string + Namespaces []string `json:"namespaces,omitempty"` // NamespaceSelectors holds a list of labels that namespaces have to have in order to be watched. // Note this doesn't set the informer to watch the namespaces with the given labels. Informer still // watches all namespaces. But the events for objects whois namespce have no given labels // will be filtered out. Precisely one of Namespaces and NamespaceSelectors must be set - NamespaceSelectors []string `json:"namespaces,omitempty"` + NamespaceSelectors []string `json:"namespaceSelectors,omitempty"` } // KubernetesDeployMode holds configuration for how to deploy managed resources such as the Envoy Proxy diff --git a/internal/envoygateway/config/decoder_test.go b/internal/envoygateway/config/decoder_test.go index ebd1bf145e6..80fdc461ff8 100644 --- a/internal/envoygateway/config/decoder_test.go +++ b/internal/envoygateway/config/decoder_test.go @@ -234,6 +234,55 @@ func TestDecode(t *testing.T) { }, expect: true, }, + { + in: inPath + "gateway-ns-watch.yaml", + out: &v1alpha1.EnvoyGateway{ + TypeMeta: metav1.TypeMeta{ + Kind: v1alpha1.KindEnvoyGateway, + APIVersion: v1alpha1.GroupVersion.String(), + }, + EnvoyGatewaySpec: v1alpha1.EnvoyGatewaySpec{ + Provider: &v1alpha1.EnvoyGatewayProvider{ + Type: v1alpha1.ProviderTypeKubernetes, + Kubernetes: &v1alpha1.EnvoyGatewayKubernetesProvider{ + Watch: &v1alpha1.KubernetesWatchMode{ + Type: v1alpha1.KubernetesWatchModeTypeNamespaces, + Namespaces: []string{ + "ns-a", + "ns-b", + }, + }, + }, + }, + Gateway: v1alpha1.DefaultGateway(), + }, + }, + expect: true, + }, + { + in: inPath + "gateway-nsselector-watch.yaml", + out: &v1alpha1.EnvoyGateway{ + TypeMeta: metav1.TypeMeta{ + Kind: v1alpha1.KindEnvoyGateway, + APIVersion: v1alpha1.GroupVersion.String(), + }, + EnvoyGatewaySpec: v1alpha1.EnvoyGatewaySpec{ + Provider: &v1alpha1.EnvoyGatewayProvider{ + Type: v1alpha1.ProviderTypeKubernetes, + Kubernetes: &v1alpha1.EnvoyGatewayKubernetesProvider{ + Watch: &v1alpha1.KubernetesWatchMode{ + Type: v1alpha1.KubernetesWatchModeTypeNamespaceSelectors, + NamespaceSelectors: []string{ + "label-a", + }, + }, + }, + }, + Gateway: v1alpha1.DefaultGateway(), + }, + }, + expect: true, + }, { in: inPath + "invalid-gateway-logging.yaml", expect: false, diff --git a/internal/envoygateway/config/testdata/decoder/in/gateway-ns-watch.yaml b/internal/envoygateway/config/testdata/decoder/in/gateway-ns-watch.yaml new file mode 100644 index 00000000000..44c995fc64d --- /dev/null +++ b/internal/envoygateway/config/testdata/decoder/in/gateway-ns-watch.yaml @@ -0,0 +1,12 @@ +apiVersion: gateway.envoyproxy.io/v1alpha1 +kind: EnvoyGateway +gateway: + controllerName: gateway.envoyproxy.io/gatewayclass-controller +provider: + type: Kubernetes + kubernetes: + watch: + type: Namespaces + namespaces: + - ns-a + - ns-b diff --git a/internal/envoygateway/config/testdata/decoder/in/gateway-nsselector-watch.yaml b/internal/envoygateway/config/testdata/decoder/in/gateway-nsselector-watch.yaml new file mode 100644 index 00000000000..4bc7369f6ae --- /dev/null +++ b/internal/envoygateway/config/testdata/decoder/in/gateway-nsselector-watch.yaml @@ -0,0 +1,11 @@ +apiVersion: gateway.envoyproxy.io/v1alpha1 +kind: EnvoyGateway +gateway: + controllerName: gateway.envoyproxy.io/gatewayclass-controller +provider: + type: Kubernetes + kubernetes: + watch: + type: NamespaceSelectors + namespaceSelectors: + - label-a From 421f454e1c9aa38033b9bf4b9ade47d1d445b3b9 Mon Sep 17 00:00:00 2001 From: qicz Date: Wed, 27 Dec 2023 17:48:40 +0800 Subject: [PATCH 2/2] fix gen Signed-off-by: qicz --- site/content/en/latest/api/extension_types.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/site/content/en/latest/api/extension_types.md b/site/content/en/latest/api/extension_types.md index 5a8b4aaf753..60bdef40583 100644 --- a/site/content/en/latest/api/extension_types.md +++ b/site/content/en/latest/api/extension_types.md @@ -1122,9 +1122,9 @@ _Appears in:_ | Field | Description | | --- | --- | -| `Type` _[KubernetesWatchModeType](#kuberneteswatchmodetype)_ | Type indicates what watch mode to use. KubernetesWatchModeTypeNamespaces and KubernetesWatchModeTypeNamespaceSelectors are currently supported By default, when this field is unset or empty, Envoy Gateway will watch for input namespaced resources from all namespaces. | -| `Namespaces` _string array_ | Namespaces holds the list of namespaces that Envoy Gateway will watch for namespaced scoped resources such as Gateway, HTTPRoute and Service. Note that Envoy Gateway will continue to reconcile relevant cluster scoped resources such as GatewayClass that it is linked to. Precisely one of Namespaces and NamespaceSelectors must be set | -| `namespaces` _string array_ | NamespaceSelectors holds a list of labels that namespaces have to have in order to be watched. Note this doesn't set the informer to watch the namespaces with the given labels. Informer still watches all namespaces. But the events for objects whois namespce have no given labels will be filtered out. Precisely one of Namespaces and NamespaceSelectors must be set | +| `type` _[KubernetesWatchModeType](#kuberneteswatchmodetype)_ | Type indicates what watch mode to use. KubernetesWatchModeTypeNamespaces and KubernetesWatchModeTypeNamespaceSelectors are currently supported By default, when this field is unset or empty, Envoy Gateway will watch for input namespaced resources from all namespaces. | +| `namespaces` _string array_ | Namespaces holds the list of namespaces that Envoy Gateway will watch for namespaced scoped resources such as Gateway, HTTPRoute and Service. Note that Envoy Gateway will continue to reconcile relevant cluster scoped resources such as GatewayClass that it is linked to. Precisely one of Namespaces and NamespaceSelectors must be set | +| `namespaceSelectors` _string array_ | NamespaceSelectors holds a list of labels that namespaces have to have in order to be watched. Note this doesn't set the informer to watch the namespaces with the given labels. Informer still watches all namespaces. But the events for objects whois namespce have no given labels will be filtered out. Precisely one of Namespaces and NamespaceSelectors must be set | #### KubernetesWatchModeType