github.com/kubernetes-sigs/blobfuse-csi-driver@v0.5.0/test/e2e/driver/driver.go (about) 1 /* 2 Copyright 2019 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 driver 18 19 import ( 20 "github.com/kubernetes-csi/external-snapshotter/pkg/apis/volumesnapshot/v1alpha1" 21 v1 "k8s.io/api/core/v1" 22 storagev1 "k8s.io/api/storage/v1" 23 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 24 ) 25 26 const ( 27 VolumeSnapshotClassKind = "VolumeSnapshotClass" 28 SnapshotAPIVersion = "snapshot.storage.k8s.io/v1alpha1" 29 ) 30 31 type PVTestDriver interface { 32 DynamicPVTestDriver 33 PreProvisionedVolumeTestDriver 34 VolumeSnapshotTestDriver 35 } 36 37 // DynamicPVTestDriver represents an interface for a CSI driver that supports DynamicPV 38 type DynamicPVTestDriver interface { 39 // GetDynamicProvisionStorageClass returns a StorageClass dynamic provision Persistent Volume 40 GetDynamicProvisionStorageClass(parameters map[string]string, mountOptions []string, reclaimPolicy *v1.PersistentVolumeReclaimPolicy, bindingMode *storagev1.VolumeBindingMode, allowedTopologyValues []string, namespace string) *storagev1.StorageClass 41 } 42 43 // PreProvisionedVolumeTestDriver represents an interface for a CSI driver that supports pre-provisioned volume 44 type PreProvisionedVolumeTestDriver interface { 45 // GetPersistentVolume returns a PersistentVolume with pre-provisioned volumeHandle 46 GetPersistentVolume(volumeID string, fsType string, size string, reclaimPolicy *v1.PersistentVolumeReclaimPolicy, namespace string, attrib map[string]string, nodeStageSecretRef string) *v1.PersistentVolume 47 // GetPreProvisionStorageClass returns a StorageClass with existing container 48 GetPreProvisionStorageClass(parameters map[string]string, mountOptions []string, reclaimPolicy *v1.PersistentVolumeReclaimPolicy, bindingMode *storagev1.VolumeBindingMode, allowedTopologyValues []string, namespace string) *storagev1.StorageClass 49 } 50 51 type VolumeSnapshotTestDriver interface { 52 GetVolumeSnapshotClass(namespace string) *v1alpha1.VolumeSnapshotClass 53 } 54 55 func getStorageClass( 56 generateName string, 57 provisioner string, 58 parameters map[string]string, 59 mountOptions []string, 60 reclaimPolicy *v1.PersistentVolumeReclaimPolicy, 61 bindingMode *storagev1.VolumeBindingMode, 62 allowedTopologies []v1.TopologySelectorTerm, 63 ) *storagev1.StorageClass { 64 if reclaimPolicy == nil { 65 defaultReclaimPolicy := v1.PersistentVolumeReclaimDelete 66 reclaimPolicy = &defaultReclaimPolicy 67 } 68 if bindingMode == nil { 69 defaultBindingMode := storagev1.VolumeBindingImmediate 70 bindingMode = &defaultBindingMode 71 } 72 return &storagev1.StorageClass{ 73 ObjectMeta: metav1.ObjectMeta{ 74 GenerateName: generateName, 75 }, 76 Provisioner: provisioner, 77 Parameters: parameters, 78 MountOptions: mountOptions, 79 ReclaimPolicy: reclaimPolicy, 80 VolumeBindingMode: bindingMode, 81 AllowedTopologies: allowedTopologies, 82 } 83 } 84 85 func getVolumeSnapshotClass(generateName string, provisioner string) *v1alpha1.VolumeSnapshotClass { 86 return &v1alpha1.VolumeSnapshotClass{ 87 TypeMeta: metav1.TypeMeta{ 88 Kind: VolumeSnapshotClassKind, 89 APIVersion: SnapshotAPIVersion, 90 }, 91 92 ObjectMeta: metav1.ObjectMeta{ 93 GenerateName: generateName, 94 }, 95 Snapshotter: provisioner, 96 } 97 }