mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-06 18:54:06 +00:00
test: Fix NodeLogQuery tests
- Remove redundant tests - Fix formatting of the query command by using fmt.Sprintf to prevent spurious characters from being introduced - Fix running of the journalctl command on the node by add the default options - Restrict running the tests on a single node
This commit is contained in:
parent
263ab254ef
commit
6b6be38896
@ -458,186 +458,122 @@ var _ = SIGDescribe("kubelet", func() {
|
|||||||
|
|
||||||
// Tests for NodeLogQuery feature
|
// Tests for NodeLogQuery feature
|
||||||
f.Describe("kubectl get --raw \"/api/v1/nodes/<insert-node-name-here>/proxy/logs/?query=/<insert-log-file-name-here>", feature.NodeLogQuery, "[LinuxOnly]", func() {
|
f.Describe("kubectl get --raw \"/api/v1/nodes/<insert-node-name-here>/proxy/logs/?query=/<insert-log-file-name-here>", feature.NodeLogQuery, "[LinuxOnly]", func() {
|
||||||
var (
|
var linuxNodeName string
|
||||||
numNodes int
|
|
||||||
nodeNames sets.String
|
|
||||||
)
|
|
||||||
|
|
||||||
ginkgo.BeforeEach(func(ctx context.Context) {
|
ginkgo.BeforeEach(func(ctx context.Context) {
|
||||||
nodes, err := e2enode.GetBoundedReadySchedulableNodes(ctx, c, maxNodesToCheck)
|
nodes, err := e2enode.GetReadyNodesIncludingTainted(ctx, c)
|
||||||
numNodes = len(nodes.Items)
|
|
||||||
framework.ExpectNoError(err)
|
framework.ExpectNoError(err)
|
||||||
nodeNames = sets.NewString()
|
if len(nodes.Items) == 0 {
|
||||||
for i := 0; i < numNodes; i++ {
|
framework.Fail("Expected at least one Linux node to be present")
|
||||||
nodeNames.Insert(nodes.Items[i].Name)
|
|
||||||
}
|
}
|
||||||
|
linuxNodeName = nodes.Items[0].Name
|
||||||
})
|
})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Test if kubectl get --raw "/api/v1/nodes/<insert-node-name-here>/proxy/logs/?"
|
Test if kubectl get --raw "/api/v1/nodes/<insert-node-name-here>/proxy/logs/?query"
|
||||||
returns an error or not!
|
returns an error!
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ginkgo.It("should return the error of running without --query option", func() {
|
ginkgo.It("should return the error with an empty --query option", func() {
|
||||||
ginkgo.By("Starting the command")
|
ginkgo.By("Starting the command")
|
||||||
tk := e2ekubectl.NewTestKubeconfig(framework.TestContext.CertDir, framework.TestContext.Host, framework.TestContext.KubeConfig, framework.TestContext.KubeContext, framework.TestContext.KubectlPath, ns)
|
tk := e2ekubectl.NewTestKubeconfig(framework.TestContext.CertDir, framework.TestContext.Host, framework.TestContext.KubeConfig, framework.TestContext.KubeContext, framework.TestContext.KubectlPath, ns)
|
||||||
|
|
||||||
for nodeName := range nodeNames {
|
queryCommand := fmt.Sprintf("/api/v1/nodes/%s/proxy/logs/?query", linuxNodeName)
|
||||||
queryCommand := "\"/api/v1/nodes/" + nodeName + "/proxy/logs/?"
|
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
|
||||||
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
|
_, _, err := framework.StartCmdAndStreamOutput(cmd)
|
||||||
_, _, err := framework.StartCmdAndStreamOutput(cmd)
|
if err != nil {
|
||||||
if err != nil {
|
framework.Failf("Failed to start kubectl command! Error: %v", err)
|
||||||
framework.Failf("Failed to start kubectl command! Error: %v", err)
|
|
||||||
}
|
|
||||||
err = cmd.Wait()
|
|
||||||
if err == nil {
|
|
||||||
framework.Failf("Command kubectl get --raw" + queryCommand + " was expected to return an error!")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
err = cmd.Wait()
|
||||||
|
gomega.Expect(err).To(gomega.HaveOccurred(), "Command kubectl get --raw "+queryCommand+" was expected to return an error!")
|
||||||
})
|
})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Test if kubectl get --raw "/api/v1/nodes/<insert-node-name-here>/proxy/logs/?query=kubelet"
|
Test if kubectl get --raw "/api/v1/nodes/<insert-node-name-here>/proxy/logs/?query=kubelet"
|
||||||
returns the kubelet logs or not!
|
returns the kubelet logs
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ginkgo.It("should return the logs ", func(ctx context.Context) {
|
ginkgo.It("should return the kubelet logs ", func(ctx context.Context) {
|
||||||
ginkgo.By("Starting the command")
|
ginkgo.By("Starting the command")
|
||||||
tk := e2ekubectl.NewTestKubeconfig(framework.TestContext.CertDir, framework.TestContext.Host, framework.TestContext.KubeConfig, framework.TestContext.KubeContext, framework.TestContext.KubectlPath, ns)
|
tk := e2ekubectl.NewTestKubeconfig(framework.TestContext.CertDir, framework.TestContext.Host, framework.TestContext.KubeConfig, framework.TestContext.KubeContext, framework.TestContext.KubectlPath, ns)
|
||||||
|
|
||||||
for nodeName := range nodeNames {
|
queryCommand := fmt.Sprintf("/api/v1/nodes/%s/proxy/logs/?query=kubelet", linuxNodeName)
|
||||||
queryCommand := "\"/api/v1/nodes/" + nodeName + "/proxy/logs/?query=kubelet\""
|
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
|
||||||
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
|
result := runKubectlCommand(cmd)
|
||||||
result := runKubectlCommand(cmd)
|
assertContains("kubelet", result)
|
||||||
assertContains("kubelet", result)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
/*
|
|
||||||
Test if kubectl get --raw "/api/v1/nodes/<insert-node-name-here>/proxy/logs/?query=kubelet&pattern=container"
|
|
||||||
returns something or not!
|
|
||||||
*/
|
|
||||||
|
|
||||||
ginkgo.It("should return the logs filtered by pattern container", func(ctx context.Context) {
|
|
||||||
ginkgo.By("Starting the command")
|
|
||||||
tk := e2ekubectl.NewTestKubeconfig(framework.TestContext.CertDir, framework.TestContext.Host, framework.TestContext.KubeConfig, framework.TestContext.KubeContext, framework.TestContext.KubectlPath, ns)
|
|
||||||
|
|
||||||
for nodeName := range nodeNames {
|
|
||||||
queryCommand := "\"/api/v1/nodes/" + nodeName + "/proxy/logs/?query=kubelet&pattern=container\""
|
|
||||||
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
|
|
||||||
result := runKubectlCommand(cmd)
|
|
||||||
assertContains("container", result)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Test if kubectl get --raw "/api/v1/nodes/<insert-node-name-here>/proxy/logs/?query=kubelet&boot=0"
|
Test if kubectl get --raw "/api/v1/nodes/<insert-node-name-here>/proxy/logs/?query=kubelet&boot=0"
|
||||||
returns something or not!
|
returns kubelet logs from the current boot
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ginkgo.It("should return the kubelet logs for the current boot", func(ctx context.Context) {
|
ginkgo.It("should return the kubelet logs for the current boot", func(ctx context.Context) {
|
||||||
ginkgo.By("Starting the command")
|
ginkgo.By("Starting the command")
|
||||||
tk := e2ekubectl.NewTestKubeconfig(framework.TestContext.CertDir, framework.TestContext.Host, framework.TestContext.KubeConfig, framework.TestContext.KubeContext, framework.TestContext.KubectlPath, ns)
|
tk := e2ekubectl.NewTestKubeconfig(framework.TestContext.CertDir, framework.TestContext.Host, framework.TestContext.KubeConfig, framework.TestContext.KubeContext, framework.TestContext.KubectlPath, ns)
|
||||||
|
|
||||||
for nodeName := range nodeNames {
|
queryCommand := fmt.Sprintf("/api/v1/nodes/%s/proxy/logs/?query=kubelet&boot=0", linuxNodeName)
|
||||||
queryCommand := "\"/api/v1/nodes/" + nodeName + "/proxy/logs/?query=kubelet&boot=0\""
|
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
|
||||||
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
|
result := runKubectlCommand(cmd)
|
||||||
result := runKubectlCommand(cmd)
|
assertContains("kubelet", result)
|
||||||
assertContains("kubelet", result)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Test if kubectl get --raw "/api/v1/nodes/<insert-node-name-here>/proxy/logs/?query=kubelet&boot=-1"
|
Test if kubectl get --raw "/api/v1/nodes/<insert-node-name-here>/proxy/logs/?query=kubelet&tailLines=3"
|
||||||
returns something or not!
|
returns the last three lines of the kubelet log
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ginkgo.It("should return the kubelet logs for the previous boot", func(ctx context.Context) {
|
ginkgo.It("should return the last three lines of the kubelet logs", func(ctx context.Context) {
|
||||||
|
e2eskipper.SkipUnlessProviderIs(framework.ProvidersWithSSH...)
|
||||||
ginkgo.By("Starting the command")
|
ginkgo.By("Starting the command")
|
||||||
tk := e2ekubectl.NewTestKubeconfig(framework.TestContext.CertDir, framework.TestContext.Host, framework.TestContext.KubeConfig, framework.TestContext.KubeContext, framework.TestContext.KubectlPath, ns)
|
tk := e2ekubectl.NewTestKubeconfig(framework.TestContext.CertDir, framework.TestContext.Host, framework.TestContext.KubeConfig, framework.TestContext.KubeContext, framework.TestContext.KubectlPath, ns)
|
||||||
|
|
||||||
for nodeName := range nodeNames {
|
queryCommand := fmt.Sprintf("/api/v1/nodes/%s/proxy/logs/?query=kubelet&tailLines=3", linuxNodeName)
|
||||||
queryCommand := "\"/api/v1/nodes/" + nodeName + "/proxy/logs/?query=kubelet&boot=-1\""
|
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
|
||||||
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
|
result := runKubectlCommand(cmd)
|
||||||
result := runKubectlCommand(cmd)
|
logs := journalctlCommandOnNode(linuxNodeName, "-u kubelet -n 3")
|
||||||
assertContains("kubelet", result)
|
if result != logs {
|
||||||
|
framework.Failf("Failed to receive the correct kubelet logs or the correct amount of lines of logs")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Test if kubectl get --raw "/api/v1/nodes/<insert-node-name-here>/proxy/logs/?query=kubelet&tailLines=2"
|
Test if kubectl get --raw "/api/v1/nodes/<insert-node-name-here>/proxy/logs/?query=kubelet&pattern=kubelet"
|
||||||
returns something or not!
|
returns kubelet logs for the current boot with the pattern container
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ginkgo.It("should return the kubelet logs for the previous boot", func(ctx context.Context) {
|
ginkgo.It("should return the kubelet logs for the current boot with the pattern container", func(ctx context.Context) {
|
||||||
|
e2eskipper.SkipUnlessProviderIs(framework.ProvidersWithSSH...)
|
||||||
ginkgo.By("Starting the command")
|
ginkgo.By("Starting the command")
|
||||||
tk := e2ekubectl.NewTestKubeconfig(framework.TestContext.CertDir, framework.TestContext.Host, framework.TestContext.KubeConfig, framework.TestContext.KubeContext, framework.TestContext.KubectlPath, ns)
|
tk := e2ekubectl.NewTestKubeconfig(framework.TestContext.CertDir, framework.TestContext.Host, framework.TestContext.KubeConfig, framework.TestContext.KubeContext, framework.TestContext.KubectlPath, ns)
|
||||||
for nodeName := range nodeNames {
|
|
||||||
queryCommand := "\"/api/v1/nodes/" + nodeName + "/proxy/logs/?query=kubelet&tailLines=3\""
|
queryCommand := fmt.Sprintf("/api/v1/nodes/%s/proxy/logs/?query=kubelet&boot=0&pattern=container", linuxNodeName)
|
||||||
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
|
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
|
||||||
result := runKubectlCommand(cmd)
|
result := runKubectlCommand(cmd)
|
||||||
logs := journalctlCommandOnNode(nodeName, "-u kubelet -n 3 --utc")
|
logs := journalctlCommandOnNode(linuxNodeName, "-u kubelet --grep container --boot 0")
|
||||||
if result != logs {
|
if result != logs {
|
||||||
framework.Failf("Failed to receive the correct kubelet logs or the correct amount of lines of logs")
|
framework.Failf("Failed to receive the correct kubelet logs")
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Test if kubectl get --raw "/api/v1/nodes/<insert-node-name-here>/proxy/logs/?query=kubelet&tailLines=2&pattern=kubelet&boot=0"
|
Test if kubectl get --raw "/api/v1/nodes/<insert-node-name-here>/proxy/logs/?query=kubelet&sinceTime=<now>"
|
||||||
returns something or not!
|
returns the kubelet since the current date and time. This can be "-- No entries --" which is correct.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ginkgo.It("should return the kubelet logs for the current boot with pattern error and output in 2 lines", func(ctx context.Context) {
|
ginkgo.It("should return the kubelet logs since the current date and time", func() {
|
||||||
ginkgo.By("Starting the command")
|
|
||||||
tk := e2ekubectl.NewTestKubeconfig(framework.TestContext.CertDir, framework.TestContext.Host, framework.TestContext.KubeConfig, framework.TestContext.KubeContext, framework.TestContext.KubectlPath, ns)
|
|
||||||
for nodeName := range nodeNames {
|
|
||||||
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 := journalctlCommandOnNode(nodeName, "-u kubelet -n 3 --utc")
|
|
||||||
if result != logs {
|
|
||||||
framework.Failf("Failed to receive the correct kubelet logs")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
/*
|
|
||||||
Test if kubectl get --raw "/api/v1/nodes/<insert-node-name-here>/proxy/logs/?query=kubelet&tailLines=3&untilTime=<now>"
|
|
||||||
returns the kubelet logs or not!
|
|
||||||
*/
|
|
||||||
|
|
||||||
ginkgo.It("should return the logs for the requested query until the current date and time", func() {
|
|
||||||
ginkgo.By("Starting the command")
|
ginkgo.By("Starting the command")
|
||||||
start := time.Now().UTC()
|
start := time.Now().UTC()
|
||||||
tk := e2ekubectl.NewTestKubeconfig(framework.TestContext.CertDir, framework.TestContext.Host, framework.TestContext.KubeConfig, framework.TestContext.KubeContext, framework.TestContext.KubectlPath, ns)
|
tk := e2ekubectl.NewTestKubeconfig(framework.TestContext.CertDir, framework.TestContext.Host, framework.TestContext.KubeConfig, framework.TestContext.KubeContext, framework.TestContext.KubectlPath, ns)
|
||||||
for nodeName := range nodeNames {
|
|
||||||
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 := 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")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
/*
|
currentTime := start.Format(time.RFC3339)
|
||||||
Test if kubectl get --raw "/api/v1/nodes/<insert-node-name-here>/proxy/logs/?query=kubelet&tailLines=3&sinceTime=4 hours ago"
|
queryCommand := fmt.Sprintf("/api/v1/nodes/%s/proxy/logs/?query=kubelet&sinceTime=%s", linuxNodeName, currentTime)
|
||||||
returns the kubelet logs or not!
|
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
|
||||||
*/
|
journalctlDateLayout := "2006-1-2 15:4:5"
|
||||||
|
result := runKubectlCommand(cmd)
|
||||||
ginkgo.It("should return the logs for the requested query since the current date and time", func() {
|
logs := journalctlCommandOnNode(linuxNodeName, fmt.Sprintf("-u kubelet --since \"%s\"", start.Format(journalctlDateLayout)))
|
||||||
ginkgo.By("Starting the command")
|
if result != logs {
|
||||||
start := time.Now().UTC()
|
framework.Failf("Failed to receive the correct kubelet logs or the correct amount of lines of logs")
|
||||||
start = start.Add(time.Duration(-4) * time.Hour)
|
|
||||||
tk := e2ekubectl.NewTestKubeconfig(framework.TestContext.CertDir, framework.TestContext.Host, framework.TestContext.KubeConfig, framework.TestContext.KubeContext, framework.TestContext.KubectlPath, ns)
|
|
||||||
for nodeName := range nodeNames {
|
|
||||||
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 := journalctlCommandOnNode(nodeName, "-u kubelet --utc")
|
|
||||||
assertContains(result, logs)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -671,11 +607,11 @@ func assertContains(expectedString string, result string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
framework.Failf("Failed to find \"%s\"", expectedString)
|
framework.Failf("Failed to find \"%s\"", expectedString)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func journalctlCommandOnNode(nodeName string, args string) string {
|
func journalctlCommandOnNode(nodeName string, args string) string {
|
||||||
result, err := e2essh.NodeExec(context.Background(), nodeName, "journalctl "+args, framework.TestContext.Provider)
|
result, err := e2essh.NodeExec(context.Background(), nodeName,
|
||||||
|
"journalctl --utc --no-pager --output=short-precise "+args, framework.TestContext.Provider)
|
||||||
framework.ExpectNoError(err)
|
framework.ExpectNoError(err)
|
||||||
e2essh.LogResult(result)
|
e2essh.LogResult(result)
|
||||||
return result.Stdout
|
return result.Stdout
|
||||||
|
Loading…
Reference in New Issue
Block a user