Skip to content

feat: watch owned resources and user-provided TLS secrets for prompt reconciliation#142

Open
viniciusdc wants to merge 1 commit into
mainfrom
feat/owned-resource-watches
Open

feat: watch owned resources and user-provided TLS secrets for prompt reconciliation#142
viniciusdc wants to merge 1 commit into
mainfrom
feat/owned-resource-watches

Conversation

@viniciusdc

Copy link
Copy Markdown
Collaborator

Summary

PR 3 of the routing/SecurityPolicy consolidation (#139). The controller only watched NebariApp (via For) plus cert-manager Certificates, so drift in the resources it manages was only repaired on the periodic requeue (up to ~1 minute). This adds event-driven watches.

Owned resources (closes #30)

  • SetupWithManager now Owns HTTPRoute, SecurityPolicy, and Secret, so external edits or deletions of those trigger reconciliation immediately.
  • HTTPRoutes and SecurityPolicys already carry controller owner references; the OIDC client Secret did not. storeClientSecret now sets one via controllerutil.SetControllerReference (and adopts pre-existing secrets on the next sync by writing the owner reference on update too).
  • KeycloakProvider gains a Scheme field, wired from mgr.GetScheme() in main.go. A nil Scheme skips the owner reference, so existing provider tests that don't wire a scheme keep passing.
  • Scheme registration already covers all three types (gatewayapiv1.Install, egv1alpha1.AddToScheme, core), so no scheme changes were needed.

User-provided TLS secrets (closes #115)

  • Adds a filtered Watches on Secrets in the Gateway namespace (envoy-gateway-system), mapped back to any NebariApp referencing them via routing.tls.secretName. Creating or fixing a referenced secret now flips TLSReady promptly instead of on the periodic requeue.
  • The map function lists NebariApps from the controller cache, so the per-event cost is negligible. The namespace filter lives in the watch predicate; the OIDC client Secret in app namespaces is handled by Owns above, this watch is for the unowned, user-managed secret.

Test plan

  • go build ./..., go vet ./..., gofmt -l clean.
  • go test ./internal/controller/reconcilers/auth/... passes, including the new TestKeycloakProvider_StoreClientSecret_SetsOwnerReference.
  • go test -run TestSecretToNebariApp ./internal/controller/ passes (placed in a standalone test file so it runs without the envtest suite).
  • The internal/controller Ginkgo/envtest suite fails locally on a pre-existing scheme-registration gap (also fails on clean main; needs make test's CRD setup) — unrelated to this change.

Notes / follow-ups

…reconciliation

The controller only watched NebariApp (via For) plus cert-manager Certificates,
so drift in the resources it manages was only repaired on the periodic requeue
(up to a minute). Add event-driven watches.

Owned resources (#30):
- SetupWithManager now Owns HTTPRoute, SecurityPolicy, and Secret, so external
  edits or deletions of those trigger reconciliation immediately. HTTPRoutes and
  SecurityPolicies already carry controller owner references; the OIDC client
  Secret did not, so storeClientSecret now sets one (and adopts pre-existing
  secrets on the next sync). KeycloakProvider gains a Scheme field, wired from
  the manager in main.go, for SetControllerReference; a nil Scheme skips the
  owner reference so existing tests without a scheme still pass.

User-provided TLS secrets (#115):
- Add a filtered Watches on Secrets in the Gateway namespace mapped back to any
  NebariApp referencing them via routing.tls.secretName. Creating or fixing a
  referenced secret now flips TLSReady promptly instead of on the periodic
  requeue. The map function lists NebariApps from the controller cache, so the
  per-event cost is negligible.

Tests:
- TestSecretToNebariApp covers the map function (match, no spurious requeues).
- TestKeycloakProvider_StoreClientSecret_SetsOwnerReference asserts the secret
  is created with a controller owner reference to the NebariApp.

Closes #30
Closes #115
@github-actions

github-actions Bot commented Jun 6, 2026

Copy link
Copy Markdown

Docker Images Built

Images pushed to Quay.io for branch feat-owned-resource-watches:

Image Tag Platforms
Operator quay.io/nebari/nebari-operator:feat-owned-resource-watches linux/amd64 + linux/arm64

Test the operator:

kubectl apply -k https://github.com/nebari-dev/nebari-operator.git/config/default?ref=feat/owned-resource-watches
kubectl set image deployment/nebari-operator-controller-manager manager=quay.io/nebari/nebari-operator:feat-owned-resource-watches -n nebari-operator-system

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.

Watch user-provided TLS secrets to fast-track TLSReady transitions enhancement: Add watches on owned resources (HTTPRoute, SecurityPolicy, Secret)

2 participants