Skip to content

Commit

Permalink
Merge pull request #21848 from baude/machinestartcleanup
Browse files Browse the repository at this point in the history
Clean up gvproxy if machine start fails
  • Loading branch information
openshift-merge-bot[bot] authored Feb 28, 2024
2 parents 2d4ef6f + dfae51a commit c93ed35
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/machine/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (c *CleanupCallback) clean() {
}
}

func InitCleanup() CleanupCallback {
func CleanUp() CleanupCallback {
return CleanupCallback{
Funcs: []func() error{},
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/machine/hyperv/stubber.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (h HyperVStubber) CreateVM(opts define.CreateVMOpts, mc *vmconfigs.MachineC
var (
err error
)
callbackFuncs := machine.InitCleanup()
callbackFuncs := machine.CleanUp()
defer callbackFuncs.CleanIfErr(&err)
go callbackFuncs.CleanOnSignal()

Expand Down Expand Up @@ -182,7 +182,7 @@ func (h HyperVStubber) StartVM(mc *vmconfigs.MachineConfig) (func() error, func(
return nil, nil, err
}

callbackFuncs := machine.InitCleanup()
callbackFuncs := machine.CleanUp()
defer callbackFuncs.CleanIfErr(&err)
go callbackFuncs.CleanOnSignal()

Expand Down Expand Up @@ -384,7 +384,7 @@ func (h HyperVStubber) PostStartNetworking(mc *vmconfigs.MachineConfig, noInfo b
err error
executable string
)
callbackFuncs := machine.InitCleanup()
callbackFuncs := machine.CleanUp()
defer callbackFuncs.CleanIfErr(&err)
go callbackFuncs.CleanOnSignal()

Expand Down
20 changes: 18 additions & 2 deletions pkg/machine/shim/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func Init(opts machineDefine.InitOptions, mp vmconfigs.VMProvider) (*vmconfigs.M
imagePath *machineDefine.VMFile
)

callbackFuncs := machine.InitCleanup()
callbackFuncs := machine.CleanUp()
defer callbackFuncs.CleanIfErr(&err)
go callbackFuncs.CleanOnSignal()

Expand Down Expand Up @@ -350,15 +350,31 @@ func Stop(mc *vmconfigs.MachineConfig, mp vmconfigs.VMProvider, dirs *machineDef
return nil
}

func Start(mc *vmconfigs.MachineConfig, mp vmconfigs.VMProvider, _ *machineDefine.MachineDirs, opts machine.StartOptions) error {
func Start(mc *vmconfigs.MachineConfig, mp vmconfigs.VMProvider, dirs *machineDefine.MachineDirs, opts machine.StartOptions) error {
defaultBackoff := 500 * time.Millisecond
maxBackoffs := 6

gvproxyPidFile, err := dirs.RuntimeDir.AppendToNewVMFile("gvproxy.pid", nil)
if err != nil {
return err
}

// start gvproxy and set up the API socket forwarding
forwardSocketPath, forwardingState, err := startNetworking(mc, mp)
if err != nil {
return err
}

callBackFuncs := machine.CleanUp()
defer callBackFuncs.CleanIfErr(&err)
go callBackFuncs.CleanOnSignal()

// Clean up gvproxy if start fails
cleanGV := func() error {
return machine.CleanupGVProxy(*gvproxyPidFile)
}
callBackFuncs.Add(cleanGV)

// if there are generic things that need to be done, a preStart function could be added here
// should it be extensive

Expand Down
2 changes: 1 addition & 1 deletion pkg/machine/wsl/stubber.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (w WSLStubber) CreateVM(opts define.CreateVMOpts, mc *vmconfigs.MachineConf
err error
)
// cleanup half-baked files if init fails at any point
callbackFuncs := machine.InitCleanup()
callbackFuncs := machine.CleanUp()
defer callbackFuncs.CleanIfErr(&err)
go callbackFuncs.CleanOnSignal()
mc.WSLHypervisor = new(vmconfigs.WSLConfig)
Expand Down

0 comments on commit c93ed35

Please sign in to comment.