@@ -37,7 +37,7 @@ func clusterReset(cluster *shared.Cluster, resetCmd string) {
3737 resetRes string
3838 resetCmdErr error
3939 )
40-
40+ // running cluster reset command on the first server node.
4141 resetRes , resetCmdErr = shared .RunCommandOnNode (resetCmd , cluster .ServerIPs [0 ])
4242 shared .LogLevel ("debug" , "Cluster reset command output: %s" , resetRes )
4343 shared .LogLevel ("debug" , "Cluster reset command error: %v" , resetCmdErr )
@@ -51,11 +51,20 @@ func killall(cluster *shared.Cluster) {
5151 shared .LogLevel ("debug" , "Found killall script at: %s" , killallLocationCmd )
5252 Expect (findErr ).NotTo (HaveOccurred ())
5353
54- for i := len (cluster .ServerIPs ) - 1 ; i >= 0 ; i -- {
55- _ , err := shared .RunCommandOnNode ("sudo " + killallLocationCmd , cluster .ServerIPs [i ])
54+ // Run killall on only the secondary servers and not the primary.
55+ if len (cluster .ServerIPs ) > 1 {
56+ for i := len (cluster .ServerIPs ) - 1 ; i > 0 ; i -- {
57+ _ , err := shared .RunCommandOnNode ("sudo " + killallLocationCmd , cluster .ServerIPs [i ])
58+ Expect (err ).NotTo (HaveOccurred ())
59+ }
60+ } else { // len(cluster.ServerIPs) <= 1 Only one server node present in cluster.
61+ shared .LogLevel ("info" , "Only one server node present, skipping killall on secondary servers" )
62+ // Run killall on the primary server for a 1 server node cluster.
63+ _ , err := shared .RunCommandOnNode ("sudo " + killallLocationCmd , cluster .ServerIPs [0 ])
5664 Expect (err ).NotTo (HaveOccurred ())
5765 }
5866
67+
5968 // since we have killed the server, the kubectl command will fail.
6069 res , _ := shared .RunCommandHost ("kubectl get nodes --kubeconfig=" + shared .KubeConfigFile )
6170 Expect (res ).To (SatisfyAny (ContainSubstring ("timed out" ), ContainSubstring ("refused" )))
@@ -106,7 +115,8 @@ func restartServer(cluster *shared.Cluster, ms *shared.ManageService) {
106115}
107116
108117func deleteDataDirectories (cluster * shared.Cluster ) {
109- for i := len (cluster .ServerIPs ) - 1 ; i >= 0 ; i -- {
118+ // Deleting data directories from secondary servers, not the primary server.
119+ for i := len (cluster .ServerIPs ) - 1 ; i > 0 ; i -- {
110120 deleteCmd := fmt .Sprintf ("sudo rm -rf /var/lib/rancher/%s/server/db" , cluster .Config .Product )
111121 _ , deleteErr := shared .RunCommandOnNode (deleteCmd , cluster .ServerIPs [i ])
112122 Expect (deleteErr ).NotTo (HaveOccurred ())
0 commit comments