From 88d29901f8f942396d4c8cca459e13c3db6c8aeb Mon Sep 17 00:00:00 2001 From: Anjan Nath Date: Mon, 13 Sep 2021 18:28:03 +0530 Subject: [PATCH] Issue #2687 Modify tray started check to verify if daemon is running the daemon might take a few seconds to come up and make the api endpoint available it is better to check that the daemon is up by trying to access this endpoint to make sure user is successfully able to do `crc start` after `crc setup` --- pkg/crc/preflight/preflight_checks_tray_darwin.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pkg/crc/preflight/preflight_checks_tray_darwin.go b/pkg/crc/preflight/preflight_checks_tray_darwin.go index 16b1071621..80e47cadcf 100644 --- a/pkg/crc/preflight/preflight_checks_tray_darwin.go +++ b/pkg/crc/preflight/preflight_checks_tray_darwin.go @@ -1,11 +1,15 @@ package preflight import ( + "context" "errors" "fmt" "path/filepath" + "time" "github.com/code-ready/crc/pkg/crc/constants" + "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/code-ready/crc/pkg/os/launchd" ) @@ -71,7 +75,7 @@ func checkIfTrayAgentRunning() error { if !launchd.AgentRunning(trayAgentLabel) { return fmt.Errorf("Tray is not running") } - return nil + return checkIfDaemonRunning() } func fixTrayAgentRunning() error { @@ -99,3 +103,12 @@ func fixPlistFileExists(agentConfig launchd.AgentConfig) error { } return nil } + +func checkIfDaemonRunning() error { + return crcerrors.Retry(context.Background(), time.Second*3, func() error { + if _, err := daemonclient.New().APIClient.Version(); err != nil { + return &crcerrors.RetriableError{Err: fmt.Errorf("Daemon is not yet running: %w", err)} + } + return nil + }, time.Second*1) +}