controller-runtime icon indicating copy to clipboard operation
controller-runtime copied to clipboard

Support for CRUD sub resources in the Client

Open shawn-hurley opened this issue 7 years ago • 40 comments

Currently, I do not see a way to use subresources from the client.

I suggest that we add a variadic argument for subresources. example: https://github.com/kubernetes/client-go/blob/master/dynamic/interface.go#L32

Or we may need to add the subresources to the Options for functions that already have a variadic?

shawn-hurley avatar Oct 11 '18 12:10 shawn-hurley

There is limited support for the status subresource via https://github.com/kubernetes-sigs/controller-runtime/blob/master/pkg/client/client.go#L143

coderanger avatar Oct 11 '18 18:10 coderanger

I have a similar use case here that needs to evict pods instead of simply deleting them, using the eviction subresource of Pod.

liyinan926 avatar Oct 24 '18 17:10 liyinan926

/kind feature

We had some initial ideas for how to design this, but I think the interface needs potential a bit more work. For instance, should we do client.Subresource("name").Update(obj)? Can we discover name from the object? (maybe?). Thoughts and usecases always welcome :-)

DirectXMan12 avatar Oct 25 '18 00:10 DirectXMan12

So your thinking that we have a subresoureces Client, that has an interface containing Create, Update, Delete and Get that look exactly the same as the current interface?

I don't understand how we could determine the subresources for the object, could you explain what you had in mind would love to look into this.

I am assuming that we would want to keep the StatusWriter because it is so common that the helper makes sense?

shawn-hurley avatar Oct 25 '18 01:10 shawn-hurley

Depending on the subresource, we could use a RESTMapper to convert a Kind to the corresponding subresource entry in discovery, IIRC, but I haven't confirmed that -- it's just an initial thought off the top of my head. This doesn't work with subresources like status, though (even though we deal with status separately). I'd be curious to see what seemed more readable or ergonomic.

DirectXMan12 avatar Nov 02 '18 20:11 DirectXMan12

Issues go stale after 90d of inactivity. Mark the issue as fresh with /remove-lifecycle stale. Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle stale

fejta-bot avatar Apr 26 '19 17:04 fejta-bot

Is this issue looking for help? I have a need for doing the client supporting subresources such as get pods/log

jay-rob avatar May 15 '19 13:05 jay-rob

yeah. In general, anything in CR that doesn't have someone working on it is open for help -- I tend to apply the help-wanted tag a bit less in cases where the design might be a bit thorny or that might require serious apimachinery spelunking, but if you're up for some back and forth on design, I'm happy to have someone working on it :-)

DirectXMan12 avatar Jun 04 '19 00:06 DirectXMan12

Stale issues rot after 30d of inactivity. Mark the issue as fresh with /remove-lifecycle rotten. Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle rotten

fejta-bot avatar Jul 04 '19 01:07 fejta-bot

/remove-lifecycle rotten /lifecycle frozen

DirectXMan12 avatar Jul 25 '19 21:07 DirectXMan12

+1 to this. Is there a quick way to document that this isn't supported, or return a 5xx when one tries to do so against envtest? Kubebuilder (which uses envtest) suggests users update status via err = r.Status().Update(context.Background(), instance). My controller was failing a new test I wrote because the Update was returning 404, which was really perplexing.

cadedaniel avatar Aug 29 '19 23:08 cadedaniel

@cadedaniel I believe that the status subresource should work. If you're getting a 404 return code I would double-check if your CRD has enabled the Status subresource.

shawn-hurley avatar Aug 30 '19 12:08 shawn-hurley

namely, if you're getting 404, make sure that you've done // +kubebuilder:subresource:status on the type definition for your CRD, so you get a CRD with the status subresource enabled.

DirectXMan12 avatar Sep 03 '19 15:09 DirectXMan12

Yes, I must have missed this. Thanks, ignore my earlier comment please.

cadedaniel avatar Sep 03 '19 23:09 cadedaniel

/help

DirectXMan12 avatar Dec 09 '19 21:12 DirectXMan12

@DirectXMan12: This request has been marked as needing help from a contributor.

Please ensure the request meets the requirements listed here.

If this request no longer meets these requirements, the label can be removed by commenting with the /remove-help command.

In response to this:

/help

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

k8s-ci-robot avatar Dec 09 '19 21:12 k8s-ci-robot

/kind design

vincepri avatar Feb 20 '20 18:02 vincepri

Status is working, are there any plans to include Scale subresource as well? I'd like to control it from the client the same way it could be done via client-go.

zroubalik avatar Mar 24 '20 09:03 zroubalik

Issues go stale after 90d of inactivity. Mark the issue as fresh with /remove-lifecycle stale. Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle stale

fejta-bot avatar Jun 22 '20 09:06 fejta-bot

/remove-lifecycle stale Any updates on this? If there is a plan for how this should be implemented or we can agree on a design, I might be able to help with the implementation :)

timebertt avatar Jun 22 '20 10:06 timebertt

@tim-ebert We're waiting for a design proposal, see under designs/ for a template and examples

vincepri avatar Jun 22 '20 14:06 vincepri

heads up for anyone deciding to tackle this, versioning gets weird with scale: https://github.com/kubernetes/client-go/blob/36233866f1c7c0ad3bdac1fc466cb5de3746cfa2/scale/client.go#L182-L201

alexeldeib avatar Jul 29 '20 17:07 alexeldeib

Issues go stale after 90d of inactivity. Mark the issue as fresh with /remove-lifecycle stale. Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle stale

fejta-bot avatar Oct 27 '20 17:10 fejta-bot

/remove-lifecycle stale

timebertt avatar Oct 28 '20 11:10 timebertt

Is this issue looking for help? I have a need for doing the client supporting subresources such as get pods/log

Those are not CRUD subresources, see https://github.com/kubernetes-sigs/controller-runtime/issues/452 for that

@DirectXMan12 What is the concern with adding a simple ForSubresource(name string) Create/Patch option for this? Seems pretty straightforward and doesn't require any external API changes I think. It obviously allows for misuse if ppl use it for non-existing subresources but I think that should be ok if we add a warning to it?

alvaroaleman avatar Dec 23 '20 18:12 alvaroaleman

Issues go stale after 90d of inactivity. Mark the issue as fresh with /remove-lifecycle stale. Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale

fejta-bot avatar Mar 23 '21 19:03 fejta-bot

/remove-lifecycle stale

zroubalik avatar Mar 24 '21 08:03 zroubalik

Issues go stale after 90d of inactivity. Mark the issue as fresh with /remove-lifecycle stale. Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale

fejta-bot avatar Jun 22 '21 09:06 fejta-bot

/remove-lifecycle stale.

zroubalik avatar Jun 23 '21 09:06 zroubalik

Stale issues rot after 30d of inactivity. Mark the issue as fresh with /remove-lifecycle rotten. Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-contributor-experience at kubernetes/community. /lifecycle rotten

fejta-bot avatar Jul 23 '21 10:07 fejta-bot