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

add e2e node test for Pod hostAliases feature #46385

Merged

Conversation

evie404
Copy link
Contributor

@evie404 evie404 commented May 24, 2017

What this PR does / why we need it: adds node e2e test for #45148

tests requested in #43632 (comment)

Release note:

NONE

@yujuhong @thockin

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 24, 2017
@k8s-ci-robot
Copy link
Contributor

Hi @rickypai. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with @k8s-bot ok to test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@k8s-github-robot k8s-github-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. release-note-none Denotes a PR that doesn't merit a release note. labels May 24, 2017

rc, err := podClient.GetLogs(podName, &v1.PodLogOptions{}).Stream()
if err != nil {
return ""
Copy link
Contributor

Choose a reason for hiding this comment

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

Print this error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

every other example seem to return blank string when there's an error from getting logs. I'm not sure what's the rationale, but just cargo-culting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vishh could you help us understand why in other test cases it's acceptable to return blank string? sorry i'm not very familiar with the test framework used for the node e2e tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's fine to return the empty string, logging the error is orthogonal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed


Eventually(func() string {
pod, err := podClient.Get(podName, metav1.GetOptions{})
Expect(err).To(BeNil(), fmt.Sprintf("Error getting Pod %v", err))
Copy link
Contributor

Choose a reason for hiding this comment

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

Use framework.ExpectNoError(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.

fixed

@evie404 evie404 force-pushed the rpai/host_mapping_node_e2e_test branch from c740d9d to 8ee7fbf Compare May 26, 2017 20:56
@evie404
Copy link
Contributor Author

evie404 commented May 30, 2017

issues have been addressed. if you can take a look at this PR again, that'd be great. @Kargakis @mtaufen

@yujuhong yujuhong assigned yujuhong and mtaufen and unassigned mtaufen and euank Jun 1, 2017
Context("when scheduling a busybox Pod with hostAliases", func() {
podName := "busybox-host-aliases" + string(uuid.NewUUID())
expectedHostsFileContent := `# Kubernetes-managed hosts file.
127.0.0.1 localhost
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need to check the entire file? It should be sufficient if /etc/hosts contains the two lines we care about.

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's currently no e2e test checking any other content of the hosts file. so i figure i can help by checking the whole thing.

fixed to just check hostAlias-related entries


expectedHostsFileContent = fmt.Sprintf(expectedHostsFileContent, podIP, podName)

rc, err := podClient.GetLogs(podName, &v1.PodLogOptions{}).Stream()
Copy link
Contributor

Choose a reason for hiding this comment

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

I know you copied this from other tests, but consider using framework.GetPodLogs() which returns a string directly. This saves you the need of reading the output yourself.

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 haven't really figured out how to use framework.GetPodLogs(). keeping the old way for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

},
})

Eventually(func() string {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest making the function returns an error, and check whether the error is nil. This way, you can generate the error you want, without thinking what should be logged (e.g., failed fetching pod logs) and whether people would notice that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed to make function return error

@yujuhong
Copy link
Contributor

yujuhong commented Jun 1, 2017

@k8s-bot ok to test

@k8s-ci-robot k8s-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jun 1, 2017
@evie404 evie404 force-pushed the rpai/host_mapping_node_e2e_test branch 2 times, most recently from 632b460 to 15ca435 Compare June 1, 2017 23:52
@fejta
Copy link
Contributor

fejta commented Jun 2, 2017

@k8s-bot pull-kubernetes-federation-e2e-gce test this
ref: #46827

@evie404 evie404 force-pushed the rpai/host_mapping_node_e2e_test branch 2 times, most recently from c8b7960 to 42b7541 Compare June 2, 2017 18:42
@yujuhong yujuhong added this to the v1.7 milestone Jun 2, 2017
@yujuhong
Copy link
Contributor

yujuhong commented Jun 2, 2017

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 2, 2017
@yujuhong
Copy link
Contributor

yujuhong commented Jun 2, 2017

/cc @Random-Liu @timstclair for approval.

@evie404
Copy link
Contributor Author

evie404 commented Jun 2, 2017

thanks @yujuhong. should I backport this to release-1.7 branch? I think that'd be a good idea.

{
Image: "gcr.io/google_containers/busybox:1.24",
Name: podName,
Command: []string{"/bin/sh", "-c", "cat /etc/hosts; sleep 240"},

Choose a reason for hiding this comment

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

nit: add a longer sleep timer and just let the namespace cleanup the pod (lots of tests use 6000 (10 minutes))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

return err
}
buf := new(bytes.Buffer)
buf.ReadFrom(rc)

Choose a reason for hiding this comment

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

If you're going to read the whole stream, just use \.DoRaw() rather than Stream()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

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 reverted this. this was introducing panics in the tests and the logs are quite difficult to understand: https://k8s-gubernator.appspot.com/build/kubernetes-jenkins/pr-logs/pull/46385/pull-kubernetes-node-e2e/33666/nodelog?junit=junit_gci_05.xml&wrap=on

also, Stream() is used in other kubelet e2e tests, so I think it's safer to follow the pattern:

rc, err := podClient.GetLogs(podName, &v1.PodLogOptions{}).Stream()

@timstclair
Copy link

I think 1.7 is still tracking master, so no cherrypick should be necessary.

@evie404 evie404 force-pushed the rpai/host_mapping_node_e2e_test branch from 42b7541 to a2692cd Compare June 2, 2017 22:33
@k8s-github-robot k8s-github-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 2, 2017
@evie404 evie404 force-pushed the rpai/host_mapping_node_e2e_test branch from a2692cd to 4e7fed4 Compare June 3, 2017 00:02
@thockin thockin added approved-for-milestone approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Jun 6, 2017
@thockin
Copy link
Member

thockin commented Jun 6, 2017

/lgtm
/approve

@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rickypai, thockin, yujuhong

Associated issue: 45148

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

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@evie404
Copy link
Contributor Author

evie404 commented Jun 7, 2017

@k8s-bot pull-kubernetes-e2e-gce-etcd3 test this

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 43005, 46660, 46385, 46991, 47103)

@k8s-github-robot k8s-github-robot merged commit 6ee0282 into kubernetes:master Jun 7, 2017
@evie404 evie404 deleted the rpai/host_mapping_node_e2e_test branch June 7, 2017 23:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. 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/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants