...
1
16
17 package e2enode
18
19 import (
20 "context"
21 "time"
22
23 "github.com/onsi/ginkgo/v2"
24 "github.com/onsi/gomega"
25 v1 "k8s.io/api/core/v1"
26 apierrors "k8s.io/apimachinery/pkg/api/errors"
27 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28 "k8s.io/apimachinery/pkg/util/uuid"
29 admissionapi "k8s.io/pod-security-admission/api"
30
31 "k8s.io/kubernetes/test/e2e/framework"
32 e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
33 )
34
35 var _ = SIGDescribe("Terminate Pods", func() {
36 f := framework.NewDefaultFramework("terminate-pods")
37 f.NamespacePodSecurityLevel = admissionapi.LevelBaseline
38
39 ginkgo.It("should not hang when terminating pods mounting non-existent volumes", func(ctx context.Context) {
40 pod := &v1.Pod{
41 ObjectMeta: metav1.ObjectMeta{
42 Name: "pod1",
43 },
44 Spec: v1.PodSpec{
45 Containers: []v1.Container{
46 {
47 Name: "container1",
48 Image: busyboxImage,
49 VolumeMounts: []v1.VolumeMount{
50 {
51 Name: "vol1",
52 MountPath: "/mnt/vol1",
53 },
54 },
55 },
56 },
57 Volumes: []v1.Volume{
58 {
59 Name: "vol1",
60 VolumeSource: v1.VolumeSource{
61 Secret: &v1.SecretVolumeSource{
62 SecretName: "non-existent-" + string(uuid.NewUUID()),
63 },
64 },
65 },
66 },
67 },
68 }
69 client := e2epod.NewPodClient(f)
70 pod = client.Create(context.TODO(), pod)
71 gomega.Expect(pod.Spec.NodeName).ToNot(gomega.BeEmpty())
72
73 gomega.Eventually(ctx, func() bool {
74 pod, _ = client.Get(context.TODO(), pod.Name, metav1.GetOptions{})
75 for _, c := range pod.Status.Conditions {
76 if c.Type == v1.ContainersReady && c.Status == v1.ConditionFalse {
77 return true
78 }
79 }
80 return false
81 }, 20*time.Second, 1*time.Second).Should(gomega.BeTrue())
82
83 err := client.Delete(context.Background(), pod.Name, metav1.DeleteOptions{})
84
85
86
87 gomega.Eventually(ctx, func() bool {
88 _, err := client.Get(context.TODO(), pod.Name, metav1.GetOptions{})
89 return apierrors.IsNotFound(err)
90 }, 10*time.Second, time.Second).Should(gomega.BeTrue())
91
92 framework.ExpectNoError(err)
93 })
94 })
95
View as plain text