...
1
16
17 package csi_mock
18
19 import (
20 "context"
21 "time"
22
23 "github.com/onsi/ginkgo/v2"
24 storagev1 "k8s.io/api/storage/v1"
25 "k8s.io/kubernetes/test/e2e/framework"
26 e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
27 "k8s.io/kubernetes/test/e2e/storage/utils"
28 admissionapi "k8s.io/pod-security-admission/api"
29 utilptr "k8s.io/utils/pointer"
30 )
31
32 var _ = utils.SIGDescribe("CSI Mock volume service account token", func() {
33 f := framework.NewDefaultFramework("csi-mock-volumes-service-token")
34 f.NamespacePodSecurityLevel = admissionapi.LevelPrivileged
35 m := newMockDriverSetup(f)
36
37 ginkgo.Context("CSIServiceAccountToken", func() {
38 var (
39 err error
40 )
41 tests := []struct {
42 desc string
43 deployCSIDriverObject bool
44 tokenRequests []storagev1.TokenRequest
45 }{
46 {
47 desc: "token should not be plumbed down when csiServiceAccountTokenEnabled=false",
48 deployCSIDriverObject: true,
49 tokenRequests: nil,
50 },
51 {
52 desc: "token should not be plumbed down when CSIDriver is not deployed",
53 deployCSIDriverObject: false,
54 tokenRequests: []storagev1.TokenRequest{{}},
55 },
56 {
57 desc: "token should be plumbed down when csiServiceAccountTokenEnabled=true",
58 deployCSIDriverObject: true,
59 tokenRequests: []storagev1.TokenRequest{{ExpirationSeconds: utilptr.Int64Ptr(60 * 10)}},
60 },
61 }
62 for _, test := range tests {
63 test := test
64 csiServiceAccountTokenEnabled := test.tokenRequests != nil
65 ginkgo.It(test.desc, func(ctx context.Context) {
66 m.init(ctx, testParameters{
67 registerDriver: test.deployCSIDriverObject,
68 tokenRequests: test.tokenRequests,
69 requiresRepublish: &csiServiceAccountTokenEnabled,
70 })
71
72 ginkgo.DeferCleanup(m.cleanup)
73
74 _, _, pod := m.createPod(ctx, pvcReference)
75 if pod == nil {
76 return
77 }
78 err = e2epod.WaitForPodNameRunningInNamespace(ctx, m.cs, pod.Name, pod.Namespace)
79 framework.ExpectNoError(err, "Failed to start pod: %v", err)
80
81
82 if test.deployCSIDriverObject && csiServiceAccountTokenEnabled {
83 time.Sleep(5 * time.Second)
84 }
85
86 ginkgo.By("Deleting the previously created pod")
87 err = e2epod.DeletePodWithWait(ctx, m.cs, pod)
88 framework.ExpectNoError(err, "while deleting")
89
90 ginkgo.By("Checking CSI driver logs")
91 err = checkNodePublishVolume(ctx, m.driver.GetCalls, pod, false, false, false, test.deployCSIDriverObject && csiServiceAccountTokenEnabled)
92 framework.ExpectNoError(err)
93 })
94 }
95 })
96 })
97
View as plain text