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

CRUDKubernetesDependentResource#delete() Deletes Non-Children Resources #2349

Closed
coltmcnealy-lh opened this issue Apr 15, 2024 · 4 comments · Fixed by #2371
Closed

CRUDKubernetesDependentResource#delete() Deletes Non-Children Resources #2349

coltmcnealy-lh opened this issue Apr 15, 2024 · 4 comments · Fixed by #2371
Assignees
Milestone

Comments

@coltmcnealy-lh
Copy link
Contributor

Bug Report

I have a KafkaUserDR which is a CRUDKubernetesDependentResource<KafkaUser, LHCluster>. In my LHClusterReconciler#reconcile method, I call kafkaUserDR.delete(...).

KafkaUser is the class of the CRD that is created by the Dependent Resource, and LHCluster is the primary.

The name of the Primary resource (the LHCluster) is my-cluster. I had another CRD of a different type (LHKafkaUser), and that an instance of that CRD also named my-cluster.

The LHKafkaUser CRD creates as a dependent a KafkaUser and therefore put an ownerRef on the created KafkaUser. The ownerRef on that KafkaUser correctly reported the kind: LHKafkaUser.

However, in the LHCluster Reconciler, calling delete() on the kafkaUserDR incorrectly deleted that resource: it was owned by the LHKafkaUser and NOT by the LHCluster.

Potential Fix

I think the fix is that the CRUDKubernetesDependentResource#delete() method needs to check both the name and kind on the ownerRef of resources before deleting it. Right now, the behavior suggests that it is not checking the kind.

Environment

Using a KIND cluster. JOSDK version 4.4.x

@coltmcnealy-lh
Copy link
Contributor Author

One workaround for now is to just make sure to avoid naming clashes. But that's not exactly ideal, and when we ship our Operator as a product to our customers (which we are doing soon), we can't guarantee that they will follow such practices.

@csviri csviri self-assigned this Apr 15, 2024
@csviri
Copy link
Collaborator

csviri commented Apr 15, 2024

Hi, the issue is here, when mapping from owner references:

To solve this cross namespace, we need to add apiVersion+kind into the referencing with annotation (additional annotation probably). (AFAIK this is not handled in controller-runtime either)

Will schedule this just for v5 (if no objections), since it is already handling the primary type sort of, which could be enhanced and the reference type easily checked.

@csviri csviri added this to the 5.0 milestone Apr 15, 2024
@coltmcnealy-lh
Copy link
Contributor Author

Thanks for the update! Is there a ticket I can use to track the V5 progress?

Also, for now it looks like I can solve the issue by implementing SecondaryToPrimaryMapper in my Dependent Resources. Is that correct?

@csviri
Copy link
Collaborator

csviri commented Apr 15, 2024

Is there a ticket I can use to track the V5 progress?

There is a milestone:
https://github.com/operator-framework/java-operator-sdk/milestone/5

Also, for now it looks like I can solve the issue by implementing SecondaryToPrimaryMapper in my Dependent Resources. Is that correct?

yes, definitely, you can do that, that will fix it.

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 a pull request may close this issue.

2 participants