Skip to content

Commit

Permalink
Merge pull request kubernetes#119571 from haircommander/node-log-quer…
Browse files Browse the repository at this point in the history
…y-on-node

test: fix NodeLogQuery tests to query the correct node for logs
  • Loading branch information
k8s-ci-robot committed Jul 25, 2023
2 parents eb4063f + a248c4d commit dc6d8c6
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions test/e2e/node/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ var _ = SIGDescribe("kubelet", func() {
queryCommand := "\"/api/v1/nodes/" + nodeName + "/proxy/logs/?query=kubelet&tailLines=3\""
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
result := runKubectlCommand(cmd)
logs := journalctlCommand("-u", "kubelet", "-n 3 --utc")
logs := journalctlCommandOnNode(nodeName, "-u kubelet -n 3 --utc")
if result != logs {
framework.Failf("Failed to receive the correct kubelet logs or the correct amount of lines of logs")
}
Expand All @@ -593,7 +593,7 @@ var _ = SIGDescribe("kubelet", func() {
queryCommand := "\"/api/v1/nodes/" + nodeName + "/proxy/logs/?query=kubelet&tailLines=3&boot=0&pattern=kubelet\""
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
result := runKubectlCommand(cmd)
logs := journalctlCommand("-u", "kubelet", "-n 3 --utc")
logs := journalctlCommandOnNode(nodeName, "-u kubelet -n 3 --utc")
if result != logs {
framework.Failf("Failed to receive the correct kubelet logs")
}
Expand All @@ -613,7 +613,7 @@ var _ = SIGDescribe("kubelet", func() {
queryCommand := "\"/api/v1/nodes/" + nodeName + "/proxy/logs/?query=kubelet&tailLines=3&sinceTime=" + start.Format(time.RFC3339) + "\""
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
result := runKubectlCommand(cmd)
logs := journalctlCommand("-u", "kubelet", "-n 3 --utc")
logs := journalctlCommandOnNode(nodeName, "-u kubelet -n 3 --utc")
if result != logs {
framework.Failf("Failed to receive the correct kubelet logs or the correct amount of lines of logs")
}
Expand All @@ -634,7 +634,7 @@ var _ = SIGDescribe("kubelet", func() {
queryCommand := "\"/api/v1/nodes/" + nodeName + "/proxy/logs/?query=kubelet&tailLines=3&sinceTime=" + start.Format(time.RFC3339) + "\""
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
result := runKubectlCommand(cmd)
logs := journalctlCommand("-u", "kubelet", "--utc")
logs := journalctlCommandOnNode(nodeName, "-u kubelet --utc")
assertContains(result, logs)
}
})
Expand Down Expand Up @@ -672,13 +672,9 @@ func assertContains(expectedString string, result string) {
return
}

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

0 comments on commit dc6d8c6

Please sign in to comment.