Skip to content

Commit 497e779

Browse files
jlebonopenshift-merge-robot
authored andcommitted
kola/spawn: add --reconnect switch
Right now, `kola spawn` immediately kills the node once we leave the SSH session. This is nice most of the time for quick testing. But it basically throws out the window anything that requires rebooting (which oddly makes it more limiting than `cosa run`, which does). And sure, there's always libvirt for more persistence, but I think there's room for another gradation level here. Add a new `--reconnect` switch which can handle this. In this mode, we constantly try to reconnect to the node after getting disconnected. One can simply do Ctrl-C to kill the node.
1 parent fad3299 commit 497e779

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

mantle/cmd/kola/spawn.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ import (
2323
"os/user"
2424
"path/filepath"
2525
"strings"
26+
"time"
2627

28+
"github.com/pkg/errors"
2729
"github.com/spf13/cobra"
2830
"golang.org/x/crypto/ssh"
2931
"golang.org/x/crypto/ssh/agent"
@@ -47,6 +49,7 @@ var (
4749
spawnUserData string
4850
spawnDetach bool
4951
spawnShell bool
52+
spawnReconnect bool
5053
spawnIdle bool
5154
spawnRemove bool
5255
spawnVerbose bool
@@ -61,6 +64,7 @@ func init() {
6164
cmdSpawn.Flags().StringVarP(&spawnUserData, "userdata", "u", "", "file containing userdata to pass to the instances")
6265
cmdSpawn.Flags().BoolVarP(&spawnDetach, "detach", "t", false, "-kv --shell=false --remove=false")
6366
cmdSpawn.Flags().BoolVarP(&spawnShell, "shell", "s", true, "spawn a shell in an instance before exiting")
67+
cmdSpawn.Flags().BoolVarP(&spawnReconnect, "reconnect", "", false, "keep trying to reconnect to machine when disconnected")
6468
cmdSpawn.Flags().BoolVarP(&spawnIdle, "idle", "", false, "idle after starting machines (implies --shell=false)")
6569
cmdSpawn.Flags().BoolVarP(&spawnRemove, "remove", "r", true, "remove instances after shell exits")
6670
cmdSpawn.Flags().BoolVarP(&spawnVerbose, "verbose", "v", false, "output information about spawned instances")
@@ -206,8 +210,24 @@ func runSpawn(cmd *cobra.Command, args []string) error {
206210
return fmt.Errorf("Setting shell prompt failed: %v", err)
207211
}
208212
}
209-
if err := platform.Manhole(someMach); err != nil {
210-
return fmt.Errorf("Manhole failed: %v", err)
213+
for {
214+
var bootId string
215+
if spawnReconnect {
216+
if bootId, err = platform.GetMachineBootId(someMach); err != nil {
217+
return errors.Wrapf(err, "failed getting boot id")
218+
}
219+
}
220+
err = platform.Manhole(someMach)
221+
if !spawnReconnect {
222+
return errors.Wrapf(err, "Manhole failed")
223+
}
224+
if _, ok := errors.Cause(err).(*ssh.ExitMissingError); ok {
225+
fmt.Printf("Reconnecting (press Ctrl-C to abort)... ")
226+
if err = someMach.WaitForReboot(120*time.Second, bootId); err != nil {
227+
return errors.Wrapf(err, "failed to reboot")
228+
}
229+
fmt.Println()
230+
}
211231
}
212232
} else if spawnIdle {
213233
select {}

0 commit comments

Comments
 (0)