mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 23:17:50 +00:00
PV Controller changes to support provisioning in CSI Migration scenarios
Signed-off-by: Deep Debroy <ddebroy@docker.com>
This commit is contained in:
@@ -39,6 +39,7 @@ import (
|
||||
"k8s.io/client-go/util/workqueue"
|
||||
cloudprovider "k8s.io/cloud-provider"
|
||||
volerr "k8s.io/cloud-provider/volume/errors"
|
||||
csitranslation "k8s.io/csi-translation-lib"
|
||||
v1helper "k8s.io/kubernetes/pkg/apis/core/v1/helper"
|
||||
"k8s.io/kubernetes/pkg/controller/volume/events"
|
||||
"k8s.io/kubernetes/pkg/controller/volume/persistentvolume/metrics"
|
||||
@@ -230,6 +231,10 @@ type PersistentVolumeController struct {
|
||||
|
||||
createProvisionedPVRetryCount int
|
||||
createProvisionedPVInterval time.Duration
|
||||
|
||||
// For testing only: hook to intercept CSI driver name <=> Intree plugin name mapping
|
||||
// Not used when set to nil
|
||||
csiNameFromIntreeNameHook func(pluginName string) (string, error)
|
||||
}
|
||||
|
||||
// syncClaim is the main controller method to decide what to do with a claim.
|
||||
@@ -1346,6 +1351,13 @@ func (ctrl *PersistentVolumeController) provisionClaim(claim *v1.PersistentVolum
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ctrl *PersistentVolumeController) getCSINameFromIntreeName(pluginName string) (string, error) {
|
||||
if ctrl.csiNameFromIntreeNameHook != nil {
|
||||
return ctrl.csiNameFromIntreeNameHook(pluginName)
|
||||
}
|
||||
return csitranslation.GetCSINameFromIntreeName(pluginName)
|
||||
}
|
||||
|
||||
// provisionClaimOperation provisions a volume. This method is running in
|
||||
// standalone goroutine and already has all necessary locks.
|
||||
func (ctrl *PersistentVolumeController) provisionClaimOperation(claim *v1.PersistentVolumeClaim) (string, error) {
|
||||
@@ -1362,12 +1374,26 @@ func (ctrl *PersistentVolumeController) provisionClaimOperation(claim *v1.Persis
|
||||
}
|
||||
|
||||
var pluginName string
|
||||
provisionerName := storageClass.Provisioner
|
||||
if plugin != nil {
|
||||
pluginName = plugin.GetPluginName()
|
||||
if plugin.IsMigratedToCSI() {
|
||||
// pluginName is not set here to align with existing behavior
|
||||
// of not setting pluginName for external provisioners (including CSI)
|
||||
// Set provisionerName to CSI plugin name for setClaimProvisioner
|
||||
provisionerName, err = ctrl.getCSINameFromIntreeName(storageClass.Provisioner)
|
||||
if err != nil {
|
||||
strerr := fmt.Sprintf("error getting CSI name for In tree plugin %s: %v", storageClass.Provisioner, err)
|
||||
klog.V(2).Infof("%s", strerr)
|
||||
ctrl.eventRecorder.Event(claim, v1.EventTypeWarning, events.ProvisioningFailed, strerr)
|
||||
return "", err
|
||||
}
|
||||
} else {
|
||||
pluginName = plugin.GetPluginName()
|
||||
}
|
||||
}
|
||||
|
||||
// Add provisioner annotation so external provisioners know when to start
|
||||
newClaim, err := ctrl.setClaimProvisioner(claim, storageClass)
|
||||
newClaim, err := ctrl.setClaimProvisioner(claim, provisionerName)
|
||||
if err != nil {
|
||||
// Save failed, the controller will retry in the next sync
|
||||
klog.V(2).Infof("error saving claim %s: %v", claimToClaimKey(claim), err)
|
||||
@@ -1375,7 +1401,7 @@ func (ctrl *PersistentVolumeController) provisionClaimOperation(claim *v1.Persis
|
||||
}
|
||||
claim = newClaim
|
||||
|
||||
if plugin == nil {
|
||||
if plugin == nil || plugin.IsMigratedToCSI() {
|
||||
// findProvisionablePlugin returned no error nor plugin.
|
||||
// This means that an unknown provisioner is requested. Report an event
|
||||
// and wait for the external provisioner
|
||||
|
||||
Reference in New Issue
Block a user