mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Implement CSI migration logic for block volume
This commit is contained in:
parent
6f9bf5fe98
commit
f7050a04ce
@ -542,7 +542,7 @@ func (og *operationGenerator) GenerateMountVolumeFunc(
|
|||||||
return volumeToMount.GenerateError("MountVolume.FindPluginBySpec failed", err)
|
return volumeToMount.GenerateError("MountVolume.FindPluginBySpec failed", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
affinityErr := checkNodeAffinity(og, volumeToMount, volumePlugin)
|
affinityErr := checkNodeAffinity(og, volumeToMount)
|
||||||
if affinityErr != nil {
|
if affinityErr != nil {
|
||||||
return volumeToMount.GenerateError("MountVolume.NodeAffinity check failed", affinityErr)
|
return volumeToMount.GenerateError("MountVolume.NodeAffinity check failed", affinityErr)
|
||||||
}
|
}
|
||||||
@ -945,17 +945,29 @@ func (og *operationGenerator) GenerateMapVolumeFunc(
|
|||||||
volumeToMount VolumeToMount,
|
volumeToMount VolumeToMount,
|
||||||
actualStateOfWorld ActualStateOfWorldMounterUpdater) (volumetypes.GeneratedOperations, error) {
|
actualStateOfWorld ActualStateOfWorldMounterUpdater) (volumetypes.GeneratedOperations, error) {
|
||||||
|
|
||||||
|
originalSpec := volumeToMount.VolumeSpec
|
||||||
|
// Translate to CSI spec if migration enabled
|
||||||
|
if useCSIPlugin(og.volumePluginMgr, originalSpec) {
|
||||||
|
csiSpec, err := translateSpec(originalSpec)
|
||||||
|
if err != nil {
|
||||||
|
return volumetypes.GeneratedOperations{}, volumeToMount.GenerateErrorDetailed("MapVolume.TranslateSpec failed", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
volumeToMount.VolumeSpec = csiSpec
|
||||||
|
}
|
||||||
|
|
||||||
// Get block volume mapper plugin
|
// Get block volume mapper plugin
|
||||||
var blockVolumeMapper volume.BlockVolumeMapper
|
|
||||||
blockVolumePlugin, err :=
|
blockVolumePlugin, err :=
|
||||||
og.volumePluginMgr.FindMapperPluginBySpec(volumeToMount.VolumeSpec)
|
og.volumePluginMgr.FindMapperPluginBySpec(volumeToMount.VolumeSpec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return volumetypes.GeneratedOperations{}, volumeToMount.GenerateErrorDetailed("MapVolume.FindMapperPluginBySpec failed", err)
|
return volumetypes.GeneratedOperations{}, volumeToMount.GenerateErrorDetailed("MapVolume.FindMapperPluginBySpec failed", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if blockVolumePlugin == nil {
|
if blockVolumePlugin == nil {
|
||||||
return volumetypes.GeneratedOperations{}, volumeToMount.GenerateErrorDetailed("MapVolume.FindMapperPluginBySpec failed to find BlockVolumeMapper plugin. Volume plugin is nil.", nil)
|
return volumetypes.GeneratedOperations{}, volumeToMount.GenerateErrorDetailed("MapVolume.FindMapperPluginBySpec failed to find BlockVolumeMapper plugin. Volume plugin is nil.", nil)
|
||||||
}
|
}
|
||||||
affinityErr := checkNodeAffinity(og, volumeToMount, blockVolumePlugin)
|
|
||||||
|
affinityErr := checkNodeAffinity(og, volumeToMount)
|
||||||
if affinityErr != nil {
|
if affinityErr != nil {
|
||||||
eventErr, detailedErr := volumeToMount.GenerateError("MapVolume.NodeAffinity check failed", affinityErr)
|
eventErr, detailedErr := volumeToMount.GenerateError("MapVolume.NodeAffinity check failed", affinityErr)
|
||||||
og.recorder.Eventf(volumeToMount.Pod, v1.EventTypeWarning, kevents.FailedMountVolume, eventErr.Error())
|
og.recorder.Eventf(volumeToMount.Pod, v1.EventTypeWarning, kevents.FailedMountVolume, eventErr.Error())
|
||||||
@ -1074,7 +1086,7 @@ func (og *operationGenerator) GenerateMapVolumeFunc(
|
|||||||
blockVolumeMapper,
|
blockVolumeMapper,
|
||||||
volumeToMount.OuterVolumeSpecName,
|
volumeToMount.OuterVolumeSpecName,
|
||||||
volumeToMount.VolumeGidValue,
|
volumeToMount.VolumeGidValue,
|
||||||
volumeToMount.VolumeSpec)
|
originalSpec)
|
||||||
if markVolMountedErr != nil {
|
if markVolMountedErr != nil {
|
||||||
// On failure, return error. Caller will log and retry.
|
// On failure, return error. Caller will log and retry.
|
||||||
return volumeToMount.GenerateError("MapVolume.MarkVolumeAsMounted failed", markVolMountedErr)
|
return volumeToMount.GenerateError("MapVolume.MarkVolumeAsMounted failed", markVolMountedErr)
|
||||||
@ -1104,13 +1116,32 @@ func (og *operationGenerator) GenerateUnmapVolumeFunc(
|
|||||||
volumeToUnmount MountedVolume,
|
volumeToUnmount MountedVolume,
|
||||||
actualStateOfWorld ActualStateOfWorldMounterUpdater) (volumetypes.GeneratedOperations, error) {
|
actualStateOfWorld ActualStateOfWorldMounterUpdater) (volumetypes.GeneratedOperations, error) {
|
||||||
|
|
||||||
// Get block volume unmapper plugin
|
var blockVolumePlugin volume.BlockVolumePlugin
|
||||||
var blockVolumeUnmapper volume.BlockVolumeUnmapper
|
var err error
|
||||||
blockVolumePlugin, err :=
|
// Translate to CSI spec if migration enabled
|
||||||
|
// And get block volume unmapper plugin
|
||||||
|
if volumeToUnmount.VolumeSpec != nil && useCSIPlugin(og.volumePluginMgr, volumeToUnmount.VolumeSpec) {
|
||||||
|
csiSpec, err := translateSpec(volumeToUnmount.VolumeSpec)
|
||||||
|
if err != nil {
|
||||||
|
return volumetypes.GeneratedOperations{}, volumeToUnmount.GenerateErrorDetailed("UnmapVolume.TranslateSpec failed", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
volumeToUnmount.VolumeSpec = csiSpec
|
||||||
|
|
||||||
|
blockVolumePlugin, err =
|
||||||
|
og.volumePluginMgr.FindMapperPluginByName(csi.CSIPluginName)
|
||||||
|
if err != nil {
|
||||||
|
return volumetypes.GeneratedOperations{}, volumeToUnmount.GenerateErrorDetailed("UnmapVolume.FindMapperPluginByName failed", err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
blockVolumePlugin, err =
|
||||||
og.volumePluginMgr.FindMapperPluginByName(volumeToUnmount.PluginName)
|
og.volumePluginMgr.FindMapperPluginByName(volumeToUnmount.PluginName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return volumetypes.GeneratedOperations{}, volumeToUnmount.GenerateErrorDetailed("UnmapVolume.FindMapperPluginByName failed", err)
|
return volumetypes.GeneratedOperations{}, volumeToUnmount.GenerateErrorDetailed("UnmapVolume.FindMapperPluginByName failed", err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var blockVolumeUnmapper volume.BlockVolumeUnmapper
|
||||||
if blockVolumePlugin == nil {
|
if blockVolumePlugin == nil {
|
||||||
return volumetypes.GeneratedOperations{}, volumeToUnmount.GenerateErrorDetailed("UnmapVolume.FindMapperPluginByName failed to find BlockVolumeMapper plugin. Volume plugin is nil.", nil)
|
return volumetypes.GeneratedOperations{}, volumeToUnmount.GenerateErrorDetailed("UnmapVolume.FindMapperPluginByName failed to find BlockVolumeMapper plugin. Volume plugin is nil.", nil)
|
||||||
}
|
}
|
||||||
@ -1181,11 +1212,29 @@ func (og *operationGenerator) GenerateUnmapDeviceFunc(
|
|||||||
actualStateOfWorld ActualStateOfWorldMounterUpdater,
|
actualStateOfWorld ActualStateOfWorldMounterUpdater,
|
||||||
mounter mount.Interface) (volumetypes.GeneratedOperations, error) {
|
mounter mount.Interface) (volumetypes.GeneratedOperations, error) {
|
||||||
|
|
||||||
blockVolumePlugin, err :=
|
var blockVolumePlugin volume.BlockVolumePlugin
|
||||||
|
var err error
|
||||||
|
// Translate to CSI spec if migration enabled
|
||||||
|
if useCSIPlugin(og.volumePluginMgr, deviceToDetach.VolumeSpec) {
|
||||||
|
csiSpec, err := translateSpec(deviceToDetach.VolumeSpec)
|
||||||
|
if err != nil {
|
||||||
|
return volumetypes.GeneratedOperations{}, deviceToDetach.GenerateErrorDetailed("UnmapDevice.TranslateSpec failed", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
deviceToDetach.VolumeSpec = csiSpec
|
||||||
|
blockVolumePlugin, err =
|
||||||
|
og.volumePluginMgr.FindMapperPluginByName(csi.CSIPluginName)
|
||||||
|
if err != nil {
|
||||||
|
return volumetypes.GeneratedOperations{}, deviceToDetach.GenerateErrorDetailed("UnmapDevice.FindMapperPluginByName failed", err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
blockVolumePlugin, err =
|
||||||
og.volumePluginMgr.FindMapperPluginByName(deviceToDetach.PluginName)
|
og.volumePluginMgr.FindMapperPluginByName(deviceToDetach.PluginName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return volumetypes.GeneratedOperations{}, deviceToDetach.GenerateErrorDetailed("UnmapDevice.FindMapperPluginByName failed", err)
|
return volumetypes.GeneratedOperations{}, deviceToDetach.GenerateErrorDetailed("UnmapDevice.FindMapperPluginByName failed", err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if blockVolumePlugin == nil {
|
if blockVolumePlugin == nil {
|
||||||
return volumetypes.GeneratedOperations{}, deviceToDetach.GenerateErrorDetailed("UnmapDevice.FindMapperPluginByName failed to find BlockVolumeMapper plugin. Volume plugin is nil.", nil)
|
return volumetypes.GeneratedOperations{}, deviceToDetach.GenerateErrorDetailed("UnmapDevice.FindMapperPluginByName failed to find BlockVolumeMapper plugin. Volume plugin is nil.", nil)
|
||||||
}
|
}
|
||||||
@ -1578,7 +1627,7 @@ func checkMountOptionSupport(og *operationGenerator, volumeToMount VolumeToMount
|
|||||||
|
|
||||||
// checkNodeAffinity looks at the PV node affinity, and checks if the node has the same corresponding labels
|
// checkNodeAffinity looks at the PV node affinity, and checks if the node has the same corresponding labels
|
||||||
// This ensures that we don't mount a volume that doesn't belong to this node
|
// This ensures that we don't mount a volume that doesn't belong to this node
|
||||||
func checkNodeAffinity(og *operationGenerator, volumeToMount VolumeToMount, plugin volume.VolumePlugin) error {
|
func checkNodeAffinity(og *operationGenerator, volumeToMount VolumeToMount) error {
|
||||||
if !utilfeature.DefaultFeatureGate.Enabled(features.PersistentLocalVolumes) {
|
if !utilfeature.DefaultFeatureGate.Enabled(features.PersistentLocalVolumes) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user