Skip to content

Commit 36930f4

Browse files
authored
Merge pull request kubernetes#121707 from aravindhp/fix-node-log-viewer-e2e-test
test: Fix NodeLogQuery tests
2 parents 5dc9453 + 6b6be38 commit 36930f4

File tree

1 file changed

+59
-123
lines changed

1 file changed

+59
-123
lines changed

test/e2e/node/kubelet.go

Lines changed: 59 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -458,186 +458,122 @@ var _ = SIGDescribe("kubelet", func() {
458458

459459
// Tests for NodeLogQuery feature
460460
f.Describe("kubectl get --raw \"/api/v1/nodes/<insert-node-name-here>/proxy/logs/?query=/<insert-log-file-name-here>", feature.NodeLogQuery, "[LinuxOnly]", func() {
461-
var (
462-
numNodes int
463-
nodeNames sets.String
464-
)
461+
var linuxNodeName string
465462

466463
ginkgo.BeforeEach(func(ctx context.Context) {
467-
nodes, err := e2enode.GetBoundedReadySchedulableNodes(ctx, c, maxNodesToCheck)
468-
numNodes = len(nodes.Items)
464+
nodes, err := e2enode.GetReadyNodesIncludingTainted(ctx, c)
469465
framework.ExpectNoError(err)
470-
nodeNames = sets.NewString()
471-
for i := 0; i < numNodes; i++ {
472-
nodeNames.Insert(nodes.Items[i].Name)
466+
if len(nodes.Items) == 0 {
467+
framework.Fail("Expected at least one Linux node to be present")
473468
}
469+
linuxNodeName = nodes.Items[0].Name
474470
})
475471

476472
/*
477-
Test if kubectl get --raw "/api/v1/nodes/<insert-node-name-here>/proxy/logs/?"
478-
returns an error or not!
473+
Test if kubectl get --raw "/api/v1/nodes/<insert-node-name-here>/proxy/logs/?query"
474+
returns an error!
479475
*/
480476

481-
ginkgo.It("should return the error of running without --query option", func() {
477+
ginkgo.It("should return the error with an empty --query option", func() {
482478
ginkgo.By("Starting the command")
483479
tk := e2ekubectl.NewTestKubeconfig(framework.TestContext.CertDir, framework.TestContext.Host, framework.TestContext.KubeConfig, framework.TestContext.KubeContext, framework.TestContext.KubectlPath, ns)
484480

485-
for nodeName := range nodeNames {
486-
queryCommand := "\"/api/v1/nodes/" + nodeName + "/proxy/logs/?"
487-
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
488-
_, _, err := framework.StartCmdAndStreamOutput(cmd)
489-
if err != nil {
490-
framework.Failf("Failed to start kubectl command! Error: %v", err)
491-
}
492-
err = cmd.Wait()
493-
if err == nil {
494-
framework.Failf("Command kubectl get --raw" + queryCommand + " was expected to return an error!")
495-
}
481+
queryCommand := fmt.Sprintf("/api/v1/nodes/%s/proxy/logs/?query", linuxNodeName)
482+
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
483+
_, _, err := framework.StartCmdAndStreamOutput(cmd)
484+
if err != nil {
485+
framework.Failf("Failed to start kubectl command! Error: %v", err)
496486
}
487+
err = cmd.Wait()
488+
gomega.Expect(err).To(gomega.HaveOccurred(), "Command kubectl get --raw "+queryCommand+" was expected to return an error!")
497489
})
498490

499491
/*
500492
Test if kubectl get --raw "/api/v1/nodes/<insert-node-name-here>/proxy/logs/?query=kubelet"
501-
returns the kubelet logs or not!
502-
*/
503-
504-
ginkgo.It("should return the logs ", func(ctx context.Context) {
505-
ginkgo.By("Starting the command")
506-
tk := e2ekubectl.NewTestKubeconfig(framework.TestContext.CertDir, framework.TestContext.Host, framework.TestContext.KubeConfig, framework.TestContext.KubeContext, framework.TestContext.KubectlPath, ns)
507-
508-
for nodeName := range nodeNames {
509-
queryCommand := "\"/api/v1/nodes/" + nodeName + "/proxy/logs/?query=kubelet\""
510-
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
511-
result := runKubectlCommand(cmd)
512-
assertContains("kubelet", result)
513-
}
514-
})
515-
516-
/*
517-
Test if kubectl get --raw "/api/v1/nodes/<insert-node-name-here>/proxy/logs/?query=kubelet&pattern=container"
518-
returns something or not!
493+
returns the kubelet logs
519494
*/
520495

521-
ginkgo.It("should return the logs filtered by pattern container", func(ctx context.Context) {
496+
ginkgo.It("should return the kubelet logs ", func(ctx context.Context) {
522497
ginkgo.By("Starting the command")
523498
tk := e2ekubectl.NewTestKubeconfig(framework.TestContext.CertDir, framework.TestContext.Host, framework.TestContext.KubeConfig, framework.TestContext.KubeContext, framework.TestContext.KubectlPath, ns)
524499

525-
for nodeName := range nodeNames {
526-
queryCommand := "\"/api/v1/nodes/" + nodeName + "/proxy/logs/?query=kubelet&pattern=container\""
527-
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
528-
result := runKubectlCommand(cmd)
529-
assertContains("container", result)
530-
}
500+
queryCommand := fmt.Sprintf("/api/v1/nodes/%s/proxy/logs/?query=kubelet", linuxNodeName)
501+
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
502+
result := runKubectlCommand(cmd)
503+
assertContains("kubelet", result)
531504
})
532505

533506
/*
534507
Test if kubectl get --raw "/api/v1/nodes/<insert-node-name-here>/proxy/logs/?query=kubelet&boot=0"
535-
returns something or not!
508+
returns kubelet logs from the current boot
536509
*/
537510

538511
ginkgo.It("should return the kubelet logs for the current boot", func(ctx context.Context) {
539512
ginkgo.By("Starting the command")
540513
tk := e2ekubectl.NewTestKubeconfig(framework.TestContext.CertDir, framework.TestContext.Host, framework.TestContext.KubeConfig, framework.TestContext.KubeContext, framework.TestContext.KubectlPath, ns)
541514

542-
for nodeName := range nodeNames {
543-
queryCommand := "\"/api/v1/nodes/" + nodeName + "/proxy/logs/?query=kubelet&boot=0\""
544-
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
545-
result := runKubectlCommand(cmd)
546-
assertContains("kubelet", result)
547-
}
515+
queryCommand := fmt.Sprintf("/api/v1/nodes/%s/proxy/logs/?query=kubelet&boot=0", linuxNodeName)
516+
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
517+
result := runKubectlCommand(cmd)
518+
assertContains("kubelet", result)
548519
})
549520

550521
/*
551-
Test if kubectl get --raw "/api/v1/nodes/<insert-node-name-here>/proxy/logs/?query=kubelet&boot=-1"
552-
returns something or not!
522+
Test if kubectl get --raw "/api/v1/nodes/<insert-node-name-here>/proxy/logs/?query=kubelet&tailLines=3"
523+
returns the last three lines of the kubelet log
553524
*/
554525

555-
ginkgo.It("should return the kubelet logs for the previous boot", func(ctx context.Context) {
526+
ginkgo.It("should return the last three lines of the kubelet logs", func(ctx context.Context) {
527+
e2eskipper.SkipUnlessProviderIs(framework.ProvidersWithSSH...)
556528
ginkgo.By("Starting the command")
557529
tk := e2ekubectl.NewTestKubeconfig(framework.TestContext.CertDir, framework.TestContext.Host, framework.TestContext.KubeConfig, framework.TestContext.KubeContext, framework.TestContext.KubectlPath, ns)
558530

559-
for nodeName := range nodeNames {
560-
queryCommand := "\"/api/v1/nodes/" + nodeName + "/proxy/logs/?query=kubelet&boot=-1\""
561-
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
562-
result := runKubectlCommand(cmd)
563-
assertContains("kubelet", result)
531+
queryCommand := fmt.Sprintf("/api/v1/nodes/%s/proxy/logs/?query=kubelet&tailLines=3", linuxNodeName)
532+
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
533+
result := runKubectlCommand(cmd)
534+
logs := journalctlCommandOnNode(linuxNodeName, "-u kubelet -n 3")
535+
if result != logs {
536+
framework.Failf("Failed to receive the correct kubelet logs or the correct amount of lines of logs")
564537
}
565538
})
566539

567540
/*
568-
Test if kubectl get --raw "/api/v1/nodes/<insert-node-name-here>/proxy/logs/?query=kubelet&tailLines=2"
569-
returns something or not!
541+
Test if kubectl get --raw "/api/v1/nodes/<insert-node-name-here>/proxy/logs/?query=kubelet&pattern=kubelet"
542+
returns kubelet logs for the current boot with the pattern container
570543
*/
571544

572-
ginkgo.It("should return the kubelet logs for the previous boot", func(ctx context.Context) {
545+
ginkgo.It("should return the kubelet logs for the current boot with the pattern container", func(ctx context.Context) {
546+
e2eskipper.SkipUnlessProviderIs(framework.ProvidersWithSSH...)
573547
ginkgo.By("Starting the command")
574548
tk := e2ekubectl.NewTestKubeconfig(framework.TestContext.CertDir, framework.TestContext.Host, framework.TestContext.KubeConfig, framework.TestContext.KubeContext, framework.TestContext.KubectlPath, ns)
575-
for nodeName := range nodeNames {
576-
queryCommand := "\"/api/v1/nodes/" + nodeName + "/proxy/logs/?query=kubelet&tailLines=3\""
577-
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
578-
result := runKubectlCommand(cmd)
579-
logs := journalctlCommandOnNode(nodeName, "-u kubelet -n 3 --utc")
580-
if result != logs {
581-
framework.Failf("Failed to receive the correct kubelet logs or the correct amount of lines of logs")
582-
}
583-
}
584-
})
585-
586-
/*
587-
Test if kubectl get --raw "/api/v1/nodes/<insert-node-name-here>/proxy/logs/?query=kubelet&tailLines=2&pattern=kubelet&boot=0"
588-
returns something or not!
589-
*/
590549

591-
ginkgo.It("should return the kubelet logs for the current boot with pattern error and output in 2 lines", func(ctx context.Context) {
592-
ginkgo.By("Starting the command")
593-
tk := e2ekubectl.NewTestKubeconfig(framework.TestContext.CertDir, framework.TestContext.Host, framework.TestContext.KubeConfig, framework.TestContext.KubeContext, framework.TestContext.KubectlPath, ns)
594-
for nodeName := range nodeNames {
595-
queryCommand := "\"/api/v1/nodes/" + nodeName + "/proxy/logs/?query=kubelet&tailLines=3&boot=0&pattern=kubelet\""
596-
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
597-
result := runKubectlCommand(cmd)
598-
logs := journalctlCommandOnNode(nodeName, "-u kubelet -n 3 --utc")
599-
if result != logs {
600-
framework.Failf("Failed to receive the correct kubelet logs")
601-
}
550+
queryCommand := fmt.Sprintf("/api/v1/nodes/%s/proxy/logs/?query=kubelet&boot=0&pattern=container", linuxNodeName)
551+
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
552+
result := runKubectlCommand(cmd)
553+
logs := journalctlCommandOnNode(linuxNodeName, "-u kubelet --grep container --boot 0")
554+
if result != logs {
555+
framework.Failf("Failed to receive the correct kubelet logs")
602556
}
603557
})
604558

605559
/*
606-
Test if kubectl get --raw "/api/v1/nodes/<insert-node-name-here>/proxy/logs/?query=kubelet&tailLines=3&untilTime=<now>"
607-
returns the kubelet logs or not!
560+
Test if kubectl get --raw "/api/v1/nodes/<insert-node-name-here>/proxy/logs/?query=kubelet&sinceTime=<now>"
561+
returns the kubelet since the current date and time. This can be "-- No entries --" which is correct.
608562
*/
609563

610-
ginkgo.It("should return the logs for the requested query until the current date and time", func() {
564+
ginkgo.It("should return the kubelet logs since the current date and time", func() {
611565
ginkgo.By("Starting the command")
612566
start := time.Now().UTC()
613567
tk := e2ekubectl.NewTestKubeconfig(framework.TestContext.CertDir, framework.TestContext.Host, framework.TestContext.KubeConfig, framework.TestContext.KubeContext, framework.TestContext.KubectlPath, ns)
614-
for nodeName := range nodeNames {
615-
queryCommand := "\"/api/v1/nodes/" + nodeName + "/proxy/logs/?query=kubelet&tailLines=3&sinceTime=" + start.Format(time.RFC3339) + "\""
616-
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
617-
result := runKubectlCommand(cmd)
618-
logs := journalctlCommandOnNode(nodeName, "-u kubelet -n 3 --utc")
619-
if result != logs {
620-
framework.Failf("Failed to receive the correct kubelet logs or the correct amount of lines of logs")
621-
}
622-
}
623-
})
624-
625-
/*
626-
Test if kubectl get --raw "/api/v1/nodes/<insert-node-name-here>/proxy/logs/?query=kubelet&tailLines=3&sinceTime=4 hours ago"
627-
returns the kubelet logs or not!
628-
*/
629568

630-
ginkgo.It("should return the logs for the requested query since the current date and time", func() {
631-
ginkgo.By("Starting the command")
632-
start := time.Now().UTC()
633-
start = start.Add(time.Duration(-4) * time.Hour)
634-
tk := e2ekubectl.NewTestKubeconfig(framework.TestContext.CertDir, framework.TestContext.Host, framework.TestContext.KubeConfig, framework.TestContext.KubeContext, framework.TestContext.KubectlPath, ns)
635-
for nodeName := range nodeNames {
636-
queryCommand := "\"/api/v1/nodes/" + nodeName + "/proxy/logs/?query=kubelet&tailLines=3&sinceTime=" + start.Format(time.RFC3339) + "\""
637-
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
638-
result := runKubectlCommand(cmd)
639-
logs := journalctlCommandOnNode(nodeName, "-u kubelet --utc")
640-
assertContains(result, logs)
569+
currentTime := start.Format(time.RFC3339)
570+
queryCommand := fmt.Sprintf("/api/v1/nodes/%s/proxy/logs/?query=kubelet&sinceTime=%s", linuxNodeName, currentTime)
571+
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
572+
journalctlDateLayout := "2006-1-2 15:4:5"
573+
result := runKubectlCommand(cmd)
574+
logs := journalctlCommandOnNode(linuxNodeName, fmt.Sprintf("-u kubelet --since \"%s\"", start.Format(journalctlDateLayout)))
575+
if result != logs {
576+
framework.Failf("Failed to receive the correct kubelet logs or the correct amount of lines of logs")
641577
}
642578
})
643579
})
@@ -671,11 +607,11 @@ func assertContains(expectedString string, result string) {
671607
return
672608
}
673609
framework.Failf("Failed to find \"%s\"", expectedString)
674-
return
675610
}
676611

677612
func journalctlCommandOnNode(nodeName string, args string) string {
678-
result, err := e2essh.NodeExec(context.Background(), nodeName, "journalctl "+args, framework.TestContext.Provider)
613+
result, err := e2essh.NodeExec(context.Background(), nodeName,
614+
"journalctl --utc --no-pager --output=short-precise "+args, framework.TestContext.Provider)
679615
framework.ExpectNoError(err)
680616
e2essh.LogResult(result)
681617
return result.Stdout

0 commit comments

Comments
 (0)