Merge pull request #21694 from arixmkii/wait-for-gvproxy

Extract waitForGvProxy into shared utility function
This commit is contained in:
openshift-merge-bot[bot]
2024-02-20 18:59:46 +00:00
committed by GitHub
2 changed files with 17 additions and 16 deletions

View File

@ -23,7 +23,6 @@ import (
"github.com/containers/podman/v5/utils"
vfConfig "github.com/crc-org/vfkit/pkg/config"
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
)
// 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
if err := waitForGvProxy(gvproxySocket); err != nil {
if err := sockets.WaitForSocketWithBackoffs(gvProxyMaxBackoffAttempts, gvProxyWaitBackoff, gvproxySocket.GetPath(), "gvproxy"); err != nil {
return nil, nil, err
}
@ -321,20 +320,6 @@ func (a AppleHVStubber) VMType() define.VMType {
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) {
return nil, nil
}

View File

@ -5,6 +5,7 @@ import (
"bytes"
"fmt"
"net"
"os"
"path/filepath"
"time"
@ -94,3 +95,18 @@ func DialSocketWithBackoffsAndProcCheck(
}
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)
}