k8s.io/kubernetes@v1.29.3/test/e2e/storage/csi_mock/csi_workload.go (about) 1 /* 2 Copyright 2022 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 csi_mock 18 19 import ( 20 "context" 21 22 "github.com/onsi/ginkgo/v2" 23 "k8s.io/kubernetes/test/e2e/framework" 24 e2epod "k8s.io/kubernetes/test/e2e/framework/pod" 25 "k8s.io/kubernetes/test/e2e/storage/testsuites" 26 "k8s.io/kubernetes/test/e2e/storage/utils" 27 admissionapi "k8s.io/pod-security-admission/api" 28 ) 29 30 var _ = utils.SIGDescribe("CSI Mock workload info", func() { 31 // The CSIDriverRegistry feature gate is needed for this test in Kubernetes 1.12. 32 f := framework.NewDefaultFramework("csi-mock-volumes-workload") 33 f.NamespacePodSecurityLevel = admissionapi.LevelPrivileged 34 m := newMockDriverSetup(f) 35 ginkgo.Context("CSI workload information using mock driver", func() { 36 var ( 37 err error 38 podInfoTrue = true 39 podInfoFalse = false 40 ) 41 tests := []struct { 42 name string 43 podInfoOnMount *bool 44 deployClusterRegistrar bool 45 expectPodInfo bool 46 expectEphemeral bool 47 }{ 48 { 49 name: "should not be passed when podInfoOnMount=nil", 50 podInfoOnMount: nil, 51 deployClusterRegistrar: true, 52 expectPodInfo: false, 53 expectEphemeral: false, 54 }, 55 { 56 name: "should be passed when podInfoOnMount=true", 57 podInfoOnMount: &podInfoTrue, 58 deployClusterRegistrar: true, 59 expectPodInfo: true, 60 expectEphemeral: false, 61 }, 62 { 63 name: "contain ephemeral=true when using inline volume", 64 podInfoOnMount: &podInfoTrue, 65 deployClusterRegistrar: true, 66 expectPodInfo: true, 67 expectEphemeral: true, 68 }, 69 { 70 name: "should not be passed when podInfoOnMount=false", 71 podInfoOnMount: &podInfoFalse, 72 deployClusterRegistrar: true, 73 expectPodInfo: false, 74 expectEphemeral: false, 75 }, 76 { 77 name: "should not be passed when CSIDriver does not exist", 78 deployClusterRegistrar: false, 79 expectPodInfo: false, 80 expectEphemeral: false, 81 }, 82 } 83 for _, t := range tests { 84 test := t 85 ginkgo.It(t.name, func(ctx context.Context) { 86 m.init(ctx, testParameters{ 87 registerDriver: test.deployClusterRegistrar, 88 podInfo: test.podInfoOnMount}) 89 90 ginkgo.DeferCleanup(m.cleanup) 91 92 withVolume := pvcReference 93 if test.expectEphemeral { 94 withVolume = csiEphemeral 95 } 96 _, _, pod := m.createPod(ctx, withVolume) 97 if pod == nil { 98 return 99 } 100 err = e2epod.WaitForPodNameRunningInNamespace(ctx, m.cs, pod.Name, pod.Namespace) 101 framework.ExpectNoError(err, "Failed to start pod: %v", err) 102 103 // If we expect an ephemeral volume, the feature has to be enabled. 104 // Otherwise need to check if we expect pod info, because the content 105 // of that depends on whether the feature is enabled or not. 106 csiInlineVolumesEnabled := test.expectEphemeral 107 if test.expectPodInfo { 108 ginkgo.By("checking for CSIInlineVolumes feature") 109 csiInlineVolumesEnabled, err = testsuites.CSIInlineVolumesEnabled(ctx, m.cs, f.Timeouts, f.Namespace.Name) 110 framework.ExpectNoError(err, "failed to test for CSIInlineVolumes") 111 } 112 113 ginkgo.By("Deleting the previously created pod") 114 err = e2epod.DeletePodWithWait(ctx, m.cs, pod) 115 framework.ExpectNoError(err, "while deleting") 116 117 ginkgo.By("Checking CSI driver logs") 118 err = checkPodLogs(ctx, m.driver.GetCalls, pod, test.expectPodInfo, test.expectEphemeral, csiInlineVolumesEnabled, false, 1) 119 framework.ExpectNoError(err) 120 }) 121 } 122 }) 123 124 })