mirror of
https://github.com/containers/podman.git
synced 2025-06-30 15:49:03 +08:00
Merge pull request #21694 from arixmkii/wait-for-gvproxy
Extract waitForGvProxy into shared utility function
This commit is contained in:
@ -23,7 +23,6 @@ import (
|
|||||||
"github.com/containers/podman/v5/utils"
|
"github.com/containers/podman/v5/utils"
|
||||||
vfConfig "github.com/crc-org/vfkit/pkg/config"
|
vfConfig "github.com/crc-org/vfkit/pkg/config"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"golang.org/x/sys/unix"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// applehcMACAddress is a pre-defined mac address that vfkit recognizes
|
// applehcMACAddress is a pre-defined mac address that vfkit recognizes
|
||||||
@ -160,7 +159,7 @@ func (a AppleHVStubber) StartVM(mc *vmconfigs.MachineConfig) (func() error, func
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Wait on gvproxy to be running and aware
|
// Wait on gvproxy to be running and aware
|
||||||
if err := waitForGvProxy(gvproxySocket); err != nil {
|
if err := sockets.WaitForSocketWithBackoffs(gvProxyMaxBackoffAttempts, gvProxyWaitBackoff, gvproxySocket.GetPath(), "gvproxy"); err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -321,20 +320,6 @@ func (a AppleHVStubber) VMType() define.VMType {
|
|||||||
return define.AppleHvVirt
|
return define.AppleHvVirt
|
||||||
}
|
}
|
||||||
|
|
||||||
func waitForGvProxy(gvproxySocket *define.VMFile) error {
|
|
||||||
backoffWait := gvProxyWaitBackoff
|
|
||||||
logrus.Debug("checking that gvproxy is running")
|
|
||||||
for i := 0; i < gvProxyMaxBackoffAttempts; i++ {
|
|
||||||
err := unix.Access(gvproxySocket.GetPath(), unix.W_OK)
|
|
||||||
if err == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
time.Sleep(backoffWait)
|
|
||||||
backoffWait *= 2
|
|
||||||
}
|
|
||||||
return fmt.Errorf("unable to connect to gvproxy %q", gvproxySocket.GetPath())
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a AppleHVStubber) PrepareIgnition(_ *vmconfigs.MachineConfig, _ *ignition.IgnitionBuilder) (*ignition.ReadyUnitOpts, error) {
|
func (a AppleHVStubber) PrepareIgnition(_ *vmconfigs.MachineConfig, _ *ignition.IgnitionBuilder) (*ignition.ReadyUnitOpts, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -94,3 +95,18 @@ func DialSocketWithBackoffsAndProcCheck(
|
|||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WaitForSocketWithBackoffs attempts to discover listening socket in maxBackoffs attempts
|
||||||
|
func WaitForSocketWithBackoffs(maxBackoffs int, backoff time.Duration, socketPath string, name string) error {
|
||||||
|
backoffWait := backoff
|
||||||
|
logrus.Debugf("checking that %q socket is ready", name)
|
||||||
|
for i := 0; i < maxBackoffs; i++ {
|
||||||
|
_, err := os.Stat(socketPath)
|
||||||
|
if err == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
time.Sleep(backoffWait)
|
||||||
|
backoffWait *= 2
|
||||||
|
}
|
||||||
|
return fmt.Errorf("unable to connect to %q socket at %q", name, socketPath)
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user