remove clusterName from VolumeOptions
This commit is contained in:
		@@ -337,7 +337,6 @@ func startPersistentVolumeBinderController(ctx context.Context, controllerContex
 | 
				
			|||||||
		KubeClient:                controllerContext.ClientBuilder.ClientOrDie("persistent-volume-binder"),
 | 
							KubeClient:                controllerContext.ClientBuilder.ClientOrDie("persistent-volume-binder"),
 | 
				
			||||||
		SyncPeriod:                controllerContext.ComponentConfig.PersistentVolumeBinderController.PVClaimBinderSyncPeriod.Duration,
 | 
							SyncPeriod:                controllerContext.ComponentConfig.PersistentVolumeBinderController.PVClaimBinderSyncPeriod.Duration,
 | 
				
			||||||
		VolumePlugins:             plugins,
 | 
							VolumePlugins:             plugins,
 | 
				
			||||||
		ClusterName:               controllerContext.ComponentConfig.KubeCloudShared.ClusterName,
 | 
					 | 
				
			||||||
		VolumeInformer:            controllerContext.InformerFactory.Core().V1().PersistentVolumes(),
 | 
							VolumeInformer:            controllerContext.InformerFactory.Core().V1().PersistentVolumes(),
 | 
				
			||||||
		ClaimInformer:             controllerContext.InformerFactory.Core().V1().PersistentVolumeClaims(),
 | 
							ClaimInformer:             controllerContext.InformerFactory.Core().V1().PersistentVolumeClaims(),
 | 
				
			||||||
		ClassInformer:             controllerContext.InformerFactory.Storage().V1().StorageClasses(),
 | 
							ClassInformer:             controllerContext.InformerFactory.Storage().V1().StorageClasses(),
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -156,7 +156,6 @@ type PersistentVolumeController struct {
 | 
				
			|||||||
	eventRecorder             record.EventRecorder
 | 
						eventRecorder             record.EventRecorder
 | 
				
			||||||
	volumePluginMgr           vol.VolumePluginMgr
 | 
						volumePluginMgr           vol.VolumePluginMgr
 | 
				
			||||||
	enableDynamicProvisioning bool
 | 
						enableDynamicProvisioning bool
 | 
				
			||||||
	clusterName               string
 | 
					 | 
				
			||||||
	resyncPeriod              time.Duration
 | 
						resyncPeriod              time.Duration
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Cache of the last known version of volumes and claims. This cache is
 | 
						// Cache of the last known version of volumes and claims. This cache is
 | 
				
			||||||
@@ -1642,7 +1641,6 @@ func (ctrl *PersistentVolumeController) provisionClaimOperation(
 | 
				
			|||||||
	options := vol.VolumeOptions{
 | 
						options := vol.VolumeOptions{
 | 
				
			||||||
		PersistentVolumeReclaimPolicy: *storageClass.ReclaimPolicy,
 | 
							PersistentVolumeReclaimPolicy: *storageClass.ReclaimPolicy,
 | 
				
			||||||
		MountOptions:                  storageClass.MountOptions,
 | 
							MountOptions:                  storageClass.MountOptions,
 | 
				
			||||||
		ClusterName:                   ctrl.clusterName,
 | 
					 | 
				
			||||||
		PVName:                        pvName,
 | 
							PVName:                        pvName,
 | 
				
			||||||
		PVC:                           claim,
 | 
							PVC:                           claim,
 | 
				
			||||||
		Parameters:                    storageClass.Parameters,
 | 
							Parameters:                    storageClass.Parameters,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -64,7 +64,6 @@ type ControllerParameters struct {
 | 
				
			|||||||
	KubeClient                clientset.Interface
 | 
						KubeClient                clientset.Interface
 | 
				
			||||||
	SyncPeriod                time.Duration
 | 
						SyncPeriod                time.Duration
 | 
				
			||||||
	VolumePlugins             []vol.VolumePlugin
 | 
						VolumePlugins             []vol.VolumePlugin
 | 
				
			||||||
	ClusterName               string
 | 
					 | 
				
			||||||
	VolumeInformer            coreinformers.PersistentVolumeInformer
 | 
						VolumeInformer            coreinformers.PersistentVolumeInformer
 | 
				
			||||||
	ClaimInformer             coreinformers.PersistentVolumeClaimInformer
 | 
						ClaimInformer             coreinformers.PersistentVolumeClaimInformer
 | 
				
			||||||
	ClassInformer             storageinformers.StorageClassInformer
 | 
						ClassInformer             storageinformers.StorageClassInformer
 | 
				
			||||||
@@ -86,7 +85,6 @@ func NewController(ctx context.Context, p ControllerParameters) (*PersistentVolu
 | 
				
			|||||||
		eventRecorder:                 eventRecorder,
 | 
							eventRecorder:                 eventRecorder,
 | 
				
			||||||
		runningOperations:             goroutinemap.NewGoRoutineMap(true /* exponentialBackOffOnError */),
 | 
							runningOperations:             goroutinemap.NewGoRoutineMap(true /* exponentialBackOffOnError */),
 | 
				
			||||||
		enableDynamicProvisioning:     p.EnableDynamicProvisioning,
 | 
							enableDynamicProvisioning:     p.EnableDynamicProvisioning,
 | 
				
			||||||
		clusterName:                   p.ClusterName,
 | 
					 | 
				
			||||||
		createProvisionedPVRetryCount: createProvisionedPVRetryCount,
 | 
							createProvisionedPVRetryCount: createProvisionedPVRetryCount,
 | 
				
			||||||
		createProvisionedPVInterval:   createProvisionedPVInterval,
 | 
							createProvisionedPVInterval:   createProvisionedPVInterval,
 | 
				
			||||||
		claimQueue:                    workqueue.NewTypedWithConfig(workqueue.TypedQueueConfig[string]{Name: "claims"}),
 | 
							claimQueue:                    workqueue.NewTypedWithConfig(workqueue.TypedQueueConfig[string]{Name: "claims"}),
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -82,8 +82,6 @@ type VolumeOptions struct {
 | 
				
			|||||||
	// i.e. with required capacity, accessMode, labels matching PVC.Selector and
 | 
						// i.e. with required capacity, accessMode, labels matching PVC.Selector and
 | 
				
			||||||
	// so on.
 | 
						// so on.
 | 
				
			||||||
	PVC *v1.PersistentVolumeClaim
 | 
						PVC *v1.PersistentVolumeClaim
 | 
				
			||||||
	// Unique name of Kubernetes cluster.
 | 
					 | 
				
			||||||
	ClusterName string
 | 
					 | 
				
			||||||
	// Volume provisioning parameters from StorageClass
 | 
						// Volume provisioning parameters from StorageClass
 | 
				
			||||||
	Parameters map[string]string
 | 
						Parameters map[string]string
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -200,22 +200,6 @@ func CalculateTimeoutForVolume(minimumTimeout, timeoutIncrement int, pv *v1.Pers
 | 
				
			|||||||
	return timeout
 | 
						return timeout
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// GenerateVolumeName returns a PV name with clusterName prefix. The function
 | 
					 | 
				
			||||||
// should be used to generate a name of GCE PD or Cinder volume. It basically
 | 
					 | 
				
			||||||
// adds "<clusterName>-dynamic-" before the PV name, making sure the resulting
 | 
					 | 
				
			||||||
// string fits given length and cuts "dynamic" if not.
 | 
					 | 
				
			||||||
func GenerateVolumeName(clusterName, pvName string, maxLength int) string {
 | 
					 | 
				
			||||||
	prefix := clusterName + "-dynamic"
 | 
					 | 
				
			||||||
	pvLen := len(pvName)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// cut the "<clusterName>-dynamic" to fit full pvName into maxLength
 | 
					 | 
				
			||||||
	// +1 for the '-' dash
 | 
					 | 
				
			||||||
	if pvLen+1+len(prefix) > maxLength {
 | 
					 | 
				
			||||||
		prefix = prefix[:maxLength-pvLen-1]
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return prefix + "-" + pvName
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// GetPath checks if the path from the mounter is empty.
 | 
					// GetPath checks if the path from the mounter is empty.
 | 
				
			||||||
func GetPath(mounter volume.Mounter) (string, error) {
 | 
					func GetPath(mounter volume.Mounter) (string, error) {
 | 
				
			||||||
	path := mounter.GetPath()
 | 
						path := mounter.GetPath()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,7 +20,6 @@ import (
 | 
				
			|||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"reflect"
 | 
						"reflect"
 | 
				
			||||||
	"runtime"
 | 
						"runtime"
 | 
				
			||||||
	"strings"
 | 
					 | 
				
			||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/google/go-cmp/cmp"
 | 
						"github.com/google/go-cmp/cmp"
 | 
				
			||||||
@@ -307,30 +306,6 @@ func TestFsUserFrom(t *testing.T) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestGenerateVolumeName(t *testing.T) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Normal operation, no truncate
 | 
					 | 
				
			||||||
	v1 := GenerateVolumeName("kubernetes", "pv-cinder-abcde", 255)
 | 
					 | 
				
			||||||
	if v1 != "kubernetes-dynamic-pv-cinder-abcde" {
 | 
					 | 
				
			||||||
		t.Errorf("Expected kubernetes-dynamic-pv-cinder-abcde, got %s", v1)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Truncate trailing "6789-dynamic"
 | 
					 | 
				
			||||||
	prefix := strings.Repeat("0123456789", 9) // 90 characters prefix + 8 chars. of "-dynamic"
 | 
					 | 
				
			||||||
	v2 := GenerateVolumeName(prefix, "pv-cinder-abcde", 100)
 | 
					 | 
				
			||||||
	expect := prefix[:84] + "-pv-cinder-abcde"
 | 
					 | 
				
			||||||
	if v2 != expect {
 | 
					 | 
				
			||||||
		t.Errorf("Expected %s, got %s", expect, v2)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Truncate really long cluster name
 | 
					 | 
				
			||||||
	prefix = strings.Repeat("0123456789", 1000) // 10000 characters prefix
 | 
					 | 
				
			||||||
	v3 := GenerateVolumeName(prefix, "pv-cinder-abcde", 100)
 | 
					 | 
				
			||||||
	if v3 != expect {
 | 
					 | 
				
			||||||
		t.Errorf("Expected %s, got %s", expect, v3)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func TestHasMountRefs(t *testing.T) {
 | 
					func TestHasMountRefs(t *testing.T) {
 | 
				
			||||||
	testCases := map[string]struct {
 | 
						testCases := map[string]struct {
 | 
				
			||||||
		mountPath string
 | 
							mountPath string
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -376,7 +376,6 @@ func createAdClients(ctx context.Context, t *testing.T, server *kubeapiservertes
 | 
				
			|||||||
		KubeClient:                testClient,
 | 
							KubeClient:                testClient,
 | 
				
			||||||
		SyncPeriod:                controllerOptions.PVClaimBinderSyncPeriod,
 | 
							SyncPeriod:                controllerOptions.PVClaimBinderSyncPeriod,
 | 
				
			||||||
		VolumePlugins:             plugins,
 | 
							VolumePlugins:             plugins,
 | 
				
			||||||
		ClusterName:               "volume-test-cluster",
 | 
					 | 
				
			||||||
		VolumeInformer:            informers.Core().V1().PersistentVolumes(),
 | 
							VolumeInformer:            informers.Core().V1().PersistentVolumes(),
 | 
				
			||||||
		ClaimInformer:             informers.Core().V1().PersistentVolumeClaims(),
 | 
							ClaimInformer:             informers.Core().V1().PersistentVolumeClaims(),
 | 
				
			||||||
		ClassInformer:             informers.Storage().V1().StorageClasses(),
 | 
							ClassInformer:             informers.Storage().V1().StorageClasses(),
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1111,7 +1111,6 @@ func initPVController(t *testing.T, testCtx *testutil.TestContext, provisionDela
 | 
				
			|||||||
		// https://github.com/kubernetes/kubernetes/issues/85320
 | 
							// https://github.com/kubernetes/kubernetes/issues/85320
 | 
				
			||||||
		SyncPeriod:                5 * time.Second,
 | 
							SyncPeriod:                5 * time.Second,
 | 
				
			||||||
		VolumePlugins:             plugins,
 | 
							VolumePlugins:             plugins,
 | 
				
			||||||
		ClusterName:               "volume-test-cluster",
 | 
					 | 
				
			||||||
		VolumeInformer:            informerFactory.Core().V1().PersistentVolumes(),
 | 
							VolumeInformer:            informerFactory.Core().V1().PersistentVolumes(),
 | 
				
			||||||
		ClaimInformer:             informerFactory.Core().V1().PersistentVolumeClaims(),
 | 
							ClaimInformer:             informerFactory.Core().V1().PersistentVolumeClaims(),
 | 
				
			||||||
		ClassInformer:             informerFactory.Storage().V1().StorageClasses(),
 | 
							ClassInformer:             informerFactory.Storage().V1().StorageClasses(),
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user