Skip to content

Commit

Permalink
opt: move gateway namespace mode to common helper (envoyproxy#2129)
Browse files Browse the repository at this point in the history
opt: codes

Signed-off-by: bitliu <bitliu@tencent.com>
  • Loading branch information
Xunzhuo authored Nov 10, 2023
1 parent 8acb1ee commit c85f0e4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
9 changes: 9 additions & 0 deletions api/v1alpha1/envoygateway_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ func (e *EnvoyGateway) GetEnvoyGatewayAdminAddress() string {
return ""
}

// NamespaceMode returns if uses namespace mode.
func (e *EnvoyGateway) NamespaceMode() bool {
return e.Provider != nil &&
e.Provider.Kubernetes != nil &&
e.Provider.Kubernetes.Watch != nil &&
e.Provider.Kubernetes.Watch.Type == KubernetesWatchModeTypeNamespaces &&
len(e.Provider.Kubernetes.Watch.Namespaces) > 0
}

// DefaultGateway returns a new Gateway with default configuration parameters.
func DefaultGateway() *Gateway {
return &Gateway{
Expand Down
9 changes: 1 addition & 8 deletions internal/provider/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/manager"

"github.com/envoyproxy/gateway/api/v1alpha1"
"github.com/envoyproxy/gateway/internal/envoygateway"
"github.com/envoyproxy/gateway/internal/envoygateway/config"
"github.com/envoyproxy/gateway/internal/message"
Expand All @@ -43,13 +42,7 @@ func New(cfg *rest.Config, svr *config.Server, resources *message.ProviderResour
}

// TODO: implement config validation on the watch mode config
namespacedMode :=
svr.EnvoyGateway.Provider != nil &&
svr.EnvoyGateway.Provider.Kubernetes != nil &&
(svr.EnvoyGateway.Provider.Kubernetes.Watch != nil) &&
(svr.EnvoyGateway.Provider.Kubernetes.Watch.Type == v1alpha1.KubernetesWatchModeTypeNamespaces) &&
(len(svr.EnvoyGateway.Provider.Kubernetes.Watch.Namespaces) > 0)
if namespacedMode {
if svr.EnvoyGateway.NamespaceMode() {
mgrOpts.Cache.DefaultNamespaces = make(map[string]cache.Config)
for _, watchNS := range svr.EnvoyGateway.Provider.Kubernetes.Watch.Namespaces {
mgrOpts.Cache.DefaultNamespaces[watchNS] = cache.Config{}
Expand Down

0 comments on commit c85f0e4

Please sign in to comment.