@@ -458,186 +458,122 @@ var _ = SIGDescribe("kubelet", func() {
458
458
459
459
// Tests for NodeLogQuery feature
460
460
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
465
462
466
463
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 )
469
465
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" )
473
468
}
469
+ linuxNodeName = nodes .Items [0 ].Name
474
470
})
475
471
476
472
/*
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!
479
475
*/
480
476
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 () {
482
478
ginkgo .By ("Starting the command" )
483
479
tk := e2ekubectl .NewTestKubeconfig (framework .TestContext .CertDir , framework .TestContext .Host , framework .TestContext .KubeConfig , framework .TestContext .KubeContext , framework .TestContext .KubectlPath , ns )
484
480
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 )
496
486
}
487
+ err = cmd .Wait ()
488
+ gomega .Expect (err ).To (gomega .HaveOccurred (), "Command kubectl get --raw " + queryCommand + " was expected to return an error!" )
497
489
})
498
490
499
491
/*
500
492
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
519
494
*/
520
495
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 ) {
522
497
ginkgo .By ("Starting the command" )
523
498
tk := e2ekubectl .NewTestKubeconfig (framework .TestContext .CertDir , framework .TestContext .Host , framework .TestContext .KubeConfig , framework .TestContext .KubeContext , framework .TestContext .KubectlPath , ns )
524
499
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 )
531
504
})
532
505
533
506
/*
534
507
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
536
509
*/
537
510
538
511
ginkgo .It ("should return the kubelet logs for the current boot" , func (ctx context.Context ) {
539
512
ginkgo .By ("Starting the command" )
540
513
tk := e2ekubectl .NewTestKubeconfig (framework .TestContext .CertDir , framework .TestContext .Host , framework .TestContext .KubeConfig , framework .TestContext .KubeContext , framework .TestContext .KubectlPath , ns )
541
514
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 )
548
519
})
549
520
550
521
/*
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
553
524
*/
554
525
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 ... )
556
528
ginkgo .By ("Starting the command" )
557
529
tk := e2ekubectl .NewTestKubeconfig (framework .TestContext .CertDir , framework .TestContext .Host , framework .TestContext .KubeConfig , framework .TestContext .KubeContext , framework .TestContext .KubectlPath , ns )
558
530
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" )
564
537
}
565
538
})
566
539
567
540
/*
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
570
543
*/
571
544
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 ... )
573
547
ginkgo .By ("Starting the command" )
574
548
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
- */
590
549
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" )
602
556
}
603
557
})
604
558
605
559
/*
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.
608
562
*/
609
563
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 () {
611
565
ginkgo .By ("Starting the command" )
612
566
start := time .Now ().UTC ()
613
567
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
- */
629
568
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" )
641
577
}
642
578
})
643
579
})
@@ -671,11 +607,11 @@ func assertContains(expectedString string, result string) {
671
607
return
672
608
}
673
609
framework .Failf ("Failed to find \" %s\" " , expectedString )
674
- return
675
610
}
676
611
677
612
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 )
679
615
framework .ExpectNoError (err )
680
616
e2essh .LogResult (result )
681
617
return result .Stdout
0 commit comments