Skip to content

Commit

Permalink
style(snapshot): use event reason constants in controller
Browse files Browse the repository at this point in the history
Longhorn 4126

Signed-off-by: Eric Weber <eric.weber@suse.com>
  • Loading branch information
ejweber authored and innobead committed Jun 30, 2024
1 parent 8ee07d1 commit 147bdb6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion constant/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const (
EventReasonReady = "Ready"
EventReasonUploaded = "Uploaded"

EventReasonUpgrade = "Uppgrade"
EventReasonUpgrade = "Upgrade"

EventReasonRolloutSkippedFmt = "RolloutSkipped: %v %v"
)
11 changes: 6 additions & 5 deletions controller/snapshot_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
clientset "k8s.io/client-go/kubernetes"
v1core "k8s.io/client-go/kubernetes/typed/core/v1"

"github.com/longhorn/longhorn-manager/constant"
"github.com/longhorn/longhorn-manager/datastore"
"github.com/longhorn/longhorn-manager/engineapi"
"github.com/longhorn/longhorn-manager/types"
Expand Down Expand Up @@ -561,19 +562,19 @@ func (sc *SnapshotController) handleAttachmentTicketCreation(snap *longhorn.Snap

func (sc *SnapshotController) generatingEventsForSnapshot(existingSnapshot, snapshot *longhorn.Snapshot) {
if !existingSnapshot.Status.MarkRemoved && snapshot.Status.MarkRemoved {
sc.eventRecorder.Event(snapshot, corev1.EventTypeWarning, "SnapshotDelete", "snapshot is marked as removed")
sc.eventRecorder.Event(snapshot, corev1.EventTypeWarning, constant.EventReasonDelete, "snapshot is marked as removed")
}
if snapshot.Spec.CreateSnapshot && existingSnapshot.Status.CreationTime == "" && snapshot.Status.CreationTime != "" {
sc.eventRecorder.Eventf(snapshot, corev1.EventTypeNormal, "SnapshotCreate", "successfully provisioned the snapshot")
sc.eventRecorder.Event(snapshot, corev1.EventTypeNormal, constant.EventReasonCreate, "successfully provisioned the snapshot")
}
if snapshot.Status.Error != "" && existingSnapshot.Status.Error != snapshot.Status.Error {
sc.eventRecorder.Eventf(snapshot, corev1.EventTypeWarning, "SnapshotError", "%v", snapshot.Status.Error)
sc.eventRecorder.Eventf(snapshot, corev1.EventTypeWarning, constant.EventReasonFailed, "%v", snapshot.Status.Error)
}
if existingSnapshot.Status.ReadyToUse != snapshot.Status.ReadyToUse {
if snapshot.Status.ReadyToUse {
sc.eventRecorder.Eventf(snapshot, corev1.EventTypeNormal, "SnapshotUpdate", "snapshot becomes ready to use")
sc.eventRecorder.Event(snapshot, corev1.EventTypeNormal, constant.EventReasonUpdate, "snapshot becomes ready to use")
} else {
sc.eventRecorder.Eventf(snapshot, corev1.EventTypeWarning, "SnapshotUpdate", "snapshot becomes not ready to use")
sc.eventRecorder.Event(snapshot, corev1.EventTypeWarning, constant.EventReasonUpdate, "snapshot becomes not ready to use")
}
}
}
Expand Down

0 comments on commit 147bdb6

Please sign in to comment.