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: replace string literals with variables #23

Merged
merged 2 commits into from
Feb 15, 2024

Conversation

clobrano
Copy link
Contributor

Add variables for event reasons and messages to allow reuse of the same
messages and help tests.

Signed-off-by: Carlo Lobrano [email protected]

Copy link
Contributor

openshift-ci bot commented Feb 14, 2024

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

Copy link
Contributor

openshift-ci bot commented Feb 14, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: clobrano

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@clobrano
Copy link
Contributor Author

clobrano commented Feb 14, 2024

Following this discussion, this change can be useful when an operator has un-common events that fall into the same category of other "common" events already available as API (e.g. RemediationCannotStart)

}

// GetTargetNodeFailed will record a Warning event with reason RemediationFailed and message "Could not get remediation target node".
func GetTargetNodeFailed(recorder record.EventRecorder, object runtime.Object) {
WarningEvent(recorder, object, "RemediationCannotStart", "Could not get remediation target Node")
WarningEvent(recorder, object, RemediationCannotStartEventReason, RemediationCannotStartEventMessage)
Copy link
Member

Choose a reason for hiding this comment

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

this is very inconsistent :/

func name: GetTargetNodeFailed
reason: RemediationCannotStart
message: var name RemediationCannotStart, but value about the target node

IMHO most useful would be:
func name: RemediationCannotStart
reason: RemediationCannotStart
msg: passed in by parameter, there probably can be multiple reasons for a remediation to not start

Changing this would be an API change though, which would, when done correctly, need a major version bump...

So my suggestion is:

  • rename the msg var to e.g. RemediationCannotStartTargetNodeFailedEventMessage , to make its meaning a bit clearer
  • add a function as suggested above, and use it inside GetTargetNodeFailed?

WDYT?

Also, while I agree that the reasons should be consistent and might be worth adding to the API, I don't see that for the messages. What's the motivation for making them public?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's the motivation for making them public?

Mostly testing, but I'm still torn about leaving this information available only for testing and I won't mind reverting this particular bit 🤷

this is very inconsistent :/

I agree. I dunno why I choose a function name so different than the others :/

rename the msg var to e.g. RemediationCannotStartTargetNodeFailedEventMessage , to make its meaning a bit clearer
etc.

sounds like a good idea :)

Add variables for event reasons and messages to allow reuse of the same
messages and help tests.

Signed-off-by: Carlo Lobrano <[email protected]>
@clobrano clobrano force-pushed the event-export-variables-0 branch from 4d4d6fc to 8a66302 Compare February 14, 2024 15:06
Copy link
Member

@slintes slintes left a comment

Choose a reason for hiding this comment

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

This is better now, lgtm
Going to leave it open for others to review who use this more than I do :)

@slintes slintes dismissed their stale review February 14, 2024 15:37

dismissing a review for getting rid of requesting changes, does it work? 🤷

@razo7
Copy link
Member

razo7 commented Feb 15, 2024

/lgtm
Just one small NIT on function declaration of RemediationStarted, RemediationStoppedByNHC, RemediationFinished, and GetTargetNodeFailed. Since they no longer have a fixed message inside and they have a private variable of the message, thus their function declaration should fit with more vague information instead of specific (e.g., and message "Remediation finished" -> and a general message, or just remove the comment on the message).

@clobrano
Copy link
Contributor Author

Since they no longer have a fixed message inside

those functions still have a fixed message. Only RemediationCannotStart has a custom message

@razo7
Copy link
Member

razo7 commented Feb 15, 2024

Since they no longer have a fixed message inside

those functions still have a fixed message. Only RemediationCannotStart has a custom message

Correct, and I was referring to the other functions :)
I am trying to say that before we had an inline string with the exact message inside the function declaration (e.g., "Remediation finished"), so it was correct and straightforward, and now we have a const.
If in the future this const will be changed then we would have to remember updating the respected function declaration. I think we can reduce one less thing to remember in case future us would like to change a simple const without confusing/unaligning with the function declaration.
I hope my motivation is clearer now.

@clobrano
Copy link
Contributor Author

I hope my motivation is clearer now

Yes, thank you, now I understand it better and it makes sense

@openshift-ci openshift-ci bot removed the lgtm label Feb 15, 2024
@razo7
Copy link
Member

razo7 commented Feb 15, 2024

/lgtm

@openshift-ci openshift-ci bot added the lgtm label Feb 15, 2024
@clobrano clobrano marked this pull request as ready for review February 15, 2024 14:57
@openshift-merge-bot openshift-merge-bot bot merged commit 57f971c into medik8s:main Feb 15, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants