-
Notifications
You must be signed in to change notification settings - Fork 40k
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
Generalize Node preparation for e2e and integration tests #35129
Conversation
Jenkins GCI GKE smoke e2e failed for commit d0f20fc. Full PR test history. The magic incantation to run this job again is |
@k8s-bot gci gke test this issue: #IGNORE |
|
||
type E2ETestNodePreparer struct { | ||
client clientset.Interface | ||
countToStrategy map[int]testutils.PrepareNodeStrategy |
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.
Please add comments what these define.
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.
Done.
} | ||
for attempt := 0; attempt < UpdateRetries; attempt++ { | ||
_, err = p.client.Core().Nodes().Patch(nodes.Items[index].Name, api.MergePatchType, []byte(patch)) | ||
if err != nil { |
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.
if err == nil || !apierrs.IsConflict(err) {
break
}
it's more readable.
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.
Done.
if err != nil { | ||
glog.Errorf("Skipping cleanup of Node: failed to get Node %v: %v", name, err) | ||
encounteredError = true | ||
continue nodeloop |
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 really don't like those "goto-like" instructions.
What I suggest instead is opaque this for attempt := ... into
func() {
}
and then change those continue nodeLoop
to returns.
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.
Done.
continue nodeloop | ||
} | ||
_, err = p.client.Core().Nodes().Update(updatedNode) | ||
if err != nil { |
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.
Change error handling to what I suggested above.
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.
Done.
GenerateName: p.nodeNamePrefix, | ||
}, | ||
Spec: api.NodeSpec{ | ||
ExternalID: "foo", |
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.
What's that? And why this is equal for all nodes?
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 have no idea what it is, but validation fails without it, even though in types.go it says that it's optional.
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.
Can you please add a TODO to invistigate why this is always the same for all nodes?
} | ||
for i := 0; i < numNodes; i++ { | ||
if _, err := p.client.Core().Nodes().Create(baseNode); err != nil { | ||
panic("error creating node: " + err.Error()) |
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.
Please return error instead of panic.
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.
Done.
} | ||
} | ||
|
||
nodes := e2eframework.GetReadySchedulableNodesOrDie(p.client) |
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.
Can we reuse the PrepareNodes function from test/e2e/framework? It seems pretty much the same.
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.
There are small differences - e.g. in e2e one we do store map of strategy used to modify given Node, here we don't need to count/check number of Nodes. I can try to extract the common part.
) | ||
err := nodePreparer.PrepareNodes() | ||
if err != nil { | ||
panic(err) |
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.
b.Fatalf(err)
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.
Done.
"scheduler-perf-", | ||
) | ||
err := nodePreparer.PrepareNodes() | ||
if err != nil { |
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.
b.Fatalf(err)
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.
Done.
@wojtek-t PTAL |
sum += k | ||
for ; index < sum; index++ { | ||
err := testutils.DoPrepareNode(p.client, &nodes.Items[index], strategy) | ||
if err != nil { |
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.
if err := testutils.Do...; err != nil {
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.
Done.
strategy, found := p.nodeToAppliedStrategy[name] | ||
if found { | ||
err = testutils.DoCleanupNode(p.client, name, strategy) | ||
if err != nil { |
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.
if err := testutils.Do...; err != nil {
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.
Done.
} | ||
} | ||
} | ||
if encounteredError { |
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.
Maybe instead of having this a bool value, do:
var encouteredError error
and then when you set it to true set it to this error, and here just return this
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.
Done.
GenerateName: p.nodeNamePrefix, | ||
}, | ||
Spec: api.NodeSpec{ | ||
ExternalID: "foo", |
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.
Can you please add a TODO to invistigate why this is always the same for all nodes?
sum += k | ||
for ; index < sum; index++ { | ||
err := testutils.DoPrepareNode(p.client, &nodes.Items[index], strategy) | ||
if err != nil { |
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.
if err := testutils...; err != nil
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.
Done.
nodes := e2eframework.GetReadySchedulableNodesOrDie(p.client) | ||
for i := range nodes.Items { | ||
err := p.client.Core().Nodes().Delete(nodes.Items[i].Name, &api.DeleteOptions{}) | ||
if err != nil { |
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.
if err := ... ; err != nil
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.
Done
map[int]testutils.PrepareNodeStrategy{numNodes: &testutils.TrivialNodePrepareStrategy{}}, | ||
"scheduler-perf-", | ||
) | ||
err := nodePreparer.PrepareNodes() |
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.
if err := ... ; err != nil
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.
Done.
map[int]testutils.PrepareNodeStrategy{numNodes: &testutils.TrivialNodePrepareStrategy{}}, | ||
"scheduler-perf-", | ||
) | ||
err := nodePreparer.PrepareNodes() |
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.
if err := ... ; err != nil
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.
Done.
return nil | ||
} | ||
for attempt := 0; attempt < retries; attempt++ { | ||
if _, err = client.Core().Nodes().Patch(node.Name, api.MergePatchType, []byte(patch)); err != nil { |
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.
Why not just:
if err == nil || !apiserrs.IsConflict(err) {
return err
}
it's more readable
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 want to print out the patch contents (it was useful for debugging some other stuff some time ago).
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.
Got it. So maybe to at least avoid nested ifs:
if err == nil {
return nil
} else if !apierrs.IsConflict(err) {
return ...
}
return nil | ||
} | ||
if _, err = client.Core().Nodes().Update(updatedNode); err != nil { | ||
if !apierrs.IsConflict(err) { |
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.
Same here
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.
Same as above.
@wojtek-t PTAL |
5021668
to
1ea32f2
Compare
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.
Some minor comments.
Also please squash commits.
return nil | ||
} | ||
for attempt := 0; attempt < retries; attempt++ { | ||
if _, err = client.Core().Nodes().Patch(node.Name, api.MergePatchType, []byte(patch)); err != nil { |
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.
Got it. So maybe to at least avoid nested ifs:
if err == nil {
return nil
} else if !apierrs.IsConflict(err) {
return ...
}
} | ||
} | ||
} | ||
if encounteredError != nil { |
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.
just
return encouteredError (you don't need this if)
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.
Done.
@wojtek-t squashed, PTAL. |
lgtm |
Jenkins GKE smoke e2e failed for commit fbb3d6b. Full PR test history. The magic incantation to run this job again is |
@k8s-bot gke test this issue: #IGNORE |
@k8s-bot test this [submit-queue is verifying that this PR is safe to merge] |
Automatic merge from submit-queue |
Automatic merge from submit-queue Use TestNodePreparer in Density test Depends on kubernetes#35129
@wojtek-t
This change is