diff --git a/pkg/api/rest/resttest/resttest.go b/pkg/api/rest/resttest/resttest.go index 17e0a584220..f170ec7711d 100644 --- a/pkg/api/rest/resttest/resttest.go +++ b/pkg/api/rest/resttest/resttest.go @@ -673,7 +673,8 @@ func (t *Tester) testDeleteGracefulImmediate(obj runtime.Object, setFn SetFunc, t.Errorf("unexpected error, object should be deleted immediately: %v", err) } objectMeta = t.getObjectMetaOrFail(out) - if objectMeta.DeletionTimestamp == nil || objectMeta.DeletionGracePeriodSeconds == nil || *objectMeta.DeletionGracePeriodSeconds != 0 { + // the second delete shouldn't update the object, so the objectMeta.DeletionGracePeriodSeconds should eqaul to the value set in the first delete. + if objectMeta.DeletionTimestamp == nil || objectMeta.DeletionGracePeriodSeconds == nil || *objectMeta.DeletionGracePeriodSeconds != expectedGrace { t.Errorf("unexpected deleted meta: %#v", objectMeta) } } diff --git a/pkg/registry/generic/etcd/etcd.go b/pkg/registry/generic/etcd/etcd.go index a6532d9d42f..d83180dba39 100644 --- a/pkg/registry/generic/etcd/etcd.go +++ b/pkg/registry/generic/etcd/etcd.go @@ -387,7 +387,7 @@ func (e *Etcd) Delete(ctx api.Context, name string, options *api.DeleteOptions) if pendingGraceful { return e.finalizeDelete(obj, false) } - if graceful { + if graceful && *options.GracePeriodSeconds > 0 { out := e.NewFunc() lastGraceful := int64(0) err := e.Storage.GuaranteedUpdate( diff --git a/test/e2e/pods.go b/test/e2e/pods.go index ed432d2a0a4..7f87aac8763 100644 --- a/test/e2e/pods.go +++ b/test/e2e/pods.go @@ -343,8 +343,12 @@ var _ = Describe("Pods", func() { Fail("Timeout while waiting for pod creation") } + // We need to wait for the pod to be scheduled, otherwise the deletion + // will be carried out immediately rather than gracefully. + expectNoError(framework.WaitForPodRunning(pod.Name)) + By("deleting the pod gracefully") - if err := podClient.Delete(pod.Name, nil); err != nil { + if err := podClient.Delete(pod.Name, api.NewDeleteOptions(30)); err != nil { Failf("Failed to delete pod: %v", err) } @@ -352,7 +356,7 @@ var _ = Describe("Pods", func() { deleted := false timeout := false var lastPod *api.Pod - timer := time.After(podStartTimeout) + timer := time.After(30 * time.Second) for !deleted && !timeout { select { case event, _ := <-w.ResultChan():