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

Validate Node Name #48

Merged
merged 4 commits into from
Jun 8, 2023
Merged

Conversation

razo7
Copy link
Member

@razo7 razo7 commented May 10, 2023

  • Validate FAR CR name to a node name in the cluster.
  • Add three new verbs to check whether a specific node name match the nodes' names in the cluster.
  • Add and update unit-tests

@openshift-ci
Copy link
Contributor

openshift-ci bot commented May 10, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: razo7

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

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.

I noticed the WIP, however a quick first review 😉

controllers/fenceagentsremediation_controller.go Outdated Show resolved Hide resolved
pkg/utils/nodes.go Outdated Show resolved Hide resolved
pkg/utils/nodes.go Outdated Show resolved Hide resolved
@razo7 razo7 force-pushed the validate-node-name branch 2 times, most recently from b73169c to b81611f Compare May 11, 2023 09:35
@razo7 razo7 changed the title [WIP] Validate Node Name Validate Node Name May 11, 2023
pkg/utils/nodes.go Outdated Show resolved Hide resolved
controllers/fenceagentsremediation_controller_test.go Outdated Show resolved Hide resolved
pkg/utils/error.go Outdated Show resolved Hide resolved
pkg/utils/nodes.go Outdated Show resolved Hide resolved
pkg/utils/pods.go Outdated Show resolved Hide resolved
razo7 added 2 commits June 1, 2023 11:30
We want to validate that CR has been created correctly. Also UT functionality
We need to add three new rbac, get, list and watch, for listing the cluster nodes
pkg/utils/error.go Outdated Show resolved Hide resolved
pkg/utils/nodes.go Outdated Show resolved Hide resolved
pkg/utils/nodes.go Outdated Show resolved Hide resolved
return emptyResult, err
}
r.Log.Error(err, "Failed to validate FAR CR's name- retry")
return ctrl.Result{RequeueAfter: apiFailureRetryTimeout}, nil
Copy link
Member

@mshitrit mshitrit Jun 5, 2023

Choose a reason for hiding this comment

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

Why not just return the error here ?
(returning an error will trigger another reconcile)

@razo7 razo7 force-pushed the validate-node-name branch 2 times, most recently from da7cdee to 6e1b89d Compare June 6, 2023 10:32
controllers/fenceagentsremediation_controller.go Outdated Show resolved Hide resolved
// IsNodeNameValid returns an error if nodeName doesn't match any node name int the cluster, otherwise a nil
func IsNodeNameValid(r client.Reader, nodeName string) (bool, error) {
node := &corev1.Node{}
nodeExist := true
Copy link
Member

Choose a reason for hiding this comment

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

what do you need this for? IMHO it would be easier to read when using true or false directly

if isNotFound(err) {
  return false, nil
} else if err != nil {
  return false, err
}
return true, nil

or if you want to keep error handling nested:

if err != nil {
  if isNotFound(err) {
    return false, nil
  }
  return false, err
}
return true, nil

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 though it looks nicer and I like variables :) .
But I guess there is no actual benefit of using variables instead of explicitly the bool value here (of course in this situation).

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 went the second option, since I am not sure whether isNotFound would accept checking the input err when it is nil

pkg/utils/nodes.go Outdated Show resolved Hide resolved
pkg/utils/nodes.go Outdated Show resolved Hide resolved
pkg/utils/pods.go Outdated Show resolved Hide resolved
Delete redundant error file, and returning bool with error for IsNodeNameValid function
@mshitrit
Copy link
Member

mshitrit commented Jun 7, 2023

/lgtm
/hold
Left couple of Nits, no blockers IMO.
Feel free to fix/merge/wait more feedback

@@ -69,39 +72,53 @@ var _ = Describe("FAR Controller", func() {
underTestFAR = newFenceAgentsRemediation(validNodeName, fenceAgentIPMI, testShareParam, testNodeParam)

Context("Functionality", func() {
Context("buildFenceAgentParams", func() {
When("FAR's name isn't a node name", func() {
Context("buildFenceAgentParams - check CR name", func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: using function names in Ginkgo's node description makes it harder to understand what the test is verifying.
For example, in this context, it might be just "Check CR name against node"

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, do you have a suggestion for better naming?
I see a small value of testing the 2 functions in UT, but it does catch errors when I do small changes in them (or their dependencies)

Copy link
Contributor

Choose a reason for hiding this comment

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

For example, in this context, it might be just "Check CR name against node"

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 see, then I tend to let the context just be the function name (buildFenceAgentParams), and just remove the - check CR name

Copy link
Contributor

@clobrano clobrano Jun 8, 2023

Choose a reason for hiding this comment

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

not super important, but this would be less future-proof IMHO
If you change function name, or signature, you shall then change the test too
Instead, testing a behavior, whatever the implementation is, should always be valid also in the future

EDIT: I removed "change signature", which cannot be future proof, ofc XD

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed, checking behavior rather than a function (by it's name) seems more right.
Something to think off for next PRs and writing UTs

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.

overall looks good now, some nits only inside

controllers/fenceagentsremediation_controller.go Outdated Show resolved Hide resolved
controllers/fenceagentsremediation_controller.go Outdated Show resolved Hide resolved
controllers/fenceagentsremediation_controller_test.go Outdated Show resolved Hide resolved
pkg/utils/pods.go Outdated Show resolved Hide resolved
pkg/utils/nodes.go Outdated Show resolved Hide resolved
test/e2e/far_e2e_test.go Outdated Show resolved Hide resolved
Updating import names, and check error message of 1 UT
@slintes
Copy link
Member

slintes commented Jun 8, 2023

/lgtm
/hold

giving others the chance to check if their reviews are addressed

@openshift-ci openshift-ci bot added the lgtm label Jun 8, 2023
@clobrano
Copy link
Contributor

clobrano commented Jun 8, 2023

/lgtm
/hold

giving others the chance to check if their reviews are addressed

@razo7
Copy link
Member Author

razo7 commented Jun 8, 2023

I believe 2/3 acks is good enough for this PR 🙂
In any case @mshitrit feel free to reply here, and I will address it with a new PR :D

/unhold

@openshift-merge-robot openshift-merge-robot merged commit 4c75d75 into medik8s:main Jun 8, 2023
razo7 added a commit to razo7/fence-agents-remediation that referenced this pull request Jun 8, 2023
The E2E test is redundant after medik8s#48 PR, and it also fails here when we try to add/remove taint for a node which doesn't exist - dummy-node
razo7 added a commit to razo7/fence-agents-remediation that referenced this pull request Jun 8, 2023
The E2E test is redundant after medik8s#48 PR, and it also fails here when we try to add/remove taint for a node which doesn't exist - dummy-node
@razo7 razo7 mentioned this pull request Jun 11, 2023
razo7 added a commit to razo7/fence-agents-remediation that referenced this pull request Jun 14, 2023
The E2E test is redundant after medik8s#48 PR, and it also fails here when we try to add/remove taint for a node which doesn't exist - dummy-node
razo7 added a commit to razo7/fence-agents-remediation that referenced this pull request Jun 18, 2023
The E2E test is redundant after medik8s#48 PR, and it also fails here when we try to add/remove taint for a node which doesn't exist - dummy-node
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.

5 participants