@@ -39,7 +39,6 @@ import (
39
39
"k8s.io/client-go/util/workqueue"
40
40
cloudprovider "k8s.io/cloud-provider"
41
41
volerr "k8s.io/cloud-provider/volume/errors"
42
- csitranslation "k8s.io/csi-translation-lib"
43
42
v1helper "k8s.io/kubernetes/pkg/apis/core/v1/helper"
44
43
"k8s.io/kubernetes/pkg/controller/volume/events"
45
44
"k8s.io/kubernetes/pkg/controller/volume/persistentvolume/metrics"
@@ -134,6 +133,11 @@ const createProvisionedPVRetryCount = 5
134
133
// Interval between retries when we create a PV object for a provisioned volume.
135
134
const createProvisionedPVInterval = 10 * time .Second
136
135
136
+ // CSINameTranslator can get the CSI Driver name based on the in-tree plugin name
137
+ type CSINameTranslator interface {
138
+ GetCSINameFromInTreeName (pluginName string ) (string , error )
139
+ }
140
+
137
141
// PersistentVolumeController is a controller that synchronizes
138
142
// PersistentVolumeClaims and PersistentVolumes. It starts two
139
143
// cache.Controllers that watch PersistentVolume and PersistentVolumeClaim
@@ -200,10 +204,6 @@ type PersistentVolumeController struct {
200
204
createProvisionedPVRetryCount int
201
205
createProvisionedPVInterval time.Duration
202
206
203
- // For testing only: hook to intercept CSI driver name <=> Intree plugin name mapping
204
- // Not used when set to nil
205
- csiNameFromIntreeNameHook func (pluginName string ) (string , error )
206
-
207
207
// operationTimestamps caches start timestamp of operations
208
208
// (currently provision + binding/deletion) for metric recording.
209
209
// Detailed lifecyle/key for each operation
@@ -225,6 +225,8 @@ type PersistentVolumeController struct {
225
225
// the corresponding timestamp entry will be deleted from cache
226
226
// abort: N.A.
227
227
operationTimestamps metrics.OperationStartTimeCache
228
+
229
+ translator CSINameTranslator
228
230
}
229
231
230
232
// syncClaim is the main controller method to decide what to do with a claim.
@@ -1355,13 +1357,6 @@ func (ctrl *PersistentVolumeController) provisionClaim(claim *v1.PersistentVolum
1355
1357
return nil
1356
1358
}
1357
1359
1358
- func (ctrl * PersistentVolumeController ) getCSINameFromIntreeName (pluginName string ) (string , error ) {
1359
- if ctrl .csiNameFromIntreeNameHook != nil {
1360
- return ctrl .csiNameFromIntreeNameHook (pluginName )
1361
- }
1362
- return csitranslation .GetCSINameFromInTreeName (pluginName )
1363
- }
1364
-
1365
1360
// provisionClaimOperation provisions a volume. This method is running in
1366
1361
// standalone goroutine and already has all necessary locks.
1367
1362
func (ctrl * PersistentVolumeController ) provisionClaimOperation (
@@ -1571,7 +1566,7 @@ func (ctrl *PersistentVolumeController) provisionClaimOperationExternal(
1571
1566
provisionerName := storageClass .Provisioner
1572
1567
if plugin != nil {
1573
1568
// update the provisioner name to use the CSI in-tree name
1574
- provisionerName , err = ctrl .getCSINameFromIntreeName (storageClass .Provisioner )
1569
+ provisionerName , err = ctrl .translator . GetCSINameFromInTreeName (storageClass .Provisioner )
1575
1570
if err != nil {
1576
1571
strerr := fmt .Sprintf ("error getting CSI name for In tree plugin %s: %v" , storageClass .Provisioner , err )
1577
1572
klog .V (2 ).Infof ("%s" , strerr )
@@ -1732,7 +1727,7 @@ func (ctrl *PersistentVolumeController) getProvisionerNameFromVolume(volume *v1.
1732
1727
return "N/A"
1733
1728
}
1734
1729
if plugin != nil {
1735
- provisionerName , err := ctrl .getCSINameFromIntreeName (class .Provisioner )
1730
+ provisionerName , err := ctrl .translator . GetCSINameFromInTreeName (class .Provisioner )
1736
1731
if err == nil {
1737
1732
return provisionerName
1738
1733
}
@@ -1747,7 +1742,7 @@ func (ctrl *PersistentVolumeController) getProvisionerName(plugin vol.Provisiona
1747
1742
return plugin .GetPluginName ()
1748
1743
} else if plugin != nil {
1749
1744
// get the CSI in-tree name from storage class provisioner name
1750
- provisionerName , err := ctrl .getCSINameFromIntreeName (storageClass .Provisioner )
1745
+ provisionerName , err := ctrl .translator . GetCSINameFromInTreeName (storageClass .Provisioner )
1751
1746
if err != nil {
1752
1747
return "N/A"
1753
1748
}
0 commit comments