Skip to content

Commit a248c4d

Browse files
committed
test: fix NodeLogQuery tests to query the correct node for logs
Currently, the test queries the local node, which is not correct for most kubernetes environments. Instead, ssh to the target node and call journalctl there Signed-off-by: Peter Hunt <[email protected]>
1 parent 86b44a3 commit a248c4d

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

test/e2e/node/kubelet.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ var _ = SIGDescribe("kubelet", func() {
574574
queryCommand := "\"/api/v1/nodes/" + nodeName + "/proxy/logs/?query=kubelet&tailLines=3\""
575575
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
576576
result := runKubectlCommand(cmd)
577-
logs := journalctlCommand("-u", "kubelet", "-n 3 --utc")
577+
logs := journalctlCommandOnNode(nodeName, "-u kubelet -n 3 --utc")
578578
if result != logs {
579579
framework.Failf("Failed to receive the correct kubelet logs or the correct amount of lines of logs")
580580
}
@@ -593,7 +593,7 @@ var _ = SIGDescribe("kubelet", func() {
593593
queryCommand := "\"/api/v1/nodes/" + nodeName + "/proxy/logs/?query=kubelet&tailLines=3&boot=0&pattern=kubelet\""
594594
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
595595
result := runKubectlCommand(cmd)
596-
logs := journalctlCommand("-u", "kubelet", "-n 3 --utc")
596+
logs := journalctlCommandOnNode(nodeName, "-u kubelet -n 3 --utc")
597597
if result != logs {
598598
framework.Failf("Failed to receive the correct kubelet logs")
599599
}
@@ -613,7 +613,7 @@ var _ = SIGDescribe("kubelet", func() {
613613
queryCommand := "\"/api/v1/nodes/" + nodeName + "/proxy/logs/?query=kubelet&tailLines=3&sinceTime=" + start.Format(time.RFC3339) + "\""
614614
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
615615
result := runKubectlCommand(cmd)
616-
logs := journalctlCommand("-u", "kubelet", "-n 3 --utc")
616+
logs := journalctlCommandOnNode(nodeName, "-u kubelet -n 3 --utc")
617617
if result != logs {
618618
framework.Failf("Failed to receive the correct kubelet logs or the correct amount of lines of logs")
619619
}
@@ -634,7 +634,7 @@ var _ = SIGDescribe("kubelet", func() {
634634
queryCommand := "\"/api/v1/nodes/" + nodeName + "/proxy/logs/?query=kubelet&tailLines=3&sinceTime=" + start.Format(time.RFC3339) + "\""
635635
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
636636
result := runKubectlCommand(cmd)
637-
logs := journalctlCommand("-u", "kubelet", "--utc")
637+
logs := journalctlCommandOnNode(nodeName, "-u kubelet --utc")
638638
assertContains(result, logs)
639639
}
640640
})
@@ -672,13 +672,9 @@ func assertContains(expectedString string, result string) {
672672
return
673673
}
674674

675-
func journalctlCommand(arg ...string) string {
676-
command := exec.Command("journalctl", arg...)
677-
out, err := command.Output()
678-
if err != nil {
679-
framework.Logf("Command: %v\nError: %v", command, err)
680-
framework.Failf("Error at running journalctl command")
681-
}
682-
framework.Logf("Journalctl output: %s", out)
683-
return string(out)
675+
func journalctlCommandOnNode(nodeName string, args string) string {
676+
result, err := e2essh.NodeExec(context.Background(), nodeName, "journalctl "+args, framework.TestContext.Provider)
677+
framework.ExpectNoError(err)
678+
e2essh.LogResult(result)
679+
return result.Stdout
684680
}

0 commit comments

Comments
 (0)