Skip to content

Commit

Permalink
refactor: update watch ns api & add tests (#2367)
Browse files Browse the repository at this point in the history
* refactor: update watch ns api & add tests

Signed-off-by: qicz <[email protected]>

* fix gen

Signed-off-by: qicz <[email protected]>

---------

Signed-off-by: qicz <[email protected]>
  • Loading branch information
qicz authored Dec 27, 2023
1 parent 5833fe4 commit 690e469
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 6 deletions.
6 changes: 3 additions & 3 deletions api/v1alpha1/envoygateway_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 49 additions & 0 deletions internal/envoygateway/config/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions site/content/en/latest/api/extension_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -1134,9 +1134,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
Expand Down

0 comments on commit 690e469

Please sign in to comment.