kubernetes-client / python

Official Python client library for kubernetes
http://kubernetes.io/
Apache License 2.0
6.76k stars 3.27k forks source link

Delete with empty name results in deletecollection #2291

Open jpbetz opened 2 weeks ago

jpbetz commented 2 weeks ago

What happened (please include outputs or screenshots):

According to https://github.com/kubernetes/kubernetes/issues/127746, if delete is called with an empty name, the client will not fail but instead call delete on the collection resource and delete the entire collection of resources.

What you expected to happen:

Delete either performs the delete of a single resource, or fails.

How to reproduce it (as minimally and precisely as possible):

Call delete, but provide an empty name.

cc @zhifei92

roycaihw commented 2 weeks ago

The delete method compose the request to something like api/v1/namespaces/{namespace}/pods/{name} and when name is empty, it becomes api/v1/namespaces/{namespace}/pods, which by Kubernetes definition will delete all resources in the namespace / cluster.

This was also reported in https://github.com/kubernetes-client/python/issues/2209

I think at this point it will be hard to change this behavior, because we don't know how many users may already depend on this behavior.

jpbetz commented 2 weeks ago

What would the client code from python look like to make this call? Is there already a separate deletecollection call?