Skip to content

Commit

Permalink
Merge pull request #115 from clobrano/emit-remediation-started-event-…
Browse files Browse the repository at this point in the history
…only-once-0

Fix Remediation Started event
  • Loading branch information
openshift-merge-bot[bot] authored Jan 25, 2024
2 parents 0b1b2a7 + ee8db92 commit 80f25d9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
8 changes: 2 additions & 6 deletions controllers/machinedeletionremediation_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ const (
remediationSkippedMachineNotFound conditionChangeReason = "RemediationSkippedMachineNotFound"
remediationSkippedNoControllerOwner conditionChangeReason = "RemediationSkippedNoControllerOwner"
remediationFailed conditionChangeReason = "RemediationFailed"

// Event reasons and messages
machineDeletionRequestedEventReason = "MachineDeletionRequested"
machineDeletionRequestedEventMessage = "requesting machine deletion"
)

var (
Expand Down Expand Up @@ -135,7 +131,6 @@ func (r *MachineDeletionRemediationReconciler) Reconcile(ctx context.Context, re
finalResult.RequeueAfter = time.Second
}
}()
commonevents.RemediationStarted(r.Recorder, mdr)

if r.isTimedOutByNHC(mdr) {
log.Info("NHC time out annotation found, stopping remediation")
Expand Down Expand Up @@ -251,7 +246,8 @@ func (r *MachineDeletionRemediationReconciler) Reconcile(ctx context.Context, re
log.Error(err, "failed to delete machine", "machine", machine.GetName())
return ctrl.Result{}, err
}
commonevents.NormalEvent(r.Recorder, mdr, machineDeletionRequestedEventReason, machineDeletionRequestedEventMessage)
// The actual remediation has just started. This should be reached only once per CR.
commonevents.RemediationStarted(r.Recorder, mdr)

// requeue immediately to check machine deletion progression
return ctrl.Result{Requeue: true}, nil
Expand Down
32 changes: 16 additions & 16 deletions controllers/machinedeletionremediation_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ var _ = Describe("Machine Deletion Remediation CR", func() {
verifyConditionUnset(commonconditions.PermanentNodeDeletionExpectedType)
verifyEvents([]expectedEvent{
{v1.EventTypeWarning, "RemediationSkippedNodeNotFound", "failed to fetch node", true},
{v1.EventTypeNormal, machineDeletionRequestedEventReason, machineDeletionRequestedEventMessage, false},
{v1.EventTypeNormal, "RemediationStarted", "Remediation started", false},
})
})
})
Expand All @@ -168,7 +168,7 @@ var _ = Describe("Machine Deletion Remediation CR", func() {
{commonconditions.PermanentNodeDeletionExpectedType, metav1.ConditionUnknown, v1alpha1.MachineDeletionOnUndefinedProviderReason}})
verifyEvents([]expectedEvent{
{v1.EventTypeWarning, "RemediationSkippedNoControllerOwner", noControllerOwnerErrorMsg, true},
{v1.EventTypeNormal, machineDeletionRequestedEventReason, machineDeletionRequestedEventMessage, false},
{v1.EventTypeNormal, "RemediationStarted", "Remediation started", false},
})
})
})
Expand All @@ -190,7 +190,7 @@ var _ = Describe("Machine Deletion Remediation CR", func() {
{commonconditions.PermanentNodeDeletionExpectedType, metav1.ConditionUnknown, v1alpha1.MachineDeletionOnUndefinedProviderReason}})
verifyEvents([]expectedEvent{
{v1.EventTypeWarning, "RemediationSkippedNoControllerOwner", noControllerOwnerErrorMsg, true},
{v1.EventTypeNormal, machineDeletionRequestedEventReason, machineDeletionRequestedEventMessage, false},
{v1.EventTypeNormal, "RemediationStarted", "Remediation started", false},
})
})
})
Expand All @@ -214,7 +214,7 @@ var _ = Describe("Machine Deletion Remediation CR", func() {

verifyEvents([]expectedEvent{
{v1.EventTypeWarning, "RemediationSkippedNoControllerOwner", noControllerOwnerErrorMsg, true},
{v1.EventTypeNormal, machineDeletionRequestedEventReason, machineDeletionRequestedEventMessage, false},
{v1.EventTypeNormal, "RemediationStarted", "Remediation started", false},
})
})
})
Expand Down Expand Up @@ -257,7 +257,7 @@ var _ = Describe("Machine Deletion Remediation CR", func() {
// Cluster provider is not set in this test
{commonconditions.PermanentNodeDeletionExpectedType, metav1.ConditionUnknown, v1alpha1.MachineDeletionOnUndefinedProviderReason}})
verifyEvents([]expectedEvent{
{v1.EventTypeNormal, machineDeletionRequestedEventReason, machineDeletionRequestedEventMessage, true},
{v1.EventTypeNormal, "RemediationStarted", "Remediation started", true},
})
})
})
Expand Down Expand Up @@ -295,7 +295,7 @@ var _ = Describe("Machine Deletion Remediation CR", func() {
// Cluster provider is not set in this test
{commonconditions.PermanentNodeDeletionExpectedType, metav1.ConditionUnknown, v1alpha1.MachineDeletionOnUndefinedProviderReason}})
verifyEvents([]expectedEvent{
{v1.EventTypeNormal, machineDeletionRequestedEventReason, machineDeletionRequestedEventMessage, true},
{v1.EventTypeNormal, "RemediationStarted", "Remediation started", true},
{v1.EventTypeNormal, "RemediationFinished", "Remediation finished", true},
})
})
Expand Down Expand Up @@ -371,7 +371,7 @@ var _ = Describe("Machine Deletion Remediation CR", func() {
verifyConditionUnset(commonconditions.PermanentNodeDeletionExpectedType)
verifyEvents([]expectedEvent{
{v1.EventTypeWarning, "RemediationSkippedNodeNotFound", "failed to fetch node", true},
{v1.EventTypeNormal, machineDeletionRequestedEventReason, machineDeletionRequestedEventMessage, false},
{v1.EventTypeNormal, "RemediationStarted", "Remediation started", false},
})
})
})
Expand All @@ -394,7 +394,7 @@ var _ = Describe("Machine Deletion Remediation CR", func() {
verifyConditionUnset(commonconditions.PermanentNodeDeletionExpectedType)
verifyEvents([]expectedEvent{
{v1.EventTypeWarning, "RemediationFailed", unrecoverableError.Error(), true},
{v1.EventTypeNormal, machineDeletionRequestedEventReason, machineDeletionRequestedEventMessage, false},
{v1.EventTypeNormal, "RemediationStarted", "Remediation started", false},
})
})
})
Expand All @@ -417,7 +417,7 @@ var _ = Describe("Machine Deletion Remediation CR", func() {
verifyConditionUnset(commonconditions.PermanentNodeDeletionExpectedType)
verifyEvents([]expectedEvent{
{v1.EventTypeWarning, "RemediationFailed", unrecoverableError.Error(), true},
{v1.EventTypeNormal, machineDeletionRequestedEventReason, machineDeletionRequestedEventMessage, false},
{v1.EventTypeNormal, "RemediationStarted", "Remediation started", false},
})
})
})
Expand All @@ -440,7 +440,7 @@ var _ = Describe("Machine Deletion Remediation CR", func() {
verifyConditionUnset(commonconditions.PermanentNodeDeletionExpectedType)
verifyEvents([]expectedEvent{
{v1.EventTypeWarning, "RemediationFailed", unrecoverableError.Error(), true},
{v1.EventTypeNormal, machineDeletionRequestedEventReason, machineDeletionRequestedEventMessage, false},
{v1.EventTypeNormal, "RemediationStarted", "Remediation started", false},
})
})
})
Expand All @@ -463,7 +463,7 @@ var _ = Describe("Machine Deletion Remediation CR", func() {
verifyConditionUnset(commonconditions.PermanentNodeDeletionExpectedType)
verifyEvents([]expectedEvent{
{v1.EventTypeWarning, "RemediationSkippedMachineNotFound", "failed to fetch machine of node", true},
{v1.EventTypeNormal, machineDeletionRequestedEventReason, machineDeletionRequestedEventMessage, false},
{v1.EventTypeNormal, "RemediationStarted", "Remediation started", false},
})
})
})
Expand All @@ -487,7 +487,7 @@ var _ = Describe("Machine Deletion Remediation CR", func() {
verifyConditionUnset(commonconditions.PermanentNodeDeletionExpectedType)
verifyEvents([]expectedEvent{
{v1.EventTypeWarning, "RemediationFailed", unrecoverableError.Error(), true},
{v1.EventTypeNormal, machineDeletionRequestedEventReason, machineDeletionRequestedEventMessage, false},
{v1.EventTypeNormal, "RemediationStarted", "Remediation started", false},
})
})
})
Expand All @@ -512,7 +512,7 @@ var _ = Describe("Machine Deletion Remediation CR", func() {
// Cluster provider is not set in this test
{commonconditions.PermanentNodeDeletionExpectedType, metav1.ConditionUnknown, v1alpha1.MachineDeletionOnUndefinedProviderReason}})
verifyEvents([]expectedEvent{
{v1.EventTypeNormal, machineDeletionRequestedEventReason, machineDeletionRequestedEventMessage, false},
{v1.EventTypeNormal, "RemediationStarted", "Remediation started", false},
})
})
})
Expand All @@ -532,7 +532,7 @@ var _ = Describe("Machine Deletion Remediation CR", func() {
verifyConditionUnset(commonconditions.PermanentNodeDeletionExpectedType)
verifyEvents([]expectedEvent{
{v1.EventTypeNormal, "RemediationStopped", "NHC added the timed-out annotation, remediation will be stopped", true},
{v1.EventTypeNormal, machineDeletionRequestedEventReason, machineDeletionRequestedEventMessage, false},
{v1.EventTypeNormal, "RemediationStarted", "Remediation started", false},
})
})
})
Expand Down Expand Up @@ -576,7 +576,7 @@ var _ = Describe("Machine Deletion Remediation CR", func() {
// Cluster provider is not set in this test
{commonconditions.PermanentNodeDeletionExpectedType, metav1.ConditionUnknown, v1alpha1.MachineDeletionOnUndefinedProviderReason}})
verifyEvents([]expectedEvent{
{v1.EventTypeNormal, machineDeletionRequestedEventReason, machineDeletionRequestedEventMessage, true},
{v1.EventTypeNormal, "RemediationStarted", "Remediation started", true},
})
})
})
Expand All @@ -602,7 +602,7 @@ var _ = Describe("Machine Deletion Remediation CR", func() {
// Cluster provider is not set in this test
{commonconditions.PermanentNodeDeletionExpectedType, metav1.ConditionUnknown, v1alpha1.MachineDeletionOnUndefinedProviderReason}})
verifyEvents([]expectedEvent{
{v1.EventTypeNormal, machineDeletionRequestedEventReason, machineDeletionRequestedEventMessage, true},
{v1.EventTypeNormal, "RemediationStarted", "Remediation started", true},
})
})
})
Expand Down

0 comments on commit 80f25d9

Please sign in to comment.