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

Provide generic API to update metadata.ownerReferences field #2095

Closed
rombert opened this issue Mar 27, 2020 · 6 comments
Closed

Provide generic API to update metadata.ownerReferences field #2095

rombert opened this issue Mar 27, 2020 · 6 comments
Labels
status/stale Waiting on feedback Issues that require feedback from User/Other community members

Comments

@rombert
Copy link
Contributor

rombert commented Mar 27, 2020

I am creating a kubernetes job and some associated resources ( secrets, network policies ). The job is auto-deleted using the .spec.ttlSecondsAfterFinished field.

Since kubernetes can not clean up the associated resources automatically, I am trying to update the .metadata.ownerReferences field after creating all resources and the job.

The code is essentially

            Job owner = r.getValue().getOwner();
            OwnerReference ref = new OwnerReference(owner.getApiVersion(), false, true, owner.getKind(), owner.getMetadata().getNamespace(), owner.getMetadata().getUid());
            logger.debug("Adding {} as owner reference for created resources", ref);
            r.getValue().getOwned()
                .forEach( owned -> {
                    logger.debug("{} has owner references {}, adding new one", owned, owned.getMetadata().getOwnerReferences());
                    owned.getMetadata().getOwnerReferences().add(ref);
                    client.resource(owned).createOrReplace();
                    logger.debug("Updated owner references for {}", owned);
                });

However, the owned resources are not updated when calling createOrReplace. The reason seems to be

DEBUG i.f.k.c.d.i.NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableImpl - Item has not changed. Skipping

This calls

, which performs a comparison ignoring the status and metadata fields.

Since my change is metadata-only, it is not applied.


As an update, I became aware of the option of using edit().editMetadata() on various resources. The problem here is that there is no generic way of doing it for all resource types, so I have to special-case every resource type that I manage. A generic API would be very much appreciated.

@rombert rombert changed the title Unable to update metadata.ownerReferences field Provide generic API to update metadata.ownerReferences field Mar 27, 2020
@stale
Copy link

stale bot commented Jun 26, 2020

This issue has been automatically marked as stale because it has not had any activity since 90 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions!

@stale stale bot added the status/stale label Jun 26, 2020
@rombert
Copy link
Contributor Author

rombert commented Jun 26, 2020

Well @Stale, I'm still interested. Mind keeping this open?

@stale stale bot removed the status/stale label Jun 26, 2020
@rohanKanojia
Copy link
Member

We have been considering refactoring the behavior of createOrReplace #2292 . I think that would take care of this issue

@stale
Copy link

stale bot commented Sep 27, 2020

This issue has been automatically marked as stale because it has not had any activity since 90 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions!

@stale stale bot added the status/stale label Sep 27, 2020
@manusa
Copy link
Member

manusa commented Sep 28, 2020

createOrReplace methods have been refactored (#2292 - #2372), so this issue should have been fixed.
Please @rombert, could you confirm if your procedure works with the latest release (4.11.1)?

There is a parallel issue (#2454) with an ongoing discussion for createOrReplace behavior. The behavior described in the first comment is related and would stop working again with some of the approaches.

@stale stale bot removed the status/stale label Sep 28, 2020
@manusa manusa added the Waiting on feedback Issues that require feedback from User/Other community members label Sep 28, 2020
@stale
Copy link

stale bot commented Dec 29, 2020

This issue has been automatically marked as stale because it has not had any activity since 90 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions!

@stale stale bot added the status/stale label Dec 29, 2020
@stale stale bot closed this as completed Jan 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/stale Waiting on feedback Issues that require feedback from User/Other community members
Projects
None yet
Development

No branches or pull requests

3 participants