mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-06 10:43:56 +00:00
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:
parent
9325a57125
commit
45aa59946a
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user