Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: refactor byNamespaceSelectorEnabled #4513

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions internal/provider/kubernetes/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,6 @@ func newGatewayAPIController(mgr manager.Manager, cfg *config.Server, su Updater
}
}

byNamespaceSelector := cfg.EnvoyGateway.Provider != nil &&
cfg.EnvoyGateway.Provider.Kubernetes != nil &&
cfg.EnvoyGateway.Provider.Kubernetes.Watch != nil &&
cfg.EnvoyGateway.Provider.Kubernetes.Watch.Type == egv1a1.KubernetesWatchModeTypeNamespaceSelector &&
(cfg.EnvoyGateway.Provider.Kubernetes.Watch.NamespaceSelector.MatchLabels != nil ||
len(cfg.EnvoyGateway.Provider.Kubernetes.Watch.NamespaceSelector.MatchExpressions) > 0)

r := &gatewayAPIReconciler{
client: mgr.GetClient(),
log: cfg.Logger,
Expand All @@ -108,7 +101,7 @@ func newGatewayAPIController(mgr manager.Manager, cfg *config.Server, su Updater
extServerPolicies: extServerPoliciesGVKs,
}

if byNamespaceSelector {
if byNamespaceSelectorEnabled(cfg.EnvoyGateway) {
r.namespaceLabel = cfg.EnvoyGateway.Provider.Kubernetes.Watch.NamespaceSelector
}

Expand All @@ -131,6 +124,23 @@ func newGatewayAPIController(mgr manager.Manager, cfg *config.Server, su Updater
return nil
}

func byNamespaceSelectorEnabled(eg *egv1a1.EnvoyGateway) bool {
if eg.Provider == nil ||
eg.Provider.Kubernetes == nil ||
eg.Provider.Kubernetes.Watch == nil {
return false
}

watch := eg.Provider.Kubernetes.Watch
switch watch.Type {
case egv1a1.KubernetesWatchModeTypeNamespaceSelector:
// Make sure that the namespace selector has at least one label or expression is set.
return watch.NamespaceSelector.MatchLabels != nil || len(watch.NamespaceSelector.MatchExpressions) > 0
default:
return false
}
}

// Reconcile handles reconciling all resources in a single call. Any resource event should enqueue the
// same reconcile.Request containing the gateway controller name. This allows multiple resource updates to
// be handled by a single call to Reconcile. The reconcile.Request DOES NOT map to a specific resource.
Expand Down
Loading