k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/test/e2e/storage/csimock/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 csimock 18 19 import ( 20 "context" 21 22 "github.com/onsi/ginkgo/v2" 23 "github.com/onsi/gomega" 24 "k8s.io/kubernetes/test/e2e/framework" 25 e2epod "k8s.io/kubernetes/test/e2e/framework/pod" 26 "k8s.io/kubernetes/test/e2e/storage/testsuites" 27 "k8s.io/kubernetes/test/e2e/storage/utils" 28 admissionapi "k8s.io/pod-security-admission/api" 29 ) 30 31 var _ = utils.SIGDescribe("CSI Mock workload info", func() { 32 // The CSIDriverRegistry feature gate is needed for this test in Kubernetes 1.12. 33 f := framework.NewDefaultFramework("csi-mock-volumes-workload") 34 f.NamespacePodSecurityLevel = admissionapi.LevelPrivileged 35 m := newMockDriverSetup(f) 36 ginkgo.Context("CSI workload information using mock driver", func() { 37 tests := []struct { 38 name string 39 podInfoOnMount bool 40 deployClusterRegistrar bool 41 expectPodInfo bool 42 expectEphemeral bool 43 }{ 44 { 45 name: "should be passed when podInfoOnMount=true", 46 podInfoOnMount: true, 47 deployClusterRegistrar: true, 48 expectPodInfo: true, 49 expectEphemeral: false, 50 }, 51 { 52 name: "contain ephemeral=true when using inline volume", 53 podInfoOnMount: true, 54 deployClusterRegistrar: true, 55 expectPodInfo: true, 56 expectEphemeral: true, 57 }, 58 { 59 name: "should not be passed when podInfoOnMount=false", 60 podInfoOnMount: false, 61 deployClusterRegistrar: true, 62 expectPodInfo: false, 63 expectEphemeral: false, 64 }, 65 { 66 name: "should not be passed when CSIDriver does not exist", 67 deployClusterRegistrar: false, 68 expectPodInfo: false, 69 expectEphemeral: false, 70 }, 71 } 72 for _, t := range tests { 73 test := t 74 ginkgo.It(t.name, func(ctx context.Context) { 75 m.init(ctx, testParameters{ 76 registerDriver: test.deployClusterRegistrar, 77 podInfo: &test.podInfoOnMount}) 78 79 ginkgo.DeferCleanup(m.cleanup) 80 81 waitUntilPodInfoInLog(ctx, m, test.expectPodInfo, test.expectEphemeral) 82 83 }) 84 } 85 }) 86 87 ginkgo.Context("CSI PodInfoOnMount Update", func() { 88 tests := []struct { 89 name string 90 oldPodInfoOnMount bool 91 newPodInfoOnMount bool 92 }{ 93 { 94 name: "should not be passed when update from true to false", 95 oldPodInfoOnMount: true, 96 newPodInfoOnMount: false, 97 }, 98 { 99 name: "should be passed when update from false to true", 100 oldPodInfoOnMount: false, 101 newPodInfoOnMount: true, 102 }, 103 } 104 for _, t := range tests { 105 test := t 106 ginkgo.It(t.name, func(ctx context.Context) { 107 m.init(ctx, testParameters{ 108 registerDriver: true, 109 podInfo: &test.oldPodInfoOnMount}) 110 111 ginkgo.DeferCleanup(m.cleanup) 112 113 waitUntilPodInfoInLog(ctx, m, test.oldPodInfoOnMount, false) 114 m.update(utils.PatchCSIOptions{PodInfo: &test.newPodInfoOnMount}) 115 waitUntilPodInfoInLog(ctx, m, test.newPodInfoOnMount, false) 116 }) 117 } 118 }) 119 120 }) 121 122 func waitUntilPodInfoInLog(ctx context.Context, m *mockDriverSetup, expectPodInfo, expectEphemeral bool) { 123 var err error 124 125 utils.WaitUntil(framework.Poll, framework.PodStartTimeout, func() bool { 126 err = gomega.InterceptGomegaFailure(func() { 127 withVolume := pvcReference 128 if expectEphemeral { 129 withVolume = csiEphemeral 130 } 131 _, _, pod := m.createPod(ctx, withVolume) 132 if pod == nil { 133 return 134 } 135 err = e2epod.WaitForPodNameRunningInNamespace(ctx, m.cs, pod.Name, pod.Namespace) 136 framework.ExpectNoError(err, "Failed to start pod: %v", err) 137 138 // If we expect an ephemeral volume, the feature has to be enabled. 139 // Otherwise need to check if we expect pod info, because the content 140 // of that depends on whether the feature is enabled or not. 141 csiInlineVolumesEnabled := expectEphemeral 142 if expectPodInfo { 143 ginkgo.By("checking for CSIInlineVolumes feature") 144 csiInlineVolumesEnabled, err = testsuites.CSIInlineVolumesEnabled(ctx, m.cs, m.f.Timeouts, m.f.Namespace.Name) 145 framework.ExpectNoError(err, "failed to test for CSIInlineVolumes") 146 } 147 148 ginkgo.By("Deleting the previously created pod") 149 err = e2epod.DeletePodWithWait(ctx, m.cs, pod) 150 framework.ExpectNoError(err, "while deleting") 151 152 ginkgo.By("Checking CSI driver logs") 153 err = checkNodePublishVolume(ctx, m.driver.GetCalls, pod, expectPodInfo, expectEphemeral, csiInlineVolumesEnabled, false) 154 framework.ExpectNoError(err) 155 }) 156 157 return err == nil 158 }) 159 160 framework.ExpectNoError(err, "failed: verifing PodInfo: %s", err) 161 }