Skip to content

feat: add rh-keycloak wrapper chart with PostSync cleanup for one-shot ExternalSecrets#137

Open
minmzzhang wants to merge 4 commits into
validatedpatterns:mainfrom
minmzzhang:one-shot-keycloak-users
Open

feat: add rh-keycloak wrapper chart with PostSync cleanup for one-shot ExternalSecrets#137
minmzzhang wants to merge 4 commits into
validatedpatterns:mainfrom
minmzzhang:one-shot-keycloak-users

Conversation

@minmzzhang
Copy link
Copy Markdown
Collaborator

@minmzzhang minmzzhang commented May 21, 2026

Summary

  • Add a wrapper chart (charts/rh-keycloak) that consumes the rhbk chart as a dependency and adds a PostSync cleanup job for one-shot ExternalSecret provisioning
  • Switch values-hub.yaml from the remote rhbk chart to the local rh-keycloak wrapper chart path
  • Update commented-out overrides with rhbk. prefix to match the wrapper chart structure

How it works

When externalSecrets.oneShot is enabled (set by the wrapper chart), the keycloak-users ExternalSecret uses BeforeHookCreation and sets deletionPolicy: Retain. The PostSync job then:

  1. Waits for labeled ExternalSecrets to reach Ready
  2. Deletes them with --cascade=orphan (Secrets survive because Kubernetes GC is told to orphan dependents)
  3. Cleans up ephemeral Secrets labeled ztvp.io/cleanup=delete (the keycloak-users Secret)

This prevents ESO from continuously overwriting the keycloak-users Secret after Keycloak has consumed it during realm import.

Dependencies

  • Depends on rhbk-chart PR #15 — the wrapper chart requires rhbk >= 0.0.10 with externalSecrets.oneShot support. That PR must be merged and published before this one can be deployed.

@minmzzhang minmzzhang requested review from mlorenzofr, p-rog and sabre1041 and removed request for sabre1041 May 21, 2026 22:09
Copy link
Copy Markdown
Collaborator

@mlorenzofr mlorenzofr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to rebase after merge #135

  1. Add extraValueFiles... to values-hub.yaml
  2. Add rhbk: to the beginning of overrides/values-keycloak-network-policy.yaml and fix the indentation

Apart from that, everything else has worked correctly

Add a wrapper chart (charts/rh-keycloak) that consumes the rhbk
chart as a dependency and adds a PostSync cleanup job for
one-shot ExternalSecret provisioning.

The PostSync job:
1. Waits for labeled ExternalSecrets to sync
2. Deletes them with --cascade=orphan (Secrets survive)
3. Cleans up ephemeral Secrets labeled for deletion (keycloak-users)

Switch values-hub.yaml from the remote rhbk chart to the local
rh-keycloak wrapper chart path. Requires rhbk-chart >= 0.0.9
with externalSecrets.oneShot support. Commented-out overrides
updated with rhbk. prefix to match the wrapper chart structure.

Signed-off-by: Min Zhang <minzhang@redhat.com>
@minmzzhang minmzzhang force-pushed the one-shot-keycloak-users branch from 64360bb to 2d728b4 Compare May 25, 2026 18:35
@minmzzhang
Copy link
Copy Markdown
Collaborator Author

We need to rebase after merge #135

  1. Add extraValueFiles... to values-hub.yaml
  2. Add rhbk: to the beginning of overrides/values-keycloak-network-policy.yaml and fix the indentation

Apart from that, everything else has worked correctly

rebased the latest main and force pushed.

Bump rhbk dependency to >=0.0.10 which carries the renamed label.

Signed-off-by: Min Zhang <minzhang@redhat.com>
@mlorenzofr
Copy link
Copy Markdown
Collaborator

Depends on validatedpatterns/rhbk-chart#15

ArgoCD's HookSucceeded policy already removes the ExternalSecret, so the
PostSync Job no longer needs ExternalSecret RBAC or the one-shot label
lookup.

Signed-off-by: Min Zhang <minzhang@redhat.com>
When default-deny NetworkPolicies are enabled in keycloak-system, the
cleanup Job cannot reach the API server. Add a PostSync NetworkPolicy
allowing DNS and port 6443 egress, and label the Job pod so it matches.

Signed-off-by: Min Zhang <minzhang@redhat.com>
Copy link
Copy Markdown
Collaborator

@mlorenzofr mlorenzofr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and everything is fine

Once we have the merged validatedpatterns/rhbk-chart#15, we could also merge this PR

LGTM

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.

2 participants