Skip to content

Add dynamic namespace selection by label - #855

Closed
fourhu wants to merge 1 commit into
haproxytech:masterfrom
fourhu:feature/issue-853
Closed

fourhu wants to merge 1 commit into
haproxytech:masterfrom
fourhu:feature/issue-853

Conversation

@fourhu

@fourhu fourhu commented Sep 21, 2026

Copy link
Copy Markdown

Fixes #853.

Summary

Add --namespace-label-selector for clusters where namespace membership is controlled by labels instead of a fixed name list.

Matching namespaces are watched at startup. Labeling a namespace starts its watches without restarting the controller; removing or changing the label removes its resources from HAProxy configuration. Relabeling starts a fresh list/watch so changes made while the namespace was unselected are loaded.

--namespace-whitelist and --namespace-blacklist keep precedence. If either is configured, the selector is ignored with a warning. With the selector unset, the existing informer path is unchanged.

Implementation

  • Keep one informer session per selected namespace.
  • Assign each session a monotonically increasing epoch and reject events from retired sessions.
  • Admit a namespace to HAProxy configuration only after its initial informer events have been processed.
  • Handle label churn, namespace deletion and recreation, late CRD registration, TCP resources, and Gateway API references.
  • Document the flag, precedence rules, and informer cost.

Validation

The branch adds unit and sequential Kubernetes e2e coverage for startup selection, label and unlabel transitions, relabeling, stale sessions, namespace deletion and recreation, TCP CRs, late CRDs, whitelist and blacklist precedence, and Gateway AllowedRoutes behavior.

The same source tree passed GitHub Actions on Kubernetes v1.34.0, including the standard e2e job, the Gateway e2e job, build, linters, generated-file checks, formatting, and module checks:

https://github.com/fourhu/kubernetes-ingress/actions/runs/35522646678

Trade-off

The selector path creates informer factories per selected namespace. API traffic and goroutine count therefore grow with the number of matches. This option is intended for a bounded namespace set; leaving the flag unset keeps the current shared-informer behavior.

@fourhu
fourhu force-pushed the feature/issue-853 branch 2 times, most recently from fc421ae to 37fb20a Compare September 21, 2026 01:59
Introduce --namespace-label-selector with dynamic per-namespace watch sessions. Namespace label changes update the watched resource set without restarting the controller, while whitelist and blacklist configurations retain precedence.

Add stale-session protection, lifecycle handling, documentation, and unit and end-to-end coverage for Kubernetes and Gateway API resources.

Refs haproxytech#853.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proposal: dynamic namespace selection by label

1 participant