NodeConformance: Respect grace period when updating static pod

This commit is contained in:
Gunju Kim 2021-08-03 22:20:02 +09:00
parent edeab47b36
commit 0f2c94d842
No known key found for this signature in database
GPG Key ID: AA73776FF098A5BD

View File

@ -26,8 +26,11 @@ import (
"github.com/onsi/gomega" "github.com/onsi/gomega"
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/uuid" "k8s.io/apimachinery/pkg/util/uuid"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/kubernetes/test/e2e/framework" "k8s.io/kubernetes/test/e2e/framework"
imageutils "k8s.io/kubernetes/test/utils/image"
) )
var _ = SIGDescribe("MirrorPodWithGracePeriod", func() { var _ = SIGDescribe("MirrorPodWithGracePeriod", func() {
@ -53,10 +56,9 @@ var _ = SIGDescribe("MirrorPodWithGracePeriod", func() {
ginkgo.It("mirror pod termination should satisfy grace period when static pod is deleted [NodeConformance]", func() { ginkgo.It("mirror pod termination should satisfy grace period when static pod is deleted [NodeConformance]", func() {
ginkgo.By("get mirror pod uid") ginkgo.By("get mirror pod uid")
_, err := f.ClientSet.CoreV1().Pods(ns).Get(context.TODO(), mirrorPodName, metav1.GetOptions{}) pod, err := f.ClientSet.CoreV1().Pods(ns).Get(context.TODO(), mirrorPodName, metav1.GetOptions{})
framework.ExpectNoError(err) framework.ExpectNoError(err)
uid := pod.UID
start := time.Now()
ginkgo.By("delete the static pod") ginkgo.By("delete the static pod")
file := staticPodPath(podPath, staticPodName, ns) file := staticPodPath(podPath, staticPodName, ns)
@ -64,25 +66,51 @@ var _ = SIGDescribe("MirrorPodWithGracePeriod", func() {
err = os.Remove(file) err = os.Remove(file)
framework.ExpectNoError(err) framework.ExpectNoError(err)
for { ginkgo.By("wait for the mirror pod to be running for grace period")
if time.Now().Sub(start).Seconds() > 19 { gomega.Consistently(func() error {
break return checkMirrorPodRunningWithUID(f.ClientSet, mirrorPodName, ns, uid)
} }, 19*time.Second, 200*time.Millisecond).Should(gomega.BeNil())
pod, err := f.ClientSet.CoreV1().Pods(ns).Get(context.TODO(), mirrorPodName, metav1.GetOptions{}) })
framework.ExpectNoError(err)
if pod.Status.Phase != v1.PodRunning { ginkgo.It("mirror pod termination should satisfy grace period when static pod is updated [NodeConformance]", func() {
framework.Failf("expected the mirror pod %q to be running, got %q", mirrorPodName, pod.Status.Phase) ginkgo.By("get mirror pod uid")
} pod, err := f.ClientSet.CoreV1().Pods(ns).Get(context.TODO(), mirrorPodName, metav1.GetOptions{})
// have some pause in between the API server queries to avoid throttling framework.ExpectNoError(err)
time.Sleep(time.Duration(200) * time.Millisecond) uid := pod.UID
}
ginkgo.By("update the static pod container image")
image := imageutils.GetPauseImageName()
err = createStaticPod(podPath, staticPodName, ns, image, v1.RestartPolicyAlways)
framework.ExpectNoError(err)
ginkgo.By("wait for the mirror pod to be running for grace period")
gomega.Consistently(func() error {
return checkMirrorPodRunningWithUID(f.ClientSet, mirrorPodName, ns, uid)
}, 19*time.Second, 200*time.Millisecond).Should(gomega.BeNil())
ginkgo.By("wait for the mirror pod to be updated")
gomega.Eventually(func() error {
return checkMirrorPodRecreatedAndRunning(f.ClientSet, mirrorPodName, ns, uid)
}, 2*time.Minute, time.Second*4).Should(gomega.BeNil())
ginkgo.By("check the mirror pod container image is updated")
pod, err = f.ClientSet.CoreV1().Pods(ns).Get(context.TODO(), mirrorPodName, metav1.GetOptions{})
framework.ExpectNoError(err)
framework.ExpectEqual(len(pod.Spec.Containers), 1)
framework.ExpectEqual(pod.Spec.Containers[0].Image, image)
}) })
ginkgo.AfterEach(func() { ginkgo.AfterEach(func() {
ginkgo.By("delete the static pod")
err := deleteStaticPod(podPath, staticPodName, ns)
if !os.IsNotExist(err) {
framework.ExpectNoError(err)
}
ginkgo.By("wait for the mirror pod to disappear") ginkgo.By("wait for the mirror pod to disappear")
gomega.Eventually(func() error { gomega.Eventually(func() error {
return checkMirrorPodDisappear(f.ClientSet, mirrorPodName, ns) return checkMirrorPodDisappear(f.ClientSet, mirrorPodName, ns)
}, time.Second*19, time.Second).Should(gomega.BeNil()) }, 2*time.Minute, time.Second*4).Should(gomega.BeNil())
}) })
}) })
}) })
@ -124,3 +152,17 @@ spec:
framework.Logf("has written %v", file) framework.Logf("has written %v", file)
return err return err
} }
func checkMirrorPodRunningWithUID(cl clientset.Interface, name, namespace string, oUID types.UID) error {
pod, err := cl.CoreV1().Pods(namespace).Get(context.TODO(), name, metav1.GetOptions{})
if err != nil {
return fmt.Errorf("expected the mirror pod %q to appear: %v", name, err)
}
if pod.UID != oUID {
return fmt.Errorf("expected the uid of mirror pod %q to be same, got %q", name, pod.UID)
}
if pod.Status.Phase != v1.PodRunning {
return fmt.Errorf("expected the mirror pod %q to be running, got %q", name, pod.Status.Phase)
}
return nil
}