-
Notifications
You must be signed in to change notification settings - Fork 38.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce CSI log and event spam #71581
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,10 @@ import ( | |
"k8s.io/kubernetes/pkg/volume/util/volumepathhandler" | ||
) | ||
|
||
const ( | ||
unknownVolumePlugin string = "UnknownVolumePlugin" | ||
) | ||
|
||
var _ OperationGenerator = &operationGenerator{} | ||
|
||
type operationGenerator struct { | ||
|
@@ -82,7 +86,7 @@ func NewOperationGenerator(kubeClient clientset.Interface, | |
// OperationGenerator interface that extracts out the functions from operation_executor to make it dependency injectable | ||
type OperationGenerator interface { | ||
// Generates the MountVolume function needed to perform the mount of a volume plugin | ||
GenerateMountVolumeFunc(waitForAttachTimeout time.Duration, volumeToMount VolumeToMount, actualStateOfWorldMounterUpdater ActualStateOfWorldMounterUpdater, isRemount bool) (volumetypes.GeneratedOperations, error) | ||
GenerateMountVolumeFunc(waitForAttachTimeout time.Duration, volumeToMount VolumeToMount, actualStateOfWorldMounterUpdater ActualStateOfWorldMounterUpdater, isRemount bool) volumetypes.GeneratedOperations | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note for other reviewers: helpful to turn on "Hide whitespace changes" in github diff settings |
||
|
||
// Generates the UnmountVolume function needed to perform the unmount of a volume plugin | ||
GenerateUnmountVolumeFunc(volumeToUnmount MountedVolume, actualStateOfWorld ActualStateOfWorldMounterUpdater, podsDir string) (volumetypes.GeneratedOperations, error) | ||
|
@@ -436,61 +440,61 @@ func (og *operationGenerator) GenerateMountVolumeFunc( | |
waitForAttachTimeout time.Duration, | ||
volumeToMount VolumeToMount, | ||
actualStateOfWorld ActualStateOfWorldMounterUpdater, | ||
isRemount bool) (volumetypes.GeneratedOperations, error) { | ||
isRemount bool) volumetypes.GeneratedOperations { | ||
// Get mounter plugin | ||
volumePluginName := unknownVolumePlugin | ||
volumePlugin, err := | ||
og.volumePluginMgr.FindPluginBySpec(volumeToMount.VolumeSpec) | ||
if err != nil || volumePlugin == nil { | ||
return volumetypes.GeneratedOperations{}, volumeToMount.GenerateErrorDetailed("MountVolume.FindPluginBySpec failed", err) | ||
if err == nil && volumePlugin != nil { | ||
volumePluginName = volumePlugin.GetPluginName() | ||
} | ||
|
||
affinityErr := checkNodeAffinity(og, volumeToMount, volumePlugin) | ||
if affinityErr != nil { | ||
eventErr, detailedErr := volumeToMount.GenerateError("MountVolume.NodeAffinity check failed", affinityErr) | ||
og.recorder.Eventf(volumeToMount.Pod, v1.EventTypeWarning, kevents.FailedMountVolume, eventErr.Error()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does anyone log an event? Or did we decide it was just spammy? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes these errors will still generate logs and events, but they are now be protected by the backoff mechanism so they're not created every 100 ms -- it will quickly back off to once every two minutes. |
||
return volumetypes.GeneratedOperations{}, detailedErr | ||
} | ||
mountVolumeFunc := func() (error, error) { | ||
if err != nil || volumePlugin == nil { | ||
return volumeToMount.GenerateError("MountVolume.FindPluginBySpec failed", err) | ||
} | ||
|
||
volumeMounter, newMounterErr := volumePlugin.NewMounter( | ||
volumeToMount.VolumeSpec, | ||
volumeToMount.Pod, | ||
volume.VolumeOptions{}) | ||
if newMounterErr != nil { | ||
eventErr, detailedErr := volumeToMount.GenerateError("MountVolume.NewMounter initialization failed", newMounterErr) | ||
og.recorder.Eventf(volumeToMount.Pod, v1.EventTypeWarning, kevents.FailedMountVolume, eventErr.Error()) | ||
return volumetypes.GeneratedOperations{}, detailedErr | ||
} | ||
affinityErr := checkNodeAffinity(og, volumeToMount, volumePlugin) | ||
if affinityErr != nil { | ||
return volumeToMount.GenerateError("MountVolume.NodeAffinity check failed", affinityErr) | ||
} | ||
|
||
mountCheckError := checkMountOptionSupport(og, volumeToMount, volumePlugin) | ||
volumeMounter, newMounterErr := volumePlugin.NewMounter( | ||
volumeToMount.VolumeSpec, | ||
volumeToMount.Pod, | ||
volume.VolumeOptions{}) | ||
if newMounterErr != nil { | ||
return volumeToMount.GenerateError("MountVolume.NewMounter initialization failed", newMounterErr) | ||
|
||
if mountCheckError != nil { | ||
eventErr, detailedErr := volumeToMount.GenerateError("MountVolume.MountOptionSupport check failed", mountCheckError) | ||
og.recorder.Eventf(volumeToMount.Pod, v1.EventTypeWarning, kevents.UnsupportedMountOption, eventErr.Error()) | ||
return volumetypes.GeneratedOperations{}, detailedErr | ||
} | ||
} | ||
|
||
// Get attacher, if possible | ||
attachableVolumePlugin, _ := | ||
og.volumePluginMgr.FindAttachablePluginBySpec(volumeToMount.VolumeSpec) | ||
var volumeAttacher volume.Attacher | ||
if attachableVolumePlugin != nil { | ||
volumeAttacher, _ = attachableVolumePlugin.NewAttacher() | ||
} | ||
mountCheckError := checkMountOptionSupport(og, volumeToMount, volumePlugin) | ||
|
||
// get deviceMounter, if possible | ||
deviceMountableVolumePlugin, _ := og.volumePluginMgr.FindDeviceMountablePluginBySpec(volumeToMount.VolumeSpec) | ||
var volumeDeviceMounter volume.DeviceMounter | ||
if deviceMountableVolumePlugin != nil { | ||
volumeDeviceMounter, _ = deviceMountableVolumePlugin.NewDeviceMounter() | ||
} | ||
if mountCheckError != nil { | ||
return volumeToMount.GenerateError("MountVolume.MountOptionSupport check failed", mountCheckError) | ||
} | ||
|
||
var fsGroup *int64 | ||
if volumeToMount.Pod.Spec.SecurityContext != nil && | ||
volumeToMount.Pod.Spec.SecurityContext.FSGroup != nil { | ||
fsGroup = volumeToMount.Pod.Spec.SecurityContext.FSGroup | ||
} | ||
// Get attacher, if possible | ||
attachableVolumePlugin, _ := | ||
og.volumePluginMgr.FindAttachablePluginBySpec(volumeToMount.VolumeSpec) | ||
var volumeAttacher volume.Attacher | ||
if attachableVolumePlugin != nil { | ||
volumeAttacher, _ = attachableVolumePlugin.NewAttacher() | ||
} | ||
|
||
// get deviceMounter, if possible | ||
deviceMountableVolumePlugin, _ := og.volumePluginMgr.FindDeviceMountablePluginBySpec(volumeToMount.VolumeSpec) | ||
var volumeDeviceMounter volume.DeviceMounter | ||
if deviceMountableVolumePlugin != nil { | ||
volumeDeviceMounter, _ = deviceMountableVolumePlugin.NewDeviceMounter() | ||
} | ||
|
||
var fsGroup *int64 | ||
if volumeToMount.Pod.Spec.SecurityContext != nil && | ||
volumeToMount.Pod.Spec.SecurityContext.FSGroup != nil { | ||
fsGroup = volumeToMount.Pod.Spec.SecurityContext.FSGroup | ||
} | ||
|
||
mountVolumeFunc := func() (error, error) { | ||
devicePath := volumeToMount.DevicePath | ||
if volumeAttacher != nil { | ||
// Wait for attachable volumes to finish attaching | ||
|
@@ -536,7 +540,7 @@ func (og *operationGenerator) GenerateMountVolumeFunc( | |
|
||
// resizeFileSystem will resize the file system if user has requested a resize of | ||
// underlying persistent volume and is allowed to do so. | ||
resizeSimpleError, resizeDetailedError := og.resizeFileSystem(volumeToMount, devicePath, deviceMountPath, volumePlugin.GetPluginName()) | ||
resizeSimpleError, resizeDetailedError := og.resizeFileSystem(volumeToMount, devicePath, deviceMountPath, volumePluginName) | ||
|
||
if resizeSimpleError != nil || resizeDetailedError != nil { | ||
return resizeSimpleError, resizeDetailedError | ||
|
@@ -593,8 +597,8 @@ func (og *operationGenerator) GenerateMountVolumeFunc( | |
return volumetypes.GeneratedOperations{ | ||
OperationFunc: mountVolumeFunc, | ||
EventRecorderFunc: eventRecorderFunc, | ||
CompleteFunc: util.OperationCompleteHook(util.GetFullQualifiedPluginNameForVolume(volumePlugin.GetPluginName(), volumeToMount.VolumeSpec), "volume_mount"), | ||
}, nil | ||
CompleteFunc: util.OperationCompleteHook(util.GetFullQualifiedPluginNameForVolume(volumePluginName, volumeToMount.VolumeSpec), "volume_mount"), | ||
} | ||
} | ||
|
||
func (og *operationGenerator) resizeFileSystem(volumeToMount VolumeToMount, devicePath, deviceMountPath, pluginName string) (simpleErr, detailedErr error) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here you remove the return err because it is always nil? How about all the other GernerateXXXFunc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mount was the most problematic in terms of log/event spam because of the new CSI access pattern. I want to do the same for the others methods because the same issue technically exists with them.
I'm leaning towards getting this merged quick to fix the known issue, and then doing a follow up to make the other methods follow this pattern. But also happy to those as additional commits to this PR if folks want that.