Skip to content
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

Events refactoring #190

Merged
Merged
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
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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using EventTypeNormal and EventTypeNormal from https://github.com/kubernetes/api/blob/v0.29.2/core/v1/types.go#L6354-L6359 instead of typing the string? Here and in other occurrences in this file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using the string RemediationStarted we can also use the common remediation event reasons.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's very significant in test code.
One can even argue against it in test code, because it would be safer to validate vs a "decoupled " hardcoded value (personally not an issue as well IMO).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the event type?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH my original response for the event type question 😅 (I only saw the followup after I posted)
I was just luck that my answer fitted nicely the second question


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
Loading