github.com/kubernetes-sigs/blobfuse-csi-driver@v0.5.0/test/e2e/testsuites/pre_provisioned_provided_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" 24 25 "sigs.k8s.io/blobfuse-csi-driver/pkg/blobfuse" 26 "sigs.k8s.io/blobfuse-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 // PreProvisionedProvidedCredentiasTest will provision required PV(s), PVC(s) and Pod(s) 34 // Testing that the Pod(s) can be created successfully with provided storage account name and key(or sastoken) 35 type PreProvisionedProvidedCredentiasTest struct { 36 CSIDriver driver.PreProvisionedVolumeTestDriver 37 Pods []PodDetails 38 Blobfuse *blobfuse.Driver 39 } 40 41 func (t *PreProvisionedProvidedCredentiasTest) Run(client clientset.Interface, namespace *v1.Namespace) { 42 for _, pod := range t.Pods { 43 for n, volume := range pod.Volumes { 44 accountName, accountKey, accountSasToken, containerName, err := t.Blobfuse.GetStorageAccountAndContainer(context.Background(), volume.VolumeID, nil, nil) 45 framework.ExpectNoError(err, fmt.Sprintf("Error GetStorageAccountAndContainer from volumeID(%s): %v", volume.VolumeID, err)) 46 47 ginkgo.By("creating the secret") 48 secreteData := map[string]string{"azurestorageaccountname": accountName} 49 if accountKey != "" { 50 secreteData["azurestorageaccountkey"] = accountKey 51 } else { 52 secreteData["azurestorageaccountsastoken"] = accountSasToken 53 } 54 tsecret := NewTestSecret(client, namespace, volume.NodeStageSecretRef, secreteData) 55 tsecret.Create() 56 defer tsecret.Cleanup() 57 58 pod.Volumes[n].ContainerName = containerName 59 tpod, cleanup := pod.SetupWithPreProvisionedVolumes(client, namespace, t.CSIDriver) 60 // defer must be called here for resources not get removed before using them 61 for i := range cleanup { 62 defer cleanup[i]() 63 } 64 65 ginkgo.By("deploying the pod") 66 tpod.Create() 67 defer tpod.Cleanup() 68 ginkgo.By("checking that the pods command exits with no error") 69 tpod.WaitForSuccess() 70 } 71 } 72 }