-
Notifications
You must be signed in to change notification settings - Fork 38.8k
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
add e2e node test for Pod hostAliases feature #46385
Conversation
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 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. |
test/e2e_node/kubelet_test.go
Outdated
|
||
rc, err := podClient.GetLogs(podName, &v1.PodLogOptions{}).Stream() | ||
if err != nil { | ||
return "" |
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.
Print this 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.
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.
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.
@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.
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.
It's fine to return the empty string, logging the error is orthogonal.
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.
fixed
test/e2e_node/kubelet_test.go
Outdated
|
||
Eventually(func() string { | ||
pod, err := podClient.Get(podName, metav1.GetOptions{}) | ||
Expect(err).To(BeNil(), fmt.Sprintf("Error getting Pod %v", 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.
Use framework.ExpectNoError(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.
fixed
c740d9d
to
8ee7fbf
Compare
test/e2e_node/kubelet_test.go
Outdated
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 |
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.
Do we really need to check the entire file? It should be sufficient if /etc/hosts
contains the two lines we care about.
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'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
test/e2e_node/kubelet_test.go
Outdated
|
||
expectedHostsFileContent = fmt.Sprintf(expectedHostsFileContent, podIP, podName) | ||
|
||
rc, err := podClient.GetLogs(podName, &v1.PodLogOptions{}).Stream() |
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 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.
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 haven't really figured out how to use framework.GetPodLogs()
. keeping the old way for now.
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.
Here's an example if you'd like to give it a try:
https://github.com/kubernetes/kubernetes/blob/v1.8.0-alpha.0/test/e2e_node/security_context_test.go#L87
test/e2e_node/kubelet_test.go
Outdated
}, | ||
}) | ||
|
||
Eventually(func() string { |
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'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.
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.
fixed to make function return error
@k8s-bot ok to test |
632b460
to
15ca435
Compare
c8b7960
to
42b7541
Compare
/lgtm |
/cc @Random-Liu @timstclair for approval. |
thanks @yujuhong. should I backport this to release-1.7 branch? I think that'd be a good idea. |
test/e2e_node/kubelet_test.go
Outdated
{ | ||
Image: "gcr.io/google_containers/busybox:1.24", | ||
Name: podName, | ||
Command: []string{"/bin/sh", "-c", "cat /etc/hosts; sleep 240"}, |
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: add a longer sleep timer and just let the namespace cleanup the pod (lots of tests use 6000 (10 minutes))
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.
fixed
return err | ||
} | ||
buf := new(bytes.Buffer) | ||
buf.ReadFrom(rc) |
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 you're going to read the whole stream, just use \.DoRaw()
rather than Stream()
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.
fixed
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 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:
kubernetes/test/e2e_node/kubelet_test.go
Line 143 in 05bff30
rc, err := podClient.GetLogs(podName, &v1.PodLogOptions{}).Stream() |
I think 1.7 is still tracking master, so no cherrypick should be necessary. |
42b7541
to
a2692cd
Compare
a2692cd
to
4e7fed4
Compare
/lgtm |
[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 |
@k8s-bot pull-kubernetes-e2e-gce-etcd3 test this |
Automatic merge from submit-queue (batch tested with PRs 43005, 46660, 46385, 46991, 47103) |
What this PR does / why we need it: adds node e2e test for #45148
tests requested in #43632 (comment)
Release note:
@yujuhong @thockin