Skip to content

Commit

Permalink
Mac/Windows: Check if daemon able to serve after it starts
Browse files Browse the repository at this point in the history
This PR add time limit (15 sec) to make sure daemon able to serve
the requests after it is start because sometimes just after start
it takes time to serve.

fixes: crc-org#3148
  • Loading branch information
praveenkumar committed Apr 26, 2022
1 parent e5c608f commit 49e748e
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 deletions.
13 changes: 13 additions & 0 deletions pkg/crc/preflight/preflight_checks_nonlinux.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
package preflight

import (
"context"
"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"
)
Expand Down Expand Up @@ -70,3 +73,13 @@ func olderDaemonVersionRunning() error {
}
return daemonclient.CheckIfOlderVersion(v)
}

func checkIfDaemonIsServing() error {
return crcerrors.Retry(context.Background(), 15*time.Second, func() error {
_, err := daemonclient.GetVersionFromDaemonAPI()
if err != nil {
return &crcerrors.RetriableError{Err: err}
}
return err
}, 2*time.Second)
}
7 changes: 7 additions & 0 deletions pkg/crc/preflight/preflight_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ var daemonLaunchdChecks = []Check{
cleanupDescription: "Unloading and removing the daemon plist file",
cleanup: removeDaemonPlistFile,
},
{
configKeySuffix: "check-daemon-is-serving",
checkDescription: "Checking if crc daemon is serving the requests",
check: checkIfDaemonIsServing,
fixDescription: "crc daemon is not serving to the requests",
flags: NoFix,
},
}

// We want all preflight checks including
Expand Down
10 changes: 5 additions & 5 deletions pkg/crc/preflight/preflight_darwin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import (
func TestCountConfigurationOptions(t *testing.T) {
cfg := config.New(config.NewEmptyInMemoryStorage())
RegisterSettings(cfg)
assert.Len(t, cfg.AllConfigs(), 14)
assert.Len(t, cfg.AllConfigs(), 15)
}

func TestCountPreflights(t *testing.T) {
assert.Len(t, getPreflightChecks(true, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift), 19)
assert.Len(t, getPreflightChecks(true, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift), 19)
assert.Len(t, getPreflightChecks(true, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift), 20)
assert.Len(t, getPreflightChecks(true, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift), 20)

assert.Len(t, getPreflightChecks(true, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift), 18)
assert.Len(t, getPreflightChecks(true, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift), 18)
assert.Len(t, getPreflightChecks(true, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift), 19)
assert.Len(t, getPreflightChecks(true, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift), 19)
}
8 changes: 7 additions & 1 deletion pkg/crc/preflight/preflight_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ var daemonTaskChecks = []Check{

labels: labels{Os: Windows},
},
{
configKeySuffix: "check-daemon-is-serving",
checkDescription: "Checking if crc daemon is serving the requests",
check: checkIfDaemonIsServing,
fixDescription: "crc daemon is not serving to the requests",
flags: NoFix,
},
}

var adminHelperServiceCheks = []Check{
Expand All @@ -142,7 +149,6 @@ var adminHelperServiceCheks = []Check{
check: checkIfAdminHelperServiceRunning,
fixDescription: "Make sure you installed the crc using installer",
flags: NoFix,

labels: labels{Os: Windows},
},
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/crc/preflight/preflight_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import (
func TestCountConfigurationOptions(t *testing.T) {
cfg := config.New(config.NewEmptyInMemoryStorage())
RegisterSettings(cfg)
assert.Len(t, cfg.AllConfigs(), 12)
assert.Len(t, cfg.AllConfigs(), 13)
}

func TestCountPreflights(t *testing.T) {
assert.Len(t, getPreflightChecks(false, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift), 18)
assert.Len(t, getPreflightChecks(true, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift), 18)
assert.Len(t, getPreflightChecks(false, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift), 19)
assert.Len(t, getPreflightChecks(true, network.SystemNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift), 19)

assert.Len(t, getPreflightChecks(false, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift), 17)
assert.Len(t, getPreflightChecks(true, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift), 17)
assert.Len(t, getPreflightChecks(false, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift), 18)
assert.Len(t, getPreflightChecks(true, network.UserNetworkingMode, constants.GetDefaultBundlePath(preset.OpenShift), preset.OpenShift), 18)
}

0 comments on commit 49e748e

Please sign in to comment.