Skip to content

controller: dynamically detect new, updated, and deleted sealing key secrets - #2034

Merged
alvneiayu merged 1 commit into
bitnami:mainfrom
VedantMadane:fix-1819-detect-key-secret-updates
Sep 16, 2026
Merged

alvneiayu merged 1 commit into
bitnami:mainfrom
VedantMadane:fix-1819-detect-key-secret-updates

Conversation

@VedantMadane

Copy link
Copy Markdown
Contributor

Description

Fixes #1819.

When users manually create, update, or relabel sealing key secrets (e.g., secrets with \sealedsecrets.bitnami.com/sealed-secrets-key: active), the controller's key secrets informer (\watchKeySecrets) previously only had an \AddFunc\ handler.

This meant:

  1. Updated or newly labeled secrets were not detected without a pod restart.
  2. Deleted key secrets were not unregistered from \KeyRegistry.
  3. \HasSynced\ did not account for \kInformer.HasSynced().

  4. egistryNewKeyWithSecret\ logged errors on failed key reads but did not return immediately, leading to potential slice indexing panics on empty cert slices.

Changes

  • Added \UpdateFunc\ and \DeleteFunc\ event handlers to \watchKeySecrets\ to dynamically register, update, and unregister keys.
  • Added \unregisterKey\ to \KeyRegistry\ which safely deletes keys by fingerprint and recomputes \mostRecentKey.
  • Updated \Controller.HasSynced\ to check \c.kInformer.HasSynced()\ when \kInformer\ is present.
  • Added immediate error return in
    egistryNewKeyWithSecret\ on read failures.
  • Added comprehensive unit tests in \pkg/controller/controller_test.go\ and \pkg/controller/keyregistry_test.go.

Checklist

  • Signed-off with Developer Certificate of Origin (DCO)
  • Unit tests added and passing

alvneiayu
alvneiayu previously approved these changes Aug 27, 2026
@alvneiayu

Copy link
Copy Markdown
Collaborator

thanks a lot @VedantMadane for your contribution. Amazing catch.

@alvneiayu

Copy link
Copy Markdown
Collaborator

there are building problems 😅

@VedantMadane

Copy link
Copy Markdown
Contributor Author

Rebased on main and resolved merge conflicts / build issues with the latest client-go changes. All unit tests (go test ./...) are passing.

…secrets (bitnami#1819)

- Add UpdateFunc and DeleteFunc to watchKeySecrets event handler so the controller detects new, updated, or relabeled sealing keys without requiring a pod restart.
- Add unregisterKey to KeyRegistry to safely remove deleted keys and recompute mostRecentKey.
- Update HasSynced to include kInformer.
- Fix registryNewKeyWithSecret to return errors instead of proceeding on failed key reads.
- Add unit tests for dynamic key secret detection and key unregistration.

Signed-off-by: Vedant Madane <6527493+VedantMadane@users.noreply.github.com>
@VedantMadane
VedantMadane force-pushed the fix-1819-detect-key-secret-updates branch from 3967840 to ee413a5 Compare September 15, 2026 08:30
@alvneiayu
alvneiayu merged commit 9e35500 into bitnami:main Sep 16, 2026
37 of 43 checks passed
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.

pod restart required to detect a new/updated secret with label 'sealedsecrets.bitnami.com/sealed-secrets-key: active'

2 participants