Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func (h *LifeCycleHandler) checkVMPodVolumeErrors(ctx context.Context, vm *v1alp
log.Error("Failed to get last pod event", "error", err)
return err
}
if lastEvent != nil && (lastEvent.Reason == watcher.ReasonFailedAttachVolume || lastEvent.Reason == watcher.ReasonFailedMount) {
if lastEvent != nil && watcher.IsVolumeErrorReason(lastEvent.Reason) {
return &VMPodVolumeError{
Reason: lastEvent.Reason,
Message: lastEvent.Message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,18 @@ import (
const (
ReasonFailedAttachVolume = "FailedAttachVolume"
ReasonFailedMount = "FailedMount"
ReasonFailedMapVolume = "FailedMapVolume"
)

func IsVolumeErrorReason(reason string) bool {
switch reason {
case ReasonFailedAttachVolume, ReasonFailedMount, ReasonFailedMapVolume:
return true
default:
return false
}
}

func NewVolumeEventWatcher(client client.Client) *VolumeEventWatcher {
return &VolumeEventWatcher{
client: client,
Expand All @@ -58,7 +68,7 @@ func (w *VolumeEventWatcher) Watch(mgr manager.Manager, ctr controller.Controlle
return nil
}

if e.Reason != ReasonFailedAttachVolume && e.Reason != ReasonFailedMount {
if !IsVolumeErrorReason(e.Reason) {
return nil
}

Expand Down Expand Up @@ -87,7 +97,7 @@ func (w *VolumeEventWatcher) Watch(mgr manager.Manager, ctr controller.Controlle
predicate.TypedFuncs[*corev1.Event]{
CreateFunc: func(e event.TypedCreateEvent[*corev1.Event]) bool {
return e.Object.Type == corev1.EventTypeWarning &&
(e.Object.Reason == ReasonFailedAttachVolume || e.Object.Reason == ReasonFailedMount)
IsVolumeErrorReason(e.Object.Reason)
},
UpdateFunc: func(e event.TypedUpdateEvent[*corev1.Event]) bool {
return false
Expand Down
Loading