sigs.k8s.io/blob-csi-driver@v1.24.1/test/e2e/testsuites/pre_provisioned_existing_credentials_tester.go (about) 1 /* 2 Copyright 2020 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 testsuites 18 19 import ( 20 "context" 21 "fmt" 22 23 "github.com/onsi/ginkgo/v2" 24 25 "sigs.k8s.io/blob-csi-driver/pkg/blob" 26 "sigs.k8s.io/blob-csi-driver/test/e2e/driver" 27 28 v1 "k8s.io/api/core/v1" 29 clientset "k8s.io/client-go/kubernetes" 30 "k8s.io/kubernetes/test/e2e/framework" 31 ) 32 33 // PreProvisionedExistingCredentialsTest will provision required StorageClass(es), PVC(s) and Pod(s) 34 // Testing that the Pod(s) can be created successfully with existing credentials in k8s cluster 35 type PreProvisionedExistingCredentialsTest struct { 36 CSIDriver driver.PreProvisionedVolumeTestDriver 37 Pods []PodDetails 38 } 39 40 func (t *PreProvisionedExistingCredentialsTest) Run(ctx context.Context, client clientset.Interface, namespace *v1.Namespace) { 41 for _, pod := range t.Pods { 42 for n, volume := range pod.Volumes { 43 resourceGroupName, accountName, containerName, _, _, err := blob.GetContainerInfo(volume.VolumeID) 44 if err != nil { 45 framework.ExpectNoError(err, fmt.Sprintf("Error GetContainerInfo from volumeID(%s): %v", volume.VolumeID, err)) 46 return 47 } 48 parameters := map[string]string{ 49 "resourceGroup": resourceGroupName, 50 "storageAccount": accountName, 51 "containerName": containerName, 52 } 53 54 ginkgo.By("creating the storageclass with existing credentials") 55 sc := t.CSIDriver.GetProvisionStorageClass(parameters, volume.MountOptions, volume.ReclaimPolicy, volume.VolumeBindingMode, volume.AllowedTopologyValues, namespace.Name) 56 tsc := NewTestStorageClass(client, namespace, sc) 57 createdStorageClass := tsc.Create(ctx) 58 defer tsc.Cleanup(ctx) 59 60 ginkgo.By("creating pvc with storageclass") 61 tpvc := NewTestPersistentVolumeClaim(client, namespace, volume.ClaimSize, volume.VolumeMode, &createdStorageClass) 62 tpvc.Create(ctx) 63 defer tpvc.Cleanup(ctx) 64 65 ginkgo.By("validating the pvc") 66 tpvc.WaitForBound(ctx) 67 tpvc.ValidateProvisionedPersistentVolume(ctx) 68 69 tpod := NewTestPod(client, namespace, pod.Cmd) 70 tpod.SetupVolume(tpvc.persistentVolumeClaim, fmt.Sprintf("%s%d", volume.VolumeMount.NameGenerate, n+1), fmt.Sprintf("%s%d", volume.VolumeMount.MountPathGenerate, n+1), volume.VolumeMount.ReadOnly) 71 ginkgo.By("deploying the pod") 72 tpod.Create(ctx) 73 defer tpod.Cleanup(ctx) 74 ginkgo.By("checking that the pods command exits with no error") 75 tpod.WaitForSuccess(ctx) 76 } 77 } 78 }