Skip to content

Add "OwnerType" Annotation for Non-GC'ed DependentResources #2585

Closed

Description

@coltmcnealy-lh

I have a reconciler that extends KubernetesCRUDNoGCDependentResource. The created dependent has the following annotations:

metadata:
  annotations:
    io.javaoperatorsdk/primary-name: my-thing
    io.javaoperatorsdk/primary-namespace: my-namespace

In my operator, I have several different CustomResourceDefinitions and reconcilers. Therefore, I can and do have multiple custom resources in the my-namespace namespace called my-thing.

In my own code, I need to determine the owner of these resources. I can solve that by putting labels/annotations on them myself (this is quite a bit of work). However, I imagine that this is likely a vulnerability to bugs.

Proposed Solution

Add another annotation to NoGC resources and use that for determining ownership:

metadata:
  annotations:
    io.javaoperatorsdk/primary-type: MyCustomResource

Activity

  1. metacosm commented on Nov 16, 2024

    @metacosm
    Collaborator

    I need to double check but isn't the type of the primary known when the annotations are used?

  2. metacosm commented on Nov 16, 2024

    @metacosm
    Collaborator

    Indeed, the owner type is not known. However, this will require deeper changes than simply adding the annotation because the mappers only return ResourceID instances, which, currently, only also record name and namespaces.

  3. csviri commented on Nov 16, 2024

    @csviri
    Collaborator

    @metacosm I'm pretty sure we don't need to extend resourceID, note that from v5 we do type checking for owner references, adding type annotation should do the trick, and have the secondary filter on the.

    Another option is just use labels/ label selectors, which is also more efficient.

    or rather both. But something like the primary type should be there fo sure - preferably a GroupVersionKind (GVK) as a value in some form.

  4. csviri commented on Nov 17, 2024

    @csviri
    Collaborator

    #2586

    added scretch how the impl could look like, will finalize it bit later. @coltmcnealy-lh should we backport it into 4.x or you are ok to wait for v5?

  5. coltmcnealy-lh commented on Nov 17, 2024

    @coltmcnealy-lh
    ContributorAuthor

    @csviri we have a workaround, which is just overriding a bunch of getSecondaryResources methods to use the KubernetesClient directly and filter based on labels that we manually put onto our dependents. We can wait until v5 (we do our best to stay up-to-date with the JOSDK). Just thought I'd report this in case someone else is affected.

    Thanks for the prompt response!

  6. coltmcnealy-lh commented on Jan 24, 2025

    @coltmcnealy-lh
    ContributorAuthor

    I see that #2606 was merged. Should this ticket be closed?

  7. metacosm commented on Jan 24, 2025

    @metacosm
    Collaborator

    Indeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions