Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix optional resource deletion for collector CR #3494

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

swiatekm
Copy link
Contributor

@swiatekm swiatekm commented Nov 25, 2024

Description:

I've refactored and cleaned up our owned resource tracking:

  • I've added a method that returns all the tracked resources for the reconciler. During registration, we loop over that list.
  • To be able to easily find the owned resources, I added an index with a custom field, similar to what the kubebuilder docs suggest. This makes test setup more annoying, as we need to make sure to use the caching client in controller tests, but makes the code much more robust.
  • We now track ownership of all namespaced resources instead of just a subset of them. This way we actually delete a target allocator Deployment if it's disabled in the collector CR.

Link to tracking Issue(s):

Testing:

  • Added a controller test for deleting optional resources.
  • Added a e2e test for this as well.
  • Added a controller test for versioned ConfigMaps.
  • I'd like to add more unit tests for the controller functions before merging.

gvk, err := apiutil.GVKForObject(l, cl.Scheme())
if err != nil {
return nil, err
}
list.SetGroupVersionKind(gvk)
err = cl.List(ctx, list, options...)
gvk.Kind = fmt.Sprintf("%sList", gvk.Kind)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This feels really stupid, but I couldn't find an idiomatic way to get a xxxList instance given an xxx instance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FYI, if I go back to the previous version using Unstructured, then the cache doesn't work even if I explicitly enable unstructured caching in the client. I think I'd need to change the indexer as well.

@swiatekm swiatekm force-pushed the fix/remove-optional-resources branch from 96d5c1b to 8bc20d1 Compare November 25, 2024 15:51
@swiatekm swiatekm force-pushed the fix/remove-optional-resources branch from 8bc20d1 to 7b43d08 Compare November 30, 2024 17:54
@swiatekm swiatekm marked this pull request as ready for review November 30, 2024 18:36
@swiatekm swiatekm requested a review from a team as a code owner November 30, 2024 18:36
@swiatekm swiatekm force-pushed the fix/remove-optional-resources branch from 7b43d08 to 53fb524 Compare November 30, 2024 18:36
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.

Operator doesn't delete components when removed from configuration
2 participants