diff --git a/pkg/crc/preflight/preflight_checks_darwin.go b/pkg/crc/preflight/preflight_checks_darwin.go index a72e1c17b7..541528ce46 100644 --- a/pkg/crc/preflight/preflight_checks_darwin.go +++ b/pkg/crc/preflight/preflight_checks_darwin.go @@ -11,7 +11,6 @@ import ( "github.com/code-ready/crc/pkg/crc/cache" "github.com/code-ready/crc/pkg/crc/constants" - "github.com/code-ready/crc/pkg/crc/daemonclient" "github.com/code-ready/crc/pkg/crc/logging" "github.com/code-ready/crc/pkg/crc/version" crcos "github.com/code-ready/crc/pkg/os" @@ -191,13 +190,6 @@ func checkIfDaemonPlistFileExists() error { return nil } -func daemonRunning() bool { - if _, err := daemonclient.GetVersionFromDaemonAPI(); err != nil { - return false - } - return true -} - func fixDaemonPlistFileExists() error { if err := olderDaemonVersionRunning(); err != nil { if err := killDaemonProcess(); err != nil { @@ -232,5 +224,5 @@ func fixPlistFileExists(agentConfig launchd.AgentConfig) error { logging.Debugf("failed to restart launchd agent '%s': %v", agentConfig.Label, err.Error()) return err } - return nil + return waitForDaemonRunning() } diff --git a/pkg/crc/preflight/preflight_checks_nonlinux.go b/pkg/crc/preflight/preflight_checks_nonlinux.go index 8ef5487eb1..02a6fde6c0 100644 --- a/pkg/crc/preflight/preflight_checks_nonlinux.go +++ b/pkg/crc/preflight/preflight_checks_nonlinux.go @@ -4,10 +4,14 @@ package preflight import ( + "context" + "fmt" "runtime" "strings" + "time" "github.com/code-ready/crc/pkg/crc/daemonclient" + crcerrors "github.com/code-ready/crc/pkg/crc/errors" "github.com/code-ready/crc/pkg/crc/logging" "github.com/shirou/gopsutil/v3/process" ) @@ -70,3 +74,19 @@ func olderDaemonVersionRunning() error { } return daemonclient.CheckIfOlderVersion(v) } + +func daemonRunning() bool { + if _, err := daemonclient.GetVersionFromDaemonAPI(); err != nil { + return false + } + return true +} + +func waitForDaemonRunning() error { + return crcerrors.Retry(context.Background(), 15*time.Second, func() error { + if !daemonRunning() { + return &crcerrors.RetriableError{Err: fmt.Errorf("daemon is not running yet")} + } + return nil + }, 2*time.Second) +} diff --git a/pkg/crc/preflight/preflight_daemon_task_check_windows.go b/pkg/crc/preflight/preflight_daemon_task_check_windows.go index 71391a9ef6..71c0a706e0 100644 --- a/pkg/crc/preflight/preflight_daemon_task_check_windows.go +++ b/pkg/crc/preflight/preflight_daemon_task_check_windows.go @@ -156,7 +156,7 @@ func fixDaemonTaskRunning() error { logging.Debugf("unable to run the %s task: %v : %s", constants.DaemonTaskName, err, stderr) return err } - return nil + return waitForDaemonRunning() } func checkIfOlderTask() error {