Skip to content

Conversation

andser91
Copy link

@andser91 andser91 commented May 28, 2025

Pull Request Template

Description

This PR fixes an issue where deleting a custom resource (e.g., KeycloakClient, KeycloakGroup, etc.) that references a KeycloakRealm CR which has already been deleted results in a permanent reconciliation failure.

Currently, when a child resource is deleted, the controller tries to instantiate a Keycloak client by fetching the corresponding KeycloakRealm CR. If the realm CR has already been deleted, the controller throws a NotFound error, and the resource remains stuck in a terminating state because the finalizer is never removed.

This patch ensures that if the referenced realm no longer exists, the finalizer is still properly removed, allowing the resource to be garbage collected.

Fixes #173

Type of change

  • [✓ ] Enhancement (non-breaking change which improves an existing feature or documentation)

How Has This Been Tested?

  • Deployed the operator in a development environment with CAPI-generated clusters and Keycloak running.
  • Created a KeycloakRealm and a related KeycloakClient.
  • Deleted the KeycloakRealm before the KeycloakClient.
  • Verified that the KeycloakClient finalizer was correctly removed, and the resource was deleted without manual intervention.
  • Added test case in keycloakclient_controller_integration_test

Checklist:

  • [✓] I have performed a self-review of my code
  • [✓] I have commented on my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • [✓] My changes generate no new warnings
  • [✓] I have added tests that prove my fix is effective or that my feature works
  • [✓] New and existing unit tests pass locally with my changes
  • [✓] Pull Request contains one commit. I squash my commits.

@andser91 andser91 requested review from zmotso and a team as code owners May 28, 2025 16:41
Copy link
Member

@zmotso zmotso left a comment

Choose a reason for hiding this comment

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

@andser91 Thank you for your contribution.
Your change can improve cleaning resources.
Please fix the comments.
Change commit message to: feat: Allow finalizer cleanup when realm is already deleted (#173)
Make sure you run make lint.

@andser91 andser91 changed the title feat(): allow finalizer cleanup when realm is already deleted feat: Allow finalizer cleanup when realm is already deleted May 30, 2025
@zmotso
Copy link
Member

zmotso commented Jun 2, 2025

@SergK @MykolaMarusenko Looks good, let's merge this PR.

Copy link
Member

@SergK SergK left a comment

Choose a reason for hiding this comment

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

@andser91 Thank you

@SergK SergK merged commit 12f90e2 into epam:master Jun 2, 2025
11 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.

Dangling CRs when corresponding realm is gone
3 participants