k8s.io/kubernetes@v1.29.3/test/e2e_node/terminate_pods_test.go (about) 1 /* 2 Copyright 2023 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 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 // Wait for the pod to disappear from the API server up to 10 seconds, this shouldn't hang for minutes due to 86 // non-existent secret being mounted. 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 })