mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 23:15:14 +00:00
wait for the deletionTimestamp set instead of waiting for the final deletion
This commit is contained in:
parent
d6ae61c3c9
commit
130437b94e
@ -120,9 +120,31 @@ func observeObjectDeletion(w watch.Interface) (obj runtime.Object) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func observerUpdate(w watch.Interface, expectedUpdate func(runtime.Object) bool) {
|
||||||
|
timer := time.After(30 * time.Second)
|
||||||
|
updated := false
|
||||||
|
timeout := false
|
||||||
|
for !updated && !timeout {
|
||||||
|
select {
|
||||||
|
case event, _ := <-w.ResultChan():
|
||||||
|
if event.Type == watch.Modified {
|
||||||
|
if expectedUpdate(event.Object) {
|
||||||
|
updated = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case <-timer:
|
||||||
|
timeout = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !updated {
|
||||||
|
framework.Failf("Failed to observe pod update")
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var _ = framework.KubeDescribe("Generated release_1_5 clientset", func() {
|
var _ = framework.KubeDescribe("Generated release_1_5 clientset", func() {
|
||||||
f := framework.NewDefaultFramework("clientset")
|
f := framework.NewDefaultFramework("clientset")
|
||||||
It("should create pods, delete pods, watch pods", func() {
|
It("should create pods, set the deletionTimestamp and deletionGracePeriodSeconds of the pod", func() {
|
||||||
podClient := f.ClientSet.Core().Pods(f.Namespace.Name)
|
podClient := f.ClientSet.Core().Pods(f.Namespace.Name)
|
||||||
By("constructing the pod")
|
By("constructing the pod")
|
||||||
name := "pod" + string(uuid.NewUUID())
|
name := "pod" + string(uuid.NewUUID())
|
||||||
@ -171,22 +193,16 @@ var _ = framework.KubeDescribe("Generated release_1_5 clientset", func() {
|
|||||||
framework.ExpectNoError(f.WaitForPodRunning(pod.Name))
|
framework.ExpectNoError(f.WaitForPodRunning(pod.Name))
|
||||||
|
|
||||||
By("deleting the pod gracefully")
|
By("deleting the pod gracefully")
|
||||||
if err := podClient.Delete(pod.Name, metav1.NewDeleteOptions(30)); err != nil {
|
gracePeriod := int64(31)
|
||||||
|
if err := podClient.Delete(pod.Name, metav1.NewDeleteOptions(gracePeriod)); err != nil {
|
||||||
framework.Failf("Failed to delete pod: %v", err)
|
framework.Failf("Failed to delete pod: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
By("verifying pod deletion was observed")
|
By("verifying the deletionTimestamp and deletionGracePeriodSeconds of the pod is set")
|
||||||
obj := observeObjectDeletion(w)
|
observerUpdate(w, func(obj runtime.Object) bool {
|
||||||
lastPod := obj.(*v1.Pod)
|
pod := obj.(*v1.Pod)
|
||||||
Expect(lastPod.DeletionTimestamp).ToNot(BeNil())
|
return pod.ObjectMeta.DeletionTimestamp != nil && *pod.ObjectMeta.DeletionGracePeriodSeconds == gracePeriod
|
||||||
Expect(lastPod.Spec.TerminationGracePeriodSeconds).ToNot(BeZero())
|
})
|
||||||
|
|
||||||
options = metav1.ListOptions{LabelSelector: selector}
|
|
||||||
pods, err = podClient.List(options)
|
|
||||||
if err != nil {
|
|
||||||
framework.Failf("Failed to list pods to verify deletion: %v", err)
|
|
||||||
}
|
|
||||||
Expect(len(pods.Items)).To(Equal(0))
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user