mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2026-01-08 16:21:50 +00:00
Merge pull request #100567 from jingxu97/mar/mark
Mark volume mount as uncertain in case of volume expansion fails
This commit is contained in:
@@ -81,6 +81,8 @@ const (
|
||||
// FailWithInUseVolumeName will cause NodeExpandVolume to result in FailedPrecondition error
|
||||
FailWithInUseVolumeName = "fail-expansion-in-use"
|
||||
|
||||
FailVolumeExpansion = "fail-expansion-test"
|
||||
|
||||
deviceNotMounted = "deviceNotMounted"
|
||||
deviceMountUncertain = "deviceMountUncertain"
|
||||
deviceMounted = "deviceMounted"
|
||||
@@ -467,6 +469,14 @@ func (plugin *FakeVolumePlugin) NodeExpand(resizeOptions NodeResizeOptions) (boo
|
||||
if resizeOptions.VolumeSpec.Name() == FailWithInUseVolumeName {
|
||||
return false, volumetypes.NewFailedPreconditionError("volume-in-use")
|
||||
}
|
||||
// Set up fakeVolumePlugin not support STAGE_UNSTAGE for testing the behavior
|
||||
// so as volume can be node published before we can resize
|
||||
if resizeOptions.CSIVolumePhase == volume.CSIVolumeStaged {
|
||||
return false, nil
|
||||
}
|
||||
if resizeOptions.CSIVolumePhase == volume.CSIVolumePublished && resizeOptions.VolumeSpec.Name() == FailVolumeExpansion {
|
||||
return false, fmt.Errorf("fail volume expansion for volume: %s", FailVolumeExpansion)
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -722,6 +722,14 @@ func (og *operationGenerator) GenerateMountVolumeFunc(
|
||||
if resizeError != nil {
|
||||
klog.Errorf("MountVolume.NodeExpandVolume failed with %v", resizeError)
|
||||
eventErr, detailedErr := volumeToMount.GenerateError("MountVolume.Setup failed while expanding volume", resizeError)
|
||||
// At this point, MountVolume.Setup already succeeded, we should add volume into actual state
|
||||
// so that reconciler can clean up volume when needed. However, volume resize failed,
|
||||
// we should not mark the volume as mounted to avoid pod starts using it.
|
||||
// Considering the above situations, we mark volume as uncertain here so that reconciler will tigger
|
||||
// volume tear down when pod is deleted, and also makes sure pod will not start using it.
|
||||
if err := actualStateOfWorld.MarkVolumeMountAsUncertain(markOpts); err != nil {
|
||||
klog.Errorf(volumeToMount.GenerateErrorDetailed("MountVolume.MarkVolumeMountAsUncertain failed", err).Error())
|
||||
}
|
||||
return volumetypes.NewOperationContext(eventErr, detailedErr, migrated)
|
||||
}
|
||||
}
|
||||
@@ -732,7 +740,6 @@ func (og *operationGenerator) GenerateMountVolumeFunc(
|
||||
eventErr, detailedErr := volumeToMount.GenerateError("MountVolume.MarkVolumeAsMounted failed", markVolMountedErr)
|
||||
return volumetypes.NewOperationContext(eventErr, detailedErr, migrated)
|
||||
}
|
||||
|
||||
return volumetypes.NewOperationContext(nil, nil, migrated)
|
||||
}
|
||||
|
||||
@@ -1198,6 +1205,14 @@ func (og *operationGenerator) GenerateMapVolumeFunc(
|
||||
if resizeError != nil {
|
||||
klog.Errorf("MapVolume.NodeExpandVolume failed with %v", resizeError)
|
||||
eventErr, detailedErr := volumeToMount.GenerateError("MapVolume.MarkVolumeAsMounted failed while expanding volume", resizeError)
|
||||
// At this point, MountVolume.Setup already succeeded, we should add volume into actual state
|
||||
// so that reconciler can clean up volume when needed. However, if nodeExpandVolume failed,
|
||||
// we should not mark the volume as mounted to avoid pod starts using it.
|
||||
// Considering the above situations, we mark volume as uncertain here so that reconciler will tigger
|
||||
// volume tear down when pod is deleted, and also makes sure pod will not start using it.
|
||||
if err := actualStateOfWorld.MarkVolumeMountAsUncertain(markVolumeOpts); err != nil {
|
||||
klog.Errorf(volumeToMount.GenerateErrorDetailed("MountVolume.MarkVolumeMountAsUncertain failed", err).Error())
|
||||
}
|
||||
return volumetypes.NewOperationContext(eventErr, detailedErr, migrated)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user