-
Notifications
You must be signed in to change notification settings - Fork 8
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 utils Package and Taint Functionality #61
Conversation
Skipping CI for Draft Pull Request. |
Tests will fail since the PR uses common repo which depends on newer Kubernetes API, thus #56 should be merged, and then after rebasing the PR could be tested. |
I think at the moment go.mod/go.sum/vendor aren't in sync. |
By("having one control-plane-role taint") | ||
taintedNode := &corev1.Node{} | ||
Expect(k8sClient.Get(context.Background(), nodeKey, taintedNode)).To(Succeed()) | ||
Expect(utils.TaintExists(taintedNode.Spec.Taints, &controlPlaneRoleTaint)).To(BeTrue()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks like a test for the utils package to me, so it should be there IMHO
Add UT to check whether append and remove taint functions append and remove properly taints while the other taints remain
Use common for k8s node labels
Add missing and remove unused modules, make vendored copy of dependencies, and verify dependencies have expected content
pkg/utils/nodes.go
Outdated
// used for making new node object for test and have a unique resourceVersion | ||
// GetNode returns a node object with the name nodeName based on the nodeType input | ||
func GetNode(nodeType, nodeName string) *corev1.Node { | ||
if nodeType == "control-plane" { | ||
return &corev1.Node{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: nodeName, | ||
}, | ||
Spec: corev1.NodeSpec{ | ||
Taints: []corev1.Taint{ | ||
{ | ||
Key: medik8sLabels.ControlPlaneRole, | ||
Effect: corev1.TaintEffectNoExecute, | ||
}, | ||
}, | ||
}, | ||
} | ||
} else { | ||
return &corev1.Node{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: nodeName, | ||
}, | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes more sense to move this function which is used for unit-testing to another file. Maybe under test
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or even having two local function for getting the node object? One in fenceagentsremediation_controller_test.go
, and one in utils_test.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I would put it into pkg/utils/nodes_test.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But then controllers/fenceagentsremediation_controller_test.go
could not find the GetNode
function from a test code pkg/utils/nodes_test.go
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah crap, I always forget about this limitation...
then I would just leave it here 🤷🏼♂️
/test 4.13-openshift-e2e |
pkg/utils/utils_suite_test.go
Outdated
@@ -0,0 +1,99 @@ | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filename: you can skip "utils", it's redundant (there should be one suite per package)
pkg/utils/utils_test.go
Outdated
@@ -0,0 +1,78 @@ | |||
package utils |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I would name this file nodes_test.go, so you can have separate test files when you add new util files later on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But nodes_test.go wouldn't be interfered as the test file for nodes.go, while this file shares a test for the taint file as well? ATM it has tests for two utils files, taint.go
, and nodes.go
Going with your direction maybe it would make more sense to move Context("Taint functioninality test",...
logic to taint_test.go
, and have nodes_test.go
for the other tests that utils.go has.
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, ideally every xyz.go file should have its own xyz_test.go file. But I won't block on this, for these few methods / tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me :)
pkg/utils/nodes.go
Outdated
// used for making new node object for test and have a unique resourceVersion | ||
// GetNode returns a node object with the name nodeName based on the nodeType input | ||
func GetNode(nodeType, nodeName string) *corev1.Node { | ||
if nodeType == "control-plane" { | ||
return &corev1.Node{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: nodeName, | ||
}, | ||
Spec: corev1.NodeSpec{ | ||
Taints: []corev1.Taint{ | ||
{ | ||
Key: medik8sLabels.ControlPlaneRole, | ||
Effect: corev1.TaintEffectNoExecute, | ||
}, | ||
}, | ||
}, | ||
} | ||
} else { | ||
return &corev1.Node{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: nodeName, | ||
}, | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I would put it into pkg/utils/nodes_test.go
@@ -132,7 +114,7 @@ var _ = Describe("FAR Controller", func() { | |||
|
|||
When("creating valid FAR CR", func() { | |||
BeforeEach(func() { | |||
node = getNode(node01) | |||
node = utils.GetNode("", node01) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC node is always initialized to the same value.
If this is indeed the case I suggest:
- initialize node value on var declaration
- move the node creation to a share BeforeEach block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC node is always initialized to the same value.
Correct, but if it is initialized once then the second test would fail as the instance might be deleted or already created while the second test tries to create it (an error due race condition). To overcome it we initialize an independent instance of the node (same spec and name, but different resource version) in a different BeforeEach block.
pkg/utils/utils_test.go
Outdated
Context("FAR CR and Node Names Validity test", func() { | ||
BeforeEach(func() { | ||
node = GetNode("", node01) | ||
DeferCleanup(k8sClient.Delete, context.Background(), node) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: defer should be after the Create
pkg/utils/utils_test.go
Outdated
By("having one control-plane-role taint") | ||
taintedNode := &corev1.Node{} | ||
Expect(k8sClient.Get(context.Background(), nodeKey, taintedNode)).To(Succeed()) | ||
Expect(TaintExists(taintedNode.Spec.Taints, &controlPlaneRoleTaint)).To(BeTrue()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this is redundant since we added this taint in the test code
These test are unrelated to controller package, thus they should reside under utils directory
/test 4.13-openshift-e2e |
Every xyz.go file should have its own xyz_test.go file, and not a general one as utils_test.go
/test 4.13-openshift-e2e |
/retry |
/retest |
I didn't though that |
/retest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
two nits, other than that lgtm
pkg/utils/nodes.go
Outdated
@@ -33,3 +34,29 @@ func IsNodeNameValid(r client.Reader, nodeName string) (bool, error) { | |||
} | |||
return true, nil | |||
} | |||
|
|||
// used for making new node object for test and have a unique resourceVersion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comments should start with the function name, in the 1st line of the comment 😉
pkg/utils/nodes.go
Outdated
|
||
// used for making new node object for test and have a unique resourceVersion | ||
// GetNode returns a node object with the name nodeName based on the nodeType input | ||
func GetNode(nodeType, nodeName string) *corev1.Node { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO nodeRole wold be a better name than nodeType?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree
/test 4.13-openshift-e2e |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: razo7, slintes 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 |
make go-verify