Skip to content

Add dynamic namespace selection by label - #856

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 and precedence rules.

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, and whitelist/blacklist precedence.

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.

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, unit tests for Kubernetes and Gateway API resources, and end-to-end coverage for Ingress and TCP CR.

Refs haproxytech#853.
@fourhu

fourhu commented Sep 21, 2026

Copy link
Copy Markdown
Author

Superseded by a new PR with an accurate description of the current selector behavior.

@fourhu fourhu closed this Sep 21, 2026
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