@@ -390,6 +390,7 @@ func (config *TestConfig) RemoveNode(nodeName string) error {
390
390
if _ , err := RunCommand (cmd ); err != nil {
391
391
return fmt .Errorf ("failed to remove node %s: %v" , nodeName , err )
392
392
}
393
+ fmt .Println ("Stopped and removed " , nodeName )
393
394
return nil
394
395
}
395
396
@@ -428,13 +429,15 @@ func (config *TestConfig) Cleanup() error {
428
429
errs = append (errs , err )
429
430
}
430
431
}
432
+ config .Servers = nil
431
433
432
434
// Stop and remove all agents
433
435
for _ , agent := range config .Agents {
434
436
if err := config .RemoveNode (agent .Name ); err != nil {
435
437
errs = append (errs , err )
436
438
}
437
439
}
440
+ config .Agents = nil
438
441
439
442
// Stop DB if it was started
440
443
if config .DBType == "mysql" || config .DBType == "postgres" {
@@ -456,8 +459,6 @@ func (config *TestConfig) Cleanup() error {
456
459
if config .TestDir != "" {
457
460
return os .RemoveAll (config .TestDir )
458
461
}
459
- config .Agents = nil
460
- config .Servers = nil
461
462
return nil
462
463
}
463
464
@@ -640,10 +641,47 @@ func FetchExternalIPs(kubeconfig string, servicename string) ([]string, error) {
640
641
// RestartCluster restarts the k3s service on each node given
641
642
func RestartCluster (nodes []DockerNode ) error {
642
643
for _ , node := range nodes {
643
- cmd := "systemctl restart k3s* --all"
644
+ // Wait 60 seconds for the restart to succeed.
645
+ // If k3s doesn't report started to systemd within 60 seconds something is wrong.
646
+ cmd := "timeout -v 60 systemctl restart k3s* --all"
644
647
if _ , err := node .RunCmdOnNode (cmd ); err != nil {
645
648
return err
646
649
}
647
650
}
648
651
return nil
649
652
}
653
+
654
+ func DescribeNodesAndPods (config * TestConfig ) string {
655
+ cmd := "kubectl describe node,pod -A --kubeconfig=" + config .KubeconfigFile
656
+ out , err := RunCommand (cmd )
657
+ if err != nil {
658
+ return fmt .Sprintf ("** %v **\n %s" , err , out )
659
+ }
660
+ return out
661
+ }
662
+
663
+ func TailDockerLogs (lines int , nodes []DockerNode ) string {
664
+ logs := & strings.Builder {}
665
+ for _ , node := range nodes {
666
+ cmd := fmt .Sprintf ("docker logs %s --tail=%d" , node .Name , lines )
667
+ if l , err := RunCommand (cmd ); err != nil {
668
+ fmt .Fprintf (logs , "** failed to read docker logs for node %s ***\n %v\n " , node .Name , err )
669
+ } else {
670
+ fmt .Fprintf (logs , "** docker logs for node %s ***\n %s\n " , node .Name , l )
671
+ }
672
+ }
673
+ return logs .String ()
674
+ }
675
+
676
+ func TailJournalLogs (lines int , nodes []DockerNode ) string {
677
+ logs := & strings.Builder {}
678
+ for _ , node := range nodes {
679
+ cmd := fmt .Sprintf ("journalctl -u k3s* --no-pager --lines=%d" , lines )
680
+ if l , err := node .RunCmdOnNode (cmd ); err != nil {
681
+ fmt .Fprintf (logs , "** failed to read journald log for node %s ***\n %v\n " , node .Name , err )
682
+ } else {
683
+ fmt .Fprintf (logs , "** journald log for node %s ***\n %s\n " , node .Name , l )
684
+ }
685
+ }
686
+ return logs .String ()
687
+ }
0 commit comments