mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 21:47:07 +00:00
Merge pull request #75986 from mucahitkurt/improvement/reduce-event-spam-for-GenerateAttachVolumeFunc
Reduce event spam for function GenerateAttachVolumeFunc
This commit is contained in:
commit
88992ba185
@ -598,11 +598,8 @@ func (oe *operationExecutor) IsOperationPending(volumeName v1.UniqueVolumeName,
|
|||||||
func (oe *operationExecutor) AttachVolume(
|
func (oe *operationExecutor) AttachVolume(
|
||||||
volumeToAttach VolumeToAttach,
|
volumeToAttach VolumeToAttach,
|
||||||
actualStateOfWorld ActualStateOfWorldAttacherUpdater) error {
|
actualStateOfWorld ActualStateOfWorldAttacherUpdater) error {
|
||||||
generatedOperations, err :=
|
generatedOperations :=
|
||||||
oe.operationGenerator.GenerateAttachVolumeFunc(volumeToAttach, actualStateOfWorld)
|
oe.operationGenerator.GenerateAttachVolumeFunc(volumeToAttach, actualStateOfWorld)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return oe.pendingOperations.Run(
|
return oe.pendingOperations.Run(
|
||||||
volumeToAttach.VolumeName, "" /* podName */, generatedOperations)
|
volumeToAttach.VolumeName, "" /* podName */, generatedOperations)
|
||||||
|
@ -407,14 +407,14 @@ func (fopg *fakeOperationGenerator) GenerateUnmountVolumeFunc(volumeToUnmount Mo
|
|||||||
OperationFunc: opFunc,
|
OperationFunc: opFunc,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
func (fopg *fakeOperationGenerator) GenerateAttachVolumeFunc(volumeToAttach VolumeToAttach, actualStateOfWorld ActualStateOfWorldAttacherUpdater) (volumetypes.GeneratedOperations, error) {
|
func (fopg *fakeOperationGenerator) GenerateAttachVolumeFunc(volumeToAttach VolumeToAttach, actualStateOfWorld ActualStateOfWorldAttacherUpdater) volumetypes.GeneratedOperations {
|
||||||
opFunc := func() (error, error) {
|
opFunc := func() (error, error) {
|
||||||
startOperationAndBlock(fopg.ch, fopg.quit)
|
startOperationAndBlock(fopg.ch, fopg.quit)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
return volumetypes.GeneratedOperations{
|
return volumetypes.GeneratedOperations{
|
||||||
OperationFunc: opFunc,
|
OperationFunc: opFunc,
|
||||||
}, nil
|
}
|
||||||
}
|
}
|
||||||
func (fopg *fakeOperationGenerator) GenerateDetachVolumeFunc(volumeToDetach AttachedVolume, verifySafeToDetach bool, actualStateOfWorld ActualStateOfWorldAttacherUpdater) (volumetypes.GeneratedOperations, error) {
|
func (fopg *fakeOperationGenerator) GenerateDetachVolumeFunc(volumeToDetach AttachedVolume, verifySafeToDetach bool, actualStateOfWorld ActualStateOfWorldAttacherUpdater) (volumetypes.GeneratedOperations, error) {
|
||||||
opFunc := func() (error, error) {
|
opFunc := func() (error, error) {
|
||||||
|
@ -46,7 +46,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
unknownVolumePlugin string = "UnknownVolumePlugin"
|
unknownVolumePlugin string = "UnknownVolumePlugin"
|
||||||
|
unknownAttachableVolumePlugin string = "UnknownAttachableVolumePlugin"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ OperationGenerator = &operationGenerator{}
|
var _ OperationGenerator = &operationGenerator{}
|
||||||
@ -97,7 +98,7 @@ type OperationGenerator interface {
|
|||||||
GenerateUnmountVolumeFunc(volumeToUnmount MountedVolume, actualStateOfWorld ActualStateOfWorldMounterUpdater, podsDir string) (volumetypes.GeneratedOperations, error)
|
GenerateUnmountVolumeFunc(volumeToUnmount MountedVolume, actualStateOfWorld ActualStateOfWorldMounterUpdater, podsDir string) (volumetypes.GeneratedOperations, error)
|
||||||
|
|
||||||
// Generates the AttachVolume function needed to perform attach of a volume plugin
|
// Generates the AttachVolume function needed to perform attach of a volume plugin
|
||||||
GenerateAttachVolumeFunc(volumeToAttach VolumeToAttach, actualStateOfWorld ActualStateOfWorldAttacherUpdater) (volumetypes.GeneratedOperations, error)
|
GenerateAttachVolumeFunc(volumeToAttach VolumeToAttach, actualStateOfWorld ActualStateOfWorldAttacherUpdater) volumetypes.GeneratedOperations
|
||||||
|
|
||||||
// Generates the DetachVolume function needed to perform the detach of a volume plugin
|
// Generates the DetachVolume function needed to perform the detach of a volume plugin
|
||||||
GenerateDetachVolumeFunc(volumeToDetach AttachedVolume, verifySafeToDetach bool, actualStateOfWorld ActualStateOfWorldAttacherUpdater) (volumetypes.GeneratedOperations, error)
|
GenerateDetachVolumeFunc(volumeToDetach AttachedVolume, verifySafeToDetach bool, actualStateOfWorld ActualStateOfWorldAttacherUpdater) (volumetypes.GeneratedOperations, error)
|
||||||
@ -293,57 +294,41 @@ func (og *operationGenerator) GenerateBulkVolumeVerifyFunc(
|
|||||||
|
|
||||||
func (og *operationGenerator) GenerateAttachVolumeFunc(
|
func (og *operationGenerator) GenerateAttachVolumeFunc(
|
||||||
volumeToAttach VolumeToAttach,
|
volumeToAttach VolumeToAttach,
|
||||||
actualStateOfWorld ActualStateOfWorldAttacherUpdater) (volumetypes.GeneratedOperations, error) {
|
actualStateOfWorld ActualStateOfWorldAttacherUpdater) volumetypes.GeneratedOperations {
|
||||||
var err error
|
attachVolumeFunc := func() (error, error) {
|
||||||
var attachableVolumePlugin volume.AttachableVolumePlugin
|
var attachableVolumePlugin volume.AttachableVolumePlugin
|
||||||
|
originalSpec := volumeToAttach.VolumeSpec
|
||||||
|
nu, err := nodeUsingCSIPlugin(og, volumeToAttach.VolumeSpec, volumeToAttach.NodeName)
|
||||||
|
if err != nil {
|
||||||
|
return volumeToAttach.GenerateError("AttachVolume.NodeUsingCSIPlugin failed", err)
|
||||||
|
}
|
||||||
|
|
||||||
// Get attacher plugin
|
// useCSIPlugin will check both CSIMigration and the plugin specific feature gate
|
||||||
eventRecorderFunc := func(err *error) {
|
if useCSIPlugin(og.volumePluginMgr, volumeToAttach.VolumeSpec) && nu {
|
||||||
if *err != nil {
|
// The volume represented by this spec is CSI and thus should be migrated
|
||||||
for _, pod := range volumeToAttach.ScheduledPods {
|
attachableVolumePlugin, err = og.volumePluginMgr.FindAttachablePluginByName(csi.CSIPluginName)
|
||||||
og.recorder.Eventf(pod, v1.EventTypeWarning, kevents.FailedAttachVolume, (*err).Error())
|
if err != nil || attachableVolumePlugin == nil {
|
||||||
|
return volumeToAttach.GenerateError("AttachVolume.FindAttachablePluginByName failed", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
csiSpec, err := translateSpec(volumeToAttach.VolumeSpec)
|
||||||
|
if err != nil {
|
||||||
|
return volumeToAttach.GenerateError("AttachVolume.TranslateSpec failed", err)
|
||||||
|
}
|
||||||
|
volumeToAttach.VolumeSpec = csiSpec
|
||||||
|
} else {
|
||||||
|
attachableVolumePlugin, err =
|
||||||
|
og.volumePluginMgr.FindAttachablePluginBySpec(volumeToAttach.VolumeSpec)
|
||||||
|
if err != nil || attachableVolumePlugin == nil {
|
||||||
|
return volumeToAttach.GenerateError("AttachVolume.FindAttachablePluginBySpec failed", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
originalSpec := volumeToAttach.VolumeSpec
|
volumeAttacher, newAttacherErr := attachableVolumePlugin.NewAttacher()
|
||||||
nu, err := nodeUsingCSIPlugin(og, volumeToAttach.VolumeSpec, volumeToAttach.NodeName)
|
if newAttacherErr != nil {
|
||||||
if err != nil {
|
return volumeToAttach.GenerateError("AttachVolume.NewAttacher failed", newAttacherErr)
|
||||||
eventRecorderFunc(&err)
|
|
||||||
return volumetypes.GeneratedOperations{}, volumeToAttach.GenerateErrorDetailed("AttachVolume.NodeUsingCSIPlugin failed", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// useCSIPlugin will check both CSIMigration and the plugin specific feature gate
|
|
||||||
if useCSIPlugin(og.volumePluginMgr, volumeToAttach.VolumeSpec) && nu {
|
|
||||||
// The volume represented by this spec is CSI and thus should be migrated
|
|
||||||
attachableVolumePlugin, err = og.volumePluginMgr.FindAttachablePluginByName(csi.CSIPluginName)
|
|
||||||
if err != nil || attachableVolumePlugin == nil {
|
|
||||||
eventRecorderFunc(&err)
|
|
||||||
return volumetypes.GeneratedOperations{}, volumeToAttach.GenerateErrorDetailed("AttachVolume.FindAttachablePluginByName failed", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
csiSpec, err := translateSpec(volumeToAttach.VolumeSpec)
|
|
||||||
if err != nil {
|
|
||||||
return volumetypes.GeneratedOperations{}, volumeToAttach.GenerateErrorDetailed("AttachVolume.TranslateSpec failed", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
volumeToAttach.VolumeSpec = csiSpec
|
|
||||||
} else {
|
|
||||||
attachableVolumePlugin, err =
|
|
||||||
og.volumePluginMgr.FindAttachablePluginBySpec(volumeToAttach.VolumeSpec)
|
|
||||||
if err != nil || attachableVolumePlugin == nil {
|
|
||||||
eventRecorderFunc(&err)
|
|
||||||
return volumetypes.GeneratedOperations{}, volumeToAttach.GenerateErrorDetailed("AttachVolume.FindAttachablePluginBySpec failed", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
volumeAttacher, newAttacherErr := attachableVolumePlugin.NewAttacher()
|
|
||||||
if newAttacherErr != nil {
|
|
||||||
eventRecorderFunc(&err)
|
|
||||||
return volumetypes.GeneratedOperations{}, volumeToAttach.GenerateErrorDetailed("AttachVolume.NewAttacher failed", newAttacherErr)
|
|
||||||
}
|
|
||||||
|
|
||||||
attachVolumeFunc := func() (error, error) {
|
|
||||||
// Execute attach
|
// Execute attach
|
||||||
devicePath, attachErr := volumeAttacher.Attach(
|
devicePath, attachErr := volumeAttacher.Attach(
|
||||||
volumeToAttach.VolumeSpec, volumeToAttach.NodeName)
|
volumeToAttach.VolumeSpec, volumeToAttach.NodeName)
|
||||||
@ -389,12 +374,32 @@ func (og *operationGenerator) GenerateAttachVolumeFunc(
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
eventRecorderFunc := func(err *error) {
|
||||||
|
if *err != nil {
|
||||||
|
for _, pod := range volumeToAttach.ScheduledPods {
|
||||||
|
og.recorder.Eventf(pod, v1.EventTypeWarning, kevents.FailedAttachVolume, (*err).Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get attacher plugin
|
||||||
|
attachableVolumePluginName := unknownAttachableVolumePlugin
|
||||||
|
attachableVolumePlugin, err :=
|
||||||
|
og.volumePluginMgr.FindAttachablePluginBySpec(volumeToAttach.VolumeSpec)
|
||||||
|
// It's ok to ignore the error, returning error is not expected from this function.
|
||||||
|
// If an error case occurred during the function generation, this error case(skipped one) will also trigger an error
|
||||||
|
// while the generated function is executed. And those errors will be handled during the execution of the generated
|
||||||
|
// function with a back off policy.
|
||||||
|
if err == nil && attachableVolumePlugin != nil {
|
||||||
|
attachableVolumePluginName = attachableVolumePlugin.GetPluginName()
|
||||||
|
}
|
||||||
|
|
||||||
return volumetypes.GeneratedOperations{
|
return volumetypes.GeneratedOperations{
|
||||||
OperationName: "volume_attach",
|
OperationName: "volume_attach",
|
||||||
OperationFunc: attachVolumeFunc,
|
OperationFunc: attachVolumeFunc,
|
||||||
EventRecorderFunc: eventRecorderFunc,
|
EventRecorderFunc: eventRecorderFunc,
|
||||||
CompleteFunc: util.OperationCompleteHook(util.GetFullQualifiedPluginNameForVolume(attachableVolumePlugin.GetPluginName(), volumeToAttach.VolumeSpec), "volume_attach"),
|
CompleteFunc: util.OperationCompleteHook(util.GetFullQualifiedPluginNameForVolume(attachableVolumePluginName, volumeToAttach.VolumeSpec), "volume_attach"),
|
||||||
}, nil
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (og *operationGenerator) GetVolumePluginMgr() *volume.VolumePluginMgr {
|
func (og *operationGenerator) GetVolumePluginMgr() *volume.VolumePluginMgr {
|
||||||
|
Loading…
Reference in New Issue
Block a user