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

kubectl delete should wait for resource to be deleted before returning #42594

Closed
1 of 4 tasks
nikhiljindal opened this issue Mar 6, 2017 · 27 comments
Closed
1 of 4 tasks
Labels
area/kubectl sig/cli Categorizes an issue or PR as relevant to SIG CLI.

Comments

@nikhiljindal
Copy link
Contributor

nikhiljindal commented Mar 6, 2017

As per #40714 (comment), kubectl delete should ensure that the resource is deleted before returning by default. We can also add a --wait-for-deletion flag that users can set if they dont want to wait.

Work items:

  • First send DELETE request to apiserver with the resource name. Server will return back resource UID as part of the response.
  • Then keep sending DELETE requests to apiserver with UID precondition until server returns 404 or 409 or we timeout.

cc @liggitt @smarterclayton @bgrant0607 @kubernetes/sig-cli-bugs

@smarterclayton
Copy link
Contributor

I'd probably want --wait - not sure what else I would be waiting on here.

StatusDetails should probably have a UID field, but there's a question of how much detail want to to put in there. I don't want to add UID, then come back later and have to add other fields like resourceVersion, deletionTimestamp, etc.

@bgrant0607 bgrant0607 added the sig/cli Categorizes an issue or PR as relevant to SIG CLI. label Mar 9, 2017
@jamiehannaford
Copy link
Contributor

Perhaps --wait could be an optional flag that turns on waiting, but by default it's not enabled? That will preserve the current UX for users who are used to the current state of things.

More of a semantic question: is there a specific reason to send DELETEs with a precondition, instead of repeated GET/HEADs? Not sure if the latter is possible since I haven't worked much with the apiserver, but that's how SDKs usually implement logic like this.

@nikhiljindal
Copy link
Contributor Author

nikhiljindal commented Mar 10, 2017

Perhaps --wait could be an optional flag that turns on waiting, but by default it's not enabled? That will preserve the current UX for users who are used to the current state of things.

The current state is that kubectl delete always waits (for ex: it waits for pods to be deleted when running kubectl delete rs or kubectl delete deployment). Namespace deletion and pod graceful deletion are exceptions.

More of a semantic question: is there a specific reason to send DELETEs with a precondition, instead of repeated GET/HEADs? Not sure if the latter is possible since I haven't worked much with the apiserver, but that's how SDKs usually implement logic like this.

It may only have access to run DELETE requests and hence wont be able to run GET.
More details: #40714 (comment)

@shiywang
Copy link
Contributor

/subscribe

k8s-github-robot pushed a commit that referenced this issue Apr 4, 2017
Automatic merge from submit-queue

Enable secrets in federation kubectl tests

Fixes #40568
Superseedes #40714

Updating kubectl tests to wait for deletion if WAIT_FOR_DELETION is set to true. WAIT_FOR_DELETION will be set to true only when the tests are being run for federation apiserver.
This change will not impact kube apiserver tests and still enable federation and kubernetes to share the same test code.
This is a workaround until #42594 is fixed.

cc @kubernetes/sig-federation-pr-reviews
cc @liggitt as he reviewed #40714
@nikhiljindal
Copy link
Contributor Author

StatusDetails should probably have a UID field, but there's a question of how much detail want to to put in there. I don't want to add UID, then come back later and have to add other fields like resourceVersion, deletionTimestamp, etc.

Sent #45600 to add UID. Happy to add other fields if required.

@nikhiljindal nikhiljindal self-assigned this May 10, 2017
k8s-github-robot pushed a commit that referenced this issue May 15, 2017
Automatic merge from submit-queue (batch tested with PRs 41331, 45591, 45600, 45176, 45658)

Updating generic registry to return UID of the deleted resource

Ref #42594

cc @kubernetes/sig-api-machinery-pr-reviews @smarterclayton 

```release-note
Updating apiserver to return UID of the deleted resource. Clients can use this UID to verify that the resource was deleted or waiting for finalizers.
```
@nikhiljindal
Copy link
Contributor Author

Sent #46471 which updates kubectl to wait for deletion by default and adds a --wait flag that users can set to disable the wait. PTAL

k8s-github-robot pushed a commit that referenced this issue Jul 8, 2017
Automatic merge from submit-queue

Deleting kubectl.ServiceReaper since there is no special service deletion logic

Ref #46471 #42594

ServiceReaper does not have any special deletion logic so we dont need it. The generic deletion logic should be enough.
By removing this reaper, service deletion also gets the new wait logic from #46471

cc @kubernetes/sig-cli-misc
perotinus pushed a commit to kubernetes-retired/cluster-registry that referenced this issue Sep 2, 2017
Automatic merge from submit-queue (batch tested with PRs 41331, 45591, 45600, 45176, 45658)

Updating generic registry to return UID of the deleted resource

Ref kubernetes/kubernetes#42594

cc @kubernetes/sig-api-machinery-pr-reviews @smarterclayton 

```release-note
Updating apiserver to return UID of the deleted resource. Clients can use this UID to verify that the resource was deleted or waiting for finalizers.
```
@luigi-riefolo
Copy link

any updates?

@Blasterdick
Copy link

@nikhiljindal could this be related ?

@nikhiljindal
Copy link
Contributor Author

@Blasterdick No this is not related. Jianhuiz pointed out the root cause for that in: #53566 (comment). Its a bug in federation deployment controller. Doesnt require any change to kubectl.

Unassigning since am not working actively on this anymore.

@nikhiljindal nikhiljindal removed their assignment Dec 1, 2017
@fejta-bot
Copy link

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

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Mar 1, 2018
@nilebox
Copy link

nilebox commented Mar 13, 2018

The current state is that kubectl delete always waits (for ex: it waits for pods to be deleted when running kubectl delete rs or kubectl delete deployment). Namespace deletion and pod graceful deletion are exceptions.

@nikhiljindal I disagree with this statement for a couple reasons:

  1. replicasets and deployments are exceptions, not vice versa, because this behavior is driven by reapers which are optional (so by default kubectl does not wait - for example, Secret, ConfigMap and CRDs don't have reapers)
  2. even for deployments the statement "kubectl delete always waits" is not 100% correct.

Example: I added a custom finalizer example.com/preventDeletion to deployment, and the behavior was the following:

  1. Created a deployment - all good:
❯ kubectl apply -f deploy.yaml
deployment "nginx-deployment" created

❯ kubectl get pod
NAME                                READY     STATUS    RESTARTS   AGE
nginx-deployment-6c54bd5869-m5tc9   1/1       Running   0          2s
nginx-deployment-6c54bd5869-t2pjl   1/1       Running   0          2s

❯ kubectl get deploy
NAME               DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   2         2         2            2           11s
  1. Deleted a deployment - pods are terminated, but deployment is still there despite the message deployment "nginx-deployment" deleted, and it will remain there until I manually remove the example.com/preventDeletion finalizer.
❯ kubectl delete deploy nginx-deployment
deployment "nginx-deployment" deleted

❯ kubectl get pod
NAME                                READY     STATUS        RESTARTS   AGE
nginx-deployment-6c54bd5869-m5tc9   0/1       Terminating   0          29s
nginx-deployment-6c54bd5869-t2pjl   0/1       Terminating   0          29s

❯ kubectl get deploy
NAME               DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   0         0         0            0           36s

e.g. 7 minutes later:

❯ kubectl get pod
No resources found.

❯ kubectl get deploy
NAME               DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   0         0         0            0           7m

@nilebox
Copy link

nilebox commented Mar 31, 2018

@nikhiljindal your PR #46471 (adding a -wait flag) has been automatically closed by bot a while ago due to inactivity. Do you have any plans on resurrecting it?

@nikhiljindal
Copy link
Contributor Author

No. Feel free to take over.

@janetkuo
Copy link
Member

janetkuo commented Apr 2, 2018

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Apr 2, 2018
@smarterclayton
Copy link
Contributor

This is driving me up the wall. I may get to this before too long.

@bgrant0607
Copy link
Member

cc @apelisse @pwittrock @mengqiy

@apelisse
Copy link
Member

apelisse commented Jun 2, 2018

is this fixed by #64034?

@nilebox
Copy link

nilebox commented Jun 2, 2018

Yes, it was fixed in #64034, followed by #59851, #63979 and #64375

@nekufa
Copy link

nekufa commented Sep 3, 2018

Guys, it's not a good idea to break current behaviour. By default delete command was not waiting until everything will be complete. I have a lot of scripts that drop a lot of resources. Now they are working for a very long time. Wait feature is good, but default behaviour change is upsetting

@roffe
Copy link

roffe commented Sep 13, 2018

@nekufa add -wait=false to your scripts kubectl command to get previous behaviour

@nekufa
Copy link

nekufa commented Sep 21, 2018

@roffe sure, i found how to achieve this, thank you.
My message was about breaking default behaviour.

@bronger
Copy link

bronger commented Jan 11, 2019

Why was this made default? I cannot find any rationale for this here. IMO, one should have very good reason to break current behaviour. Besides, while I agree that this is a good addition, there are still plenty of use cases for not waiting.

@dracan
Copy link

dracan commented Aug 17, 2019

Yikes - was wondering why delete seems to now hang. Now I know! IMO a bad choice for the default behaviour :(

@lukeschlather
Copy link

What is actually going on under the covers? It appears that the command immediately prints " deleted" and then hangs, but actually it is waiting. It seems like the messaging is incorrect. It should say "deleting" and if --wait is the default it should only print "deleted" when the object is actually deleted.

The way it works right now it seems like kubectl deletes things and then hangs for no reason, and it doesn't give any indication that a state change has actually happened when the command finally terminates. (However ctrl-c and inspecting with kubectl get shows what is going on.) It's also a little surprising that the whole operation is async and ctrl-c doesn't stop it.)

@lukeschlather
Copy link

I don't know if it could be more clear that it's async by saying "queued for deletion" or "scheduled for deletion." followed by saying "waiting for controller to report deletion" or something and finally "controller reports resource is deleted."

@lukeschlather
Copy link

I do think this is good default behavior it just needs better messaging.

zeeke added a commit to zeeke/metallb-operator that referenced this issue Feb 16, 2022
After deleting all the resources in the test namespace, check if some
DaemonSet is still in place. This check is useful because the k8s delete
APIs are asynchronous.

See kubernetes/kubernetes#42594 for more
detailed information.

Signed-off-by: Andrea Panattoni <[email protected]>
zeeke added a commit to zeeke/metallb-operator that referenced this issue Feb 16, 2022
After deleting all the resources in the test namespace, check if some
DaemonSet is still in place. This check is useful because the k8s delete
APIs are asynchronous.

See kubernetes/kubernetes#42594 for more
detailed information.

Signed-off-by: Andrea Panattoni <[email protected]>
akhilerm pushed a commit to akhilerm/apimachinery that referenced this issue Sep 20, 2022
Automatic merge from submit-queue (batch tested with PRs 41331, 45591, 45600, 45176, 45658)

Updating generic registry to return UID of the deleted resource

Ref kubernetes/kubernetes#42594

cc @kubernetes/sig-api-machinery-pr-reviews @smarterclayton 

```release-note
Updating apiserver to return UID of the deleted resource. Clients can use this UID to verify that the resource was deleted or waiting for finalizers.
```

Kubernetes-commit: a4307eb7a238cbda1cc1d6573336a1a7634b0db9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/kubectl sig/cli Categorizes an issue or PR as relevant to SIG CLI.
Projects
None yet
Development

No branches or pull requests