Skip to content

Commit

Permalink
Merge pull request #190 from mshitrit/skip-start-remediation-event
Browse files Browse the repository at this point in the history
Events refactoring
  • Loading branch information
openshift-merge-bot[bot] authored Feb 18, 2024
2 parents 21e347c + fca08b8 commit 27560cb
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 17 deletions.
16 changes: 10 additions & 6 deletions controllers/selfnoderemediation_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,6 @@ func (r *SelfNodeRemediationReconciler) Reconcile(ctx context.Context, req ctrl.
return ctrl.Result{}, err
}

//used as an indication not to spam the event
if isFinalizerAlreadyAdded := controllerutil.ContainsFinalizer(snr, SNRFinalizer); !isFinalizerAlreadyAdded {
events.RemediationStarted(r.Recorder, snr)
}

defer func() {
if updateErr := r.updateSnrStatus(ctx, snr); updateErr != nil {
if apiErrors.IsConflict(updateErr) {
Expand Down Expand Up @@ -219,7 +214,7 @@ func (r *SelfNodeRemediationReconciler) Reconcile(ctx context.Context, req ctrl.
if updateErr := r.updateConditions(remediationSkippedNodeNotFound, snr); updateErr != nil {
return ctrl.Result{}, updateErr
}
events.NormalEvent(r.Recorder, snr, eventReasonRemediationStopped, "couldn't find node matching remediation")
events.GetTargetNodeFailed(r.Recorder, snr)
} else {
r.logger.Error(err, "failed to get node", "node name", snr.Name)
}
Expand All @@ -232,6 +227,15 @@ func (r *SelfNodeRemediationReconciler) Reconcile(ctx context.Context, req ctrl.
return ctrl.Result{}, nil
}

//used as an indication not to spam the event
if isFinalizerAlreadyAdded := controllerutil.ContainsFinalizer(snr, SNRFinalizer); !isFinalizerAlreadyAdded {
eventMessage := "Remediation started by SNR manager"
if r.IsAgent() {
eventMessage = "Remediation started by SNR agent"
}
events.NormalEvent(r.Recorder, snr, "RemediationStarted", eventMessage)
}

strategy := r.getRuntimeStrategy(snr)
switch strategy {
case v1alpha1.ResourceDeletionRemediationStrategy:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ var _ = Describe("SNR Controller", func() {
It("Remediation flow", func() {
node := verifyNodeIsUnschedulable()

verifyEvent("Normal", "RemediationStarted", "Remediation started")
verifyEvent("Normal", "RemediationStarted", "Remediation started by SNR manager")

verifyEvent("Normal", "MarkUnschedulable", "Remediation process - unhealthy node marked as unschedulable")

Expand Down Expand Up @@ -252,8 +252,7 @@ var _ = Describe("SNR Controller", func() {

It("remediation should stop and update conditions", func() {
verifyTypeConditions(snr.Name, metav1.ConditionFalse, metav1.ConditionFalse, "RemediationSkippedNodeNotFound")

verifyEvent("Normal", "RemediationStopped", "couldn't find node matching remediation")
verifyEvent("Warning", "RemediationCannotStart", "Could not get remediation target Node")
})
})

Expand Down Expand Up @@ -396,7 +395,7 @@ var _ = Describe("SNR Controller", func() {
time.Sleep(time.Second)
verifyNoEvent("Normal", "MarkUnschedulable", "Remediation process - unhealthy node marked as unschedulable")
verifyTypeConditions(snr.Name, metav1.ConditionFalse, metav1.ConditionFalse, "RemediationSkippedNodeNotFound")
verifyEvent("Normal", "RemediationStopped", "couldn't find node matching remediation")
verifyEvent("Warning", "RemediationCannotStart", "Could not get remediation target Node")
})
})
When("NHC isn set as owner in the remediation", func() {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/Masterminds/sprig v2.22.0+incompatible
github.com/go-logr/logr v1.2.3
github.com/go-ping/ping v1.1.0
github.com/medik8s/common v1.12.0
github.com/medik8s/common v1.15.1
github.com/onsi/ginkgo/v2 v2.9.1
github.com/onsi/gomega v1.27.4
github.com/openshift/api v0.0.0-20230414143018-3367bc7e6ac7 // release-4.13
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJ
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/matttproud/golang_protobuf_extensions v1.0.2 h1:hAHbPm5IJGijwng3PWk09JkG9WeqChjprR5s9bBZ+OM=
github.com/matttproud/golang_protobuf_extensions v1.0.2/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
github.com/medik8s/common v1.12.0 h1:UJ5VS4rbo/K0snfuqRiYam1NhXTwo4Q7fTng34YSlmA=
github.com/medik8s/common v1.12.0/go.mod h1:Q6YR2rgyiLl6ob4Mx2uDBmybAB3d94fImwoHPbeiE54=
github.com/medik8s/common v1.15.1 h1:qo2FBZGSegf5q35AZlWzrmgwW1GfUPNmmWaPhb/Uurc=
github.com/medik8s/common v1.15.1/go.mod h1:A9jYldC6PZcAuBowNNm712FqWdASB2ey5Vjp8MYN/PY=
github.com/mitchellh/copystructure v1.1.2 h1:Th2TIvG1+6ma3e/0/bopBKohOTY7s4dA8V2q4EUcBJ0=
github.com/mitchellh/copystructure v1.1.2/go.mod h1:EBArHfARyrSWO/+Wyr9zwEkc6XMFB9XyNgFNmRkZZU4=
github.com/mitchellh/reflectwalk v1.0.1 h1:FVzMWA5RllMAKIdUSC8mdWo3XtwoecrH79BY70sEEpE=
Expand Down
11 changes: 8 additions & 3 deletions vendor/github.com/medik8s/common/pkg/events/events.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ github.com/mailru/easyjson/jwriter
# github.com/matttproud/golang_protobuf_extensions v1.0.2
## explicit; go 1.9
github.com/matttproud/golang_protobuf_extensions/pbutil
# github.com/medik8s/common v1.12.0
# github.com/medik8s/common v1.15.1
## explicit; go 1.20
github.com/medik8s/common/pkg/events
github.com/medik8s/common/pkg/labels
Expand Down

0 comments on commit 27560cb

Please sign in to comment.