sigs.k8s.io/blob-csi-driver@v1.24.1/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  	v1 "k8s.io/api/core/v1"
    21  	storagev1 "k8s.io/api/storage/v1"
    22  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    23  )
    24  
    25  type PVTestDriver interface {
    26  	DynamicPVTestDriver
    27  	PreProvisionedVolumeTestDriver
    28  }
    29  
    30  // DynamicPVTestDriver represents an interface for a CSI driver that supports DynamicPV
    31  type DynamicPVTestDriver interface {
    32  	// GetProvisionStorageClass returns a StorageClass dynamic provision Persistent Volume
    33  	GetProvisionStorageClass(parameters map[string]string, mountOptions []string, reclaimPolicy *v1.PersistentVolumeReclaimPolicy, bindingMode *storagev1.VolumeBindingMode, allowedTopologyValues []string, namespace string) *storagev1.StorageClass
    34  }
    35  
    36  // PreProvisionedVolumeTestDriver represents an interface for a CSI driver that supports pre-provisioned volume
    37  type PreProvisionedVolumeTestDriver interface {
    38  	// GetPersistentVolume returns a PersistentVolume with pre-provisioned volumeHandle
    39  	GetPersistentVolume(volumeID string, fsType string, size string, reclaimPolicy *v1.PersistentVolumeReclaimPolicy, namespace string, attrib map[string]string, nodeStageSecretRef string) *v1.PersistentVolume
    40  	// GetProvisionStorageClass returns a StorageClass with existing container
    41  	GetProvisionStorageClass(parameters map[string]string, mountOptions []string, reclaimPolicy *v1.PersistentVolumeReclaimPolicy, bindingMode *storagev1.VolumeBindingMode, allowedTopologyValues []string, namespace string) *storagev1.StorageClass
    42  }
    43  
    44  func getStorageClass(
    45  	generateName string,
    46  	provisioner string,
    47  	parameters map[string]string,
    48  	mountOptions []string,
    49  	reclaimPolicy *v1.PersistentVolumeReclaimPolicy,
    50  	bindingMode *storagev1.VolumeBindingMode,
    51  	allowedTopologies []v1.TopologySelectorTerm,
    52  ) *storagev1.StorageClass {
    53  	if reclaimPolicy == nil {
    54  		defaultReclaimPolicy := v1.PersistentVolumeReclaimDelete
    55  		reclaimPolicy = &defaultReclaimPolicy
    56  	}
    57  	if bindingMode == nil {
    58  		defaultBindingMode := storagev1.VolumeBindingImmediate
    59  		bindingMode = &defaultBindingMode
    60  	}
    61  	allowVolumeExpansion := true
    62  	return &storagev1.StorageClass{
    63  		ObjectMeta: metav1.ObjectMeta{
    64  			GenerateName: generateName,
    65  		},
    66  		Provisioner:          provisioner,
    67  		Parameters:           parameters,
    68  		MountOptions:         mountOptions,
    69  		ReclaimPolicy:        reclaimPolicy,
    70  		VolumeBindingMode:    bindingMode,
    71  		AllowedTopologies:    allowedTopologies,
    72  		AllowVolumeExpansion: &allowVolumeExpansion,
    73  	}
    74  }