Skip to content

Conversation

ArsalanAnwer0
Copy link

Fixes #8718

Problem

ReconcileResource does not add owner references to existing resources that were created without an owner. This occurs when NeedsUpdate() returns false (because data, labels, and annotations haven't changed), causing the update block which contains the owner reference logic to be skipped entirely.

Solution

Added a separate owner reference check that runs independently of NeedsUpdate(). This makes sure that owner references are added or updated on existing resources even when no other fields require updates.

Changes

  • Added owner reference validation before the NeedsUpdate block in ReconcileResource
  • Owner references are now properly set on resources that initially lacked them
  • Added test case Add owner reference to existing resource without owner when NeedsUpdate returns false to verify the fix

Testing

  • All existing tests pass (no regressions)
  • New test case specifically validates the bug scenario
  • Ran full reconciler package test suite successfully

This fix enables proper resource ownership management and garbage collection for resources created before owner references were implemented.

Fixes elastic#8718

ReconcileResource now checks and updates owner references independently
of the NeedsUpdate function. Previously, if a resource existed without
an owner reference and NeedsUpdate returned false (because data, labels,
and annotations were unchanged), the owner reference would never be added.

Changes:
Added owner reference check before the NeedsUpdate block in ReconcileResource
Owner references are now added to existing resources even when other fields don't require updates
Added test case to verify owner reference is added when NeedsUpdate returns false

The fix ensures proper resource ownership management and enables garbage collection for resources that were created before owner references were implemented.
@prodsecmachine
Copy link
Collaborator

prodsecmachine commented Oct 2, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

@botelastic botelastic bot added the triage label Oct 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ReconcileResource does not add owner of initially missing
2 participants