mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-20 02:11:09 +00:00
All code must use the context from Ginkgo when doing API calls or polling for a change, otherwise the code would not return immediately when the test gets aborted.
87 lines
3.3 KiB
Go
87 lines
3.3 KiB
Go
/*
|
|
Copyright 2022 The Kubernetes Authors.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package csi_mock
|
|
|
|
import (
|
|
"context"
|
|
"math/rand"
|
|
"strconv"
|
|
|
|
"github.com/onsi/ginkgo/v2"
|
|
"k8s.io/kubernetes/test/e2e/framework"
|
|
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
|
|
e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
|
|
"k8s.io/kubernetes/test/e2e/storage/utils"
|
|
admissionapi "k8s.io/pod-security-admission/api"
|
|
)
|
|
|
|
var _ = utils.SIGDescribe("CSI Mock fsgroup as mount option", func() {
|
|
f := framework.NewDefaultFramework("csi-mock-volumes-fsgroup-mount")
|
|
f.NamespacePodSecurityEnforceLevel = admissionapi.LevelPrivileged
|
|
m := newMockDriverSetup(f)
|
|
|
|
ginkgo.Context("Delegate FSGroup to CSI driver [LinuxOnly]", func() {
|
|
tests := []struct {
|
|
name string
|
|
enableVolumeMountGroup bool
|
|
}{
|
|
{
|
|
name: "should pass FSGroup to CSI driver if it is set in pod and driver supports VOLUME_MOUNT_GROUP",
|
|
enableVolumeMountGroup: true,
|
|
},
|
|
{
|
|
name: "should not pass FSGroup to CSI driver if it is set in pod and driver supports VOLUME_MOUNT_GROUP",
|
|
enableVolumeMountGroup: false,
|
|
},
|
|
}
|
|
for _, t := range tests {
|
|
t := t
|
|
ginkgo.It(t.name, func(ctx context.Context) {
|
|
var nodeStageFsGroup, nodePublishFsGroup string
|
|
if framework.NodeOSDistroIs("windows") {
|
|
e2eskipper.Skipf("FSGroupPolicy is only applied on linux nodes -- skipping")
|
|
}
|
|
m.init(ctx, testParameters{
|
|
disableAttach: true,
|
|
registerDriver: true,
|
|
enableVolumeMountGroup: t.enableVolumeMountGroup,
|
|
hooks: createFSGroupRequestPreHook(&nodeStageFsGroup, &nodePublishFsGroup),
|
|
})
|
|
ginkgo.DeferCleanup(m.cleanup)
|
|
|
|
fsGroupVal := int64(rand.Int63n(20000) + 1024)
|
|
fsGroup := &fsGroupVal
|
|
fsGroupStr := strconv.FormatInt(fsGroupVal, 10 /* base */)
|
|
|
|
_, _, pod := m.createPodWithFSGroup(ctx, fsGroup) /* persistent volume */
|
|
|
|
err := e2epod.WaitForPodNameRunningInNamespace(ctx, m.cs, pod.Name, pod.Namespace)
|
|
framework.ExpectNoError(err, "failed to start pod")
|
|
|
|
if t.enableVolumeMountGroup {
|
|
framework.ExpectEqual(nodeStageFsGroup, fsGroupStr, "Expect NodeStageVolumeRequest.VolumeCapability.MountVolume.VolumeMountGroup to equal %q; got: %q", fsGroupStr, nodeStageFsGroup)
|
|
framework.ExpectEqual(nodePublishFsGroup, fsGroupStr, "Expect NodePublishVolumeRequest.VolumeCapability.MountVolume.VolumeMountGroup to equal %q; got: %q", fsGroupStr, nodePublishFsGroup)
|
|
} else {
|
|
framework.ExpectEmpty(nodeStageFsGroup, "Expect NodeStageVolumeRequest.VolumeCapability.MountVolume.VolumeMountGroup to be empty; got: %q", nodeStageFsGroup)
|
|
framework.ExpectEmpty(nodePublishFsGroup, "Expect NodePublishVolumeRequest.VolumeCapability.MountVolume.VolumeMountGroup to empty; got: %q", nodePublishFsGroup)
|
|
}
|
|
})
|
|
}
|
|
})
|
|
|
|
})
|