sigs.k8s.io/cluster-api-provider-azure@v1.14.3/test/e2e/azure_csidriver.go (about) 1 //go:build e2e 2 // +build e2e 3 4 /* 5 Copyright 2022 The Kubernetes Authors. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 */ 19 20 package e2e 21 22 import ( 23 "context" 24 25 . "github.com/onsi/ginkgo/v2" 26 . "github.com/onsi/gomega" 27 appsv1 "k8s.io/api/apps/v1" 28 corev1 "k8s.io/api/core/v1" 29 "k8s.io/client-go/kubernetes" 30 deploymentBuilder "sigs.k8s.io/cluster-api-provider-azure/test/e2e/kubernetes/deployment" 31 e2e_pvc "sigs.k8s.io/cluster-api-provider-azure/test/e2e/kubernetes/pvc" 32 e2e_sc "sigs.k8s.io/cluster-api-provider-azure/test/e2e/kubernetes/storageclass" 33 "sigs.k8s.io/cluster-api/test/framework" 34 "sigs.k8s.io/cluster-api/util" 35 ) 36 37 const ( 38 DriverTypeInternal = "Internal" 39 ) 40 41 type AzureDiskCSISpecInput struct { 42 BootstrapClusterProxy framework.ClusterProxy 43 Namespace *corev1.Namespace 44 ClusterName string 45 SkipCleanup bool 46 DriverType string 47 } 48 49 // AzureDiskCSISpec implements a test that verifies out of tree azure disk csi driver 50 // can be used to create a PVC that is usable by a pod. 51 func AzureDiskCSISpec(ctx context.Context, inputGetter func() AzureDiskCSISpecInput) *appsv1.Deployment { 52 specName := "azurediskcsi-driver" 53 input := inputGetter() 54 Expect(input.BootstrapClusterProxy).NotTo(BeNil(), "Invalid argument. input.BootstrapClusterProxy can't be nil when calling %s spec", specName) 55 56 By("creating a Kubernetes client to the workload cluster") 57 clusterProxy := input.BootstrapClusterProxy.GetWorkloadCluster(ctx, input.Namespace.Name, input.ClusterName) 58 Expect(clusterProxy).NotTo(BeNil()) 59 clientset := clusterProxy.GetClientSet() 60 Expect(clientset).NotTo(BeNil()) 61 62 var pvcName string 63 if input.DriverType == DriverTypeInternal { 64 By("[In-tree]Deploying storage class and pvc") 65 By("Deploying managed disk storage class") 66 scName := "managedhdd" + util.RandomString(6) 67 e2e_sc.Create(scName).WithWaitForFirstConsumer().DeployStorageClass(clientset) 68 By("Deploying persistent volume claim") 69 pvcName = "dd-managed-hdd-5g" + util.RandomString(6) 70 pvcBuilder, err := e2e_pvc.Create(pvcName, "5Gi") 71 Expect(err).NotTo(HaveOccurred()) 72 annotations := map[string]string{ 73 "volume.beta.kubernetes.io/storage-class": scName, 74 } 75 pvcBuilder.WithAnnotations(annotations) 76 err = pvcBuilder.DeployPVC(clientset) 77 Expect(err).NotTo(HaveOccurred()) 78 } else { 79 By("[External]Deploying storage class and pvc") 80 By("Deploying managed disk storage class") 81 scName := "oot-managedhdd" + util.RandomString(6) 82 e2e_sc.Create(scName).WithWaitForFirstConsumer(). 83 WithOotProvisionerName(). 84 WithOotParameters(). 85 DeployStorageClass(clientset) 86 By("Deploying persistent volume claim") 87 pvcName = "oot-dd-managed-hdd-5g" + util.RandomString(6) 88 pvcBuilder, err := e2e_pvc.Create(pvcName, "5Gi") 89 Expect(err).NotTo(HaveOccurred()) 90 pvcBuilder.WithStorageClass(scName) 91 err = pvcBuilder.DeployPVC(clientset) 92 Expect(err).NotTo(HaveOccurred()) 93 } 94 95 By("creating a deployment that uses pvc") 96 deploymentName := "stateful" + util.RandomString(6) 97 statefulDeployment := deploymentBuilder.Create("nginx", deploymentName, corev1.NamespaceDefault).AddPVC(pvcName) 98 deployment, err := statefulDeployment.Deploy(ctx, clientset) 99 Expect(err).NotTo(HaveOccurred()) 100 waitForDeploymentAvailable(ctx, deployment, clientset, specName) 101 return deployment 102 } 103 104 func waitForDeploymentAvailable(ctx context.Context, deployment *appsv1.Deployment, clientset *kubernetes.Clientset, specName string) { 105 deployInput := WaitForDeploymentsAvailableInput{ 106 Getter: deploymentsClientAdapter{client: clientset.AppsV1().Deployments(deployment.Namespace)}, 107 Deployment: deployment, 108 Clientset: clientset, 109 } 110 WaitForDeploymentsAvailable(ctx, deployInput, e2eConfig.GetIntervals(specName, "wait-deployment")...) 111 }