Skip to content

Commit

Permalink
Issue #2687 Modify tray started check to verify if daemon is running
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
anjannath committed Sep 13, 2021
1 parent 697746d commit 88d2990
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pkg/crc/preflight/preflight_checks_tray_darwin.go
Original file line number Diff line number Diff line change
@@ -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"
)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}

0 comments on commit 88d2990

Please sign in to comment.