k8s.io/kubernetes@v1.29.3/test/e2e/storage/csi_mock/csi_fsgroup_mount.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 "math/rand" 22 "strconv" 23 24 "github.com/onsi/ginkgo/v2" 25 "github.com/onsi/gomega" 26 "k8s.io/kubernetes/test/e2e/framework" 27 e2epod "k8s.io/kubernetes/test/e2e/framework/pod" 28 e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper" 29 "k8s.io/kubernetes/test/e2e/storage/utils" 30 admissionapi "k8s.io/pod-security-admission/api" 31 ) 32 33 var _ = utils.SIGDescribe("CSI Mock fsgroup as mount option", func() { 34 f := framework.NewDefaultFramework("csi-mock-volumes-fsgroup-mount") 35 f.NamespacePodSecurityLevel = admissionapi.LevelPrivileged 36 m := newMockDriverSetup(f) 37 38 ginkgo.Context("Delegate FSGroup to CSI driver [LinuxOnly]", func() { 39 tests := []struct { 40 name string 41 enableVolumeMountGroup bool 42 }{ 43 { 44 name: "should pass FSGroup to CSI driver if it is set in pod and driver supports VOLUME_MOUNT_GROUP", 45 enableVolumeMountGroup: true, 46 }, 47 { 48 name: "should not pass FSGroup to CSI driver if it is set in pod and driver supports VOLUME_MOUNT_GROUP", 49 enableVolumeMountGroup: false, 50 }, 51 } 52 for _, t := range tests { 53 t := t 54 ginkgo.It(t.name, func(ctx context.Context) { 55 var nodeStageFsGroup, nodePublishFsGroup string 56 if framework.NodeOSDistroIs("windows") { 57 e2eskipper.Skipf("FSGroupPolicy is only applied on linux nodes -- skipping") 58 } 59 m.init(ctx, testParameters{ 60 disableAttach: true, 61 registerDriver: true, 62 enableVolumeMountGroup: t.enableVolumeMountGroup, 63 hooks: createFSGroupRequestPreHook(&nodeStageFsGroup, &nodePublishFsGroup), 64 }) 65 ginkgo.DeferCleanup(m.cleanup) 66 67 fsGroupVal := int64(rand.Int63n(20000) + 1024) 68 fsGroup := &fsGroupVal 69 fsGroupStr := strconv.FormatInt(fsGroupVal, 10 /* base */) 70 71 _, _, pod := m.createPodWithFSGroup(ctx, fsGroup) /* persistent volume */ 72 73 err := e2epod.WaitForPodNameRunningInNamespace(ctx, m.cs, pod.Name, pod.Namespace) 74 framework.ExpectNoError(err, "failed to start pod") 75 76 if t.enableVolumeMountGroup { 77 gomega.Expect(nodeStageFsGroup).To(gomega.Equal(fsGroupStr), "Expect NodeStageVolumeRequest.VolumeCapability.MountVolume.VolumeMountGroup to equal %q; got: %q", fsGroupStr, nodeStageFsGroup) 78 gomega.Expect(nodePublishFsGroup).To(gomega.Equal(fsGroupStr), "Expect NodePublishVolumeRequest.VolumeCapability.MountVolume.VolumeMountGroup to equal %q; got: %q", fsGroupStr, nodePublishFsGroup) 79 } else { 80 gomega.Expect(nodeStageFsGroup).To(gomega.BeEmpty(), "Expect NodeStageVolumeRequest.VolumeCapability.MountVolume.VolumeMountGroup to be empty; got: %q", nodeStageFsGroup) 81 gomega.Expect(nodePublishFsGroup).To(gomega.BeEmpty(), "Expect NodePublishVolumeRequest.VolumeCapability.MountVolume.VolumeMountGroup to empty; got: %q", nodePublishFsGroup) 82 } 83 }) 84 } 85 }) 86 87 })