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

Generalize Node preparation for e2e and integration tests #35129

Merged
merged 1 commit into from
Oct 20, 2016

Conversation

gmarek
Copy link
Contributor

@gmarek gmarek commented Oct 19, 2016

@wojtek-t


This change is Reviewable

@gmarek gmarek self-assigned this Oct 19, 2016
@k8s-github-robot k8s-github-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. release-note-label-needed labels Oct 19, 2016
@k8s-ci-robot
Copy link
Contributor

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 e2e test this. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

@gmarek
Copy link
Contributor Author

gmarek commented Oct 20, 2016

@k8s-bot gci gke test this issue: #IGNORE
checking something

@gmarek gmarek added release-note-none Denotes a PR that doesn't merit a release note. and removed release-note-label-needed labels Oct 20, 2016
@gmarek gmarek changed the title WIP: Generalize Node preparation for e2e and integration tests Generalize Node preparation for e2e and integration tests Oct 20, 2016
@gmarek gmarek assigned wojtek-t and unassigned gmarek Oct 20, 2016
@gmarek
Copy link
Contributor Author

gmarek commented Oct 20, 2016

cc @timothysc @jayunit100


type E2ETestNodePreparer struct {
client clientset.Interface
countToStrategy map[int]testutils.PrepareNodeStrategy
Copy link
Member

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.

Copy link
Contributor Author

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 {
Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

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.

Copy link
Contributor Author

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 {
Copy link
Member

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.

Copy link
Contributor Author

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

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?

Copy link
Contributor Author

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.

Copy link
Member

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

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.

Copy link
Contributor Author

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

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.

Copy link
Contributor Author

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

Choose a reason for hiding this comment

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

b.Fatalf(err)

Copy link
Contributor Author

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 {
Copy link
Member

Choose a reason for hiding this comment

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

b.Fatalf(err)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@gmarek
Copy link
Contributor Author

gmarek commented Oct 20, 2016

@wojtek-t PTAL

sum += k
for ; index < sum; index++ {
err := testutils.DoPrepareNode(p.client, &nodes.Items[index], strategy)
if err != nil {
Copy link
Member

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 {

Copy link
Contributor Author

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 {
Copy link
Member

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 {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

}
}
}
if encounteredError {
Copy link
Member

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

Copy link
Contributor Author

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

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 {
Copy link
Member

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

Copy link
Contributor Author

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 {
Copy link
Member

Choose a reason for hiding this comment

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

if err := ... ; err != nil

Copy link
Contributor Author

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

Choose a reason for hiding this comment

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

if err := ... ; err != nil

Copy link
Contributor Author

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

Choose a reason for hiding this comment

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

if err := ... ; err != nil

Copy link
Contributor Author

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 {
Copy link
Member

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

Copy link
Contributor Author

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).

Copy link
Member

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

Choose a reason for hiding this comment

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

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above.

@gmarek
Copy link
Contributor Author

gmarek commented Oct 20, 2016

@wojtek-t PTAL

@gmarek gmarek force-pushed the generalize branch 2 times, most recently from 5021668 to 1ea32f2 Compare October 20, 2016 09:16
Copy link
Member

@wojtek-t wojtek-t left a 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 {
Copy link
Member

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 {
Copy link
Member

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@gmarek
Copy link
Contributor Author

gmarek commented Oct 20, 2016

@wojtek-t squashed, PTAL.

@wojtek-t wojtek-t added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 20, 2016
@wojtek-t
Copy link
Member

lgtm

@k8s-ci-robot
Copy link
Contributor

Jenkins GKE smoke e2e failed for commit fbb3d6b. Full PR test history.

The magic incantation to run this job again is @k8s-bot cvm gke e2e test this. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

@gmarek
Copy link
Contributor Author

gmarek commented Oct 20, 2016

@k8s-bot gke test this issue: #IGNORE
startup problem

@k8s-github-robot
Copy link

@k8s-bot test this [submit-queue is verifying that this PR is safe to merge]

@k8s-github-robot
Copy link

Automatic merge from submit-queue

@k8s-github-robot k8s-github-robot merged commit 7a03564 into kubernetes:master Oct 20, 2016
sttts pushed a commit to sttts/kubernetes that referenced this pull request Oct 24, 2016
Automatic merge from submit-queue

Use TestNodePreparer in Density test

Depends on kubernetes#35129
@gmarek gmarek deleted the generalize branch February 21, 2017 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants