github.com/jmclong/azuredisk-csi-driver@v0.7.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/v1beta1"
    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/v1beta1"
    29  )
    30  
    31  type PVTestDriver interface {
    32  	GetDynamicProvisionStorageClass(parameters map[string]string, mountOptions []string, reclaimPolicy *v1.PersistentVolumeReclaimPolicy, bindingMode *storagev1.VolumeBindingMode, allowedTopologyValues []string, namespace string) *storagev1.StorageClass
    33  	GetPersistentVolume(volumeID string, fsType string, size string, reclaimPolicy *v1.PersistentVolumeReclaimPolicy, namespace string) *v1.PersistentVolume
    34  	GetVolumeSnapshotClass(namespace string) *v1beta1.VolumeSnapshotClass
    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) *v1.PersistentVolume
    47  }
    48  
    49  type VolumeSnapshotTestDriver interface {
    50  	GetVolumeSnapshotClass(namespace string) *v1beta1.VolumeSnapshotClass
    51  }
    52  
    53  func getStorageClass(
    54  	generateName string,
    55  	provisioner string,
    56  	parameters map[string]string,
    57  	mountOptions []string,
    58  	reclaimPolicy *v1.PersistentVolumeReclaimPolicy,
    59  	bindingMode *storagev1.VolumeBindingMode,
    60  	allowedTopologies []v1.TopologySelectorTerm,
    61  ) *storagev1.StorageClass {
    62  	if reclaimPolicy == nil {
    63  		defaultReclaimPolicy := v1.PersistentVolumeReclaimDelete
    64  		reclaimPolicy = &defaultReclaimPolicy
    65  	}
    66  	if bindingMode == nil {
    67  		defaultBindingMode := storagev1.VolumeBindingImmediate
    68  		bindingMode = &defaultBindingMode
    69  	}
    70  	return &storagev1.StorageClass{
    71  		ObjectMeta: metav1.ObjectMeta{
    72  			GenerateName: generateName,
    73  		},
    74  		Provisioner:       provisioner,
    75  		Parameters:        parameters,
    76  		MountOptions:      mountOptions,
    77  		ReclaimPolicy:     reclaimPolicy,
    78  		VolumeBindingMode: bindingMode,
    79  		AllowedTopologies: allowedTopologies,
    80  	}
    81  }
    82  
    83  func getVolumeSnapshotClass(generateName string, provisioner string) *v1beta1.VolumeSnapshotClass {
    84  	return &v1beta1.VolumeSnapshotClass{
    85  		TypeMeta: metav1.TypeMeta{
    86  			Kind:       VolumeSnapshotClassKind,
    87  			APIVersion: SnapshotAPIVersion,
    88  		},
    89  
    90  		ObjectMeta: metav1.ObjectMeta{
    91  			GenerateName: generateName,
    92  		},
    93  		Driver:         provisioner,
    94  		DeletionPolicy: v1beta1.VolumeSnapshotContentDelete,
    95  	}
    96  }