Refactor FindAttachablePluginBySpec out of CSI code path

reconstructVolume() is called when kubelet may not have connection to the
API server yet, therefore it cannot get CSIDriver instances to figure out
if a CSI volume is attachable or not.

Refactor reconstructVolume(), so it does not need
FindAttachablePluginBySpec for CSI volumes, because all of them are
deviceMountable (i.e. FindDeviceMountablePluginBySpec always returns the
CSI volume plugin).
This commit is contained in:
Jan Safranek 2023-05-05 12:36:34 +02:00
parent 9325a57125
commit 45aa59946a

View File

@ -236,17 +236,28 @@ func (rc *reconciler) reconstructVolume(volume podVolume) (rvolume *reconstructe
// Searching by spec checks whether the volume is actually attachable
// (i.e. has a PV) whereas searching by plugin name can only tell whether
// the plugin supports attachable volumes.
attachablePlugin, err := rc.volumePluginMgr.FindAttachablePluginBySpec(volumeSpec)
if err != nil {
return nil, err
}
deviceMountablePlugin, err := rc.volumePluginMgr.FindDeviceMountablePluginBySpec(volumeSpec)
if err != nil {
return nil, err
}
// The unique volume name used depends on whether the volume is attachable/device-mountable
// (needsNameFromSpec = true) or not.
needsNameFromSpec := deviceMountablePlugin != nil
if !needsNameFromSpec {
// Check attach-ability of a volume only as a fallback to avoid calling
// FindAttachablePluginBySpec for CSI volumes - it needs a connection to the API server,
// but it may not be available at this stage of kubelet startup.
// All CSI volumes are device-mountable, so they won't reach this code.
attachablePlugin, err := rc.volumePluginMgr.FindAttachablePluginBySpec(volumeSpec)
if err != nil {
return nil, err
}
needsNameFromSpec = attachablePlugin != nil
}
var uniqueVolumeName v1.UniqueVolumeName
if attachablePlugin != nil || deviceMountablePlugin != nil {
if needsNameFromSpec {
uniqueVolumeName, err = util.GetUniqueVolumeNameFromSpec(plugin, volumeSpec)
if err != nil {
return nil, err