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

api.delete can return a status object #32

Closed
clux opened this issue May 28, 2019 · 5 comments
Closed

api.delete can return a status object #32

clux opened this issue May 28, 2019 · 5 comments
Labels
bug Something isn't working

Comments

@clux
Copy link
Member

clux commented May 28, 2019

We had assumed that delete could be modelled as:

pub fn delete(&self, name: &str, dp: &DeleteParams) -> Result<Object<P, U>>;

but turns out kube sends:

{"kind":"Status","apiVersion":"v1","metadata":{},"status":"Success","details":{"name":"baz","group":"clux.dev","kind":"foos","uid":"XXX"}}

on a successful delete.

See #28 for more details. Fix client.request to fix this.

Edit: same is true for delete_collection (when it's not backgrounded).

@clux clux added the bug Something isn't working label May 28, 2019
@clux
Copy link
Member Author

clux commented May 28, 2019

Tempted to use the either crate to make the return types:

pub fn delete(&self, name: &str, dp: &DeleteParams)
  -> Result<Either<Object<P, U>, Status>>;
pub fn delete_collection(&self, lp: &ListParams)
  -> Result<Either<ObjectList<Object<P, U>, Status>>;

clux added a commit that referenced this issue May 29, 2019
@clux clux closed this as completed in 518837b May 30, 2019
@Ploppz
Copy link

Ploppz commented Mar 20, 2020

Hey @clux , I was looking at the api of delete, and I wonder why does it actually return either a resource or a status? Based on the API docs of kubernetes (https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.17/#delete-cronjob-v1beta1-batch) it looks like it should only return a status and never the resource itself?

@clux
Copy link
Member Author

clux commented Mar 22, 2020

Yeah, kubernetes isn't that great at documenting this. See kubernetes/kubernetes#59501

At any rate, this resource itself does appear out of the api, and it's consistent across all resources. k8s-openapi even has a uniform DeleteResponse type that codifies this behaviour.

@Ploppz
Copy link

Ploppz commented Mar 22, 2020

Thanks! Do you know if it is the case that whenever a status is returned rather than the deleted object, there was an error?

@clux
Copy link
Member Author

clux commented Mar 22, 2020

No, that should not be true. Kube returns 4xx/5xx errors as Error so errors should not bubble up through Status in an Ok(Either::Right) but should come in as an Err(kube::Error::Api(ae)).

Generally, Ok(Left) (the object return) is "about to be deleted", and then you can poke o.status and often see stuff like:

reason: Some("InstanceDeletionPending"), status: "True", type_: "Terminating"

(that's from crd_api example).

If you get an Ok(Right), it's usually gone-gone. Don't think I've seen other types of responses 🤔

In the examples we have slept a bit to wait for k8s to catch up, but it's possible to call a watch on object explicitly if you need to wait for a delete to have occurred.

This stuff probably needs better documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants