Skip to content

Commit

Permalink
Merge pull request #21694 from arixmkii/wait-for-gvproxy
Browse files Browse the repository at this point in the history
Extract waitForGvProxy into shared utility function
  • Loading branch information
openshift-merge-bot[bot] authored Feb 20, 2024
2 parents 39387c2 + 49400ec commit d9c706e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
17 changes: 1 addition & 16 deletions pkg/machine/applehv/stubber.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
Expand Down
16 changes: 16 additions & 0 deletions pkg/machine/sockets/sockets.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"bytes"
"fmt"
"net"
"os"
"path/filepath"
"time"

Expand Down Expand Up @@ -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)
}

0 comments on commit d9c706e

Please sign in to comment.