Repository: code-ready/crc
Pull request #1924 (2021-02-02 13:05:44)

Add check if crc daemon is running and bind to default endpoints
If user set the network mode as vsock then `crc daemon` needs to
be running as a backgroud process or in different terminal. This
is something user might forget and direct start the crc after setup.

This patch address it for windows and linux since those platform
have some preflight check for vsock side.

```
$ crc setup
[...]
INFO Checking if vsock is correctly configured
INFO Setting up vsock support
'crc daemon' is not running, run it manually on different terminal/tab
```

fixes: #1923




openshift-ci-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/code-ready/crc/pull/1924#" title="Author self-approved">praveenkumar</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=code-ready%2Fcrc).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[OWNERS](https://github.com/code-ready/crc/blob/master/OWNERS)~~ [praveenkumar]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->
gbraad: > This patch address it for windows and linux since those platform
> have some preflight check for vsock side.

Is there an issue to implement on Darwin/macOS?
openshift-ci-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/code-ready/crc/pull/1924#pullrequestreview-587571367" title="Approved">gbraad</a>*, *<a href="https://github.com/code-ready/crc/pull/1924#" title="Author self-approved">praveenkumar</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=code-ready%2Fcrc).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[OWNERS](https://github.com/code-ready/crc/blob/master/OWNERS)~~ [gbraad,praveenkumar]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->
guillaumerose: Yes it should work on darwin with the socket you use.
gbraad: @praveenkumar would you be able to modify this PR for macOS? As suggested this should be an easy test... else, a follow issue is possible.
openshift-ci-robot: New changes are detected. LGTM label has been removed.
praveenkumar: @guillaumerose @gbraad I changed the logic a bit so can be work on all the platform and also exit as soon as user try to use `vsock` mode.
openshift-ci-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/code-ready/crc/pull/1924#pullrequestreview-589205807" title="Approved">gbraad</a>*, *<a href="https://github.com/code-ready/crc/pull/1924#" title="Author self-approved">praveenkumar</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=code-ready%2Fcrc).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[OWNERS](https://github.com/code-ready/crc/blob/master/OWNERS)~~ [gbraad,praveenkumar]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->
openshift-ci-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/code-ready/crc/pull/1924#pullrequestreview-589258190" title="Approved">cfergeau</a>*, *<a href="https://github.com/code-ready/crc/pull/1924#pullrequestreview-589205807" title="Approved">gbraad</a>*, *<a href="https://github.com/code-ready/crc/pull/1924#" title="Author self-approved">praveenkumar</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=code-ready%2Fcrc).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[OWNERS](https://github.com/code-ready/crc/blob/master/OWNERS)~~ [cfergeau,gbraad,praveenkumar]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->
openshift-ci-robot: New changes are detected. LGTM label has been removed.
openshift-ci-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/code-ready/crc/pull/1924#pullrequestreview-600587130" title="Approved">cfergeau</a>*, *<a href="https://github.com/code-ready/crc/pull/1924#pullrequestreview-589205807" title="Approved">gbraad</a>*, *<a href="https://github.com/code-ready/crc/pull/1924#" title="Author self-approved">praveenkumar</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=code-ready%2Fcrc).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[OWNERS](https://github.com/code-ready/crc/blob/master/OWNERS)~~ [cfergeau,gbraad,praveenkumar]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->
praveenkumar: /needs-rebase
praveenkumar: /need-rebase
openshift-ci-robot: New changes are detected. LGTM label has been removed.

Patch:
diff --git a/pkg/crc/cluster/cluster.go b/pkg/crc/cluster/cluster.go
index b023344f3..6ff504175 100644
--- a/pkg/crc/cluster/cluster.go
+++ b/pkg/crc/cluster/cluster.go
@@ -310,7 +310,7 @@ func WaitForRequestHeaderClientCaFile(sshRunner *ssh.Runner) error {
 }
 
 func WaitForAPIServer(ocConfig oc.Config) error {
-	logging.Debugf("Waiting for apiserver availability")
+	logging.Info("Waiting for kube-apiserver availability... [takes around 2min]")
 	waitForAPIServer := func() error {
 		stdout, stderr, err := ocConfig.WithFailFast().RunOcCommand("get", "nodes")
 		if err != nil {
diff --git a/pkg/crc/preflight/preflight_checks_nondarwin.go b/pkg/crc/preflight/preflight_checks_nondarwin.go
new file mode 100644
index 000000000..6d498088f
--- /dev/null
+++ b/pkg/crc/preflight/preflight_checks_nondarwin.go
@@ -0,0 +1,36 @@
+// +build !darwin
+
+package preflight
+
+import (
+	"errors"
+	"net"
+
+	"github.com/code-ready/crc/pkg/crc/constants"
+)
+
+const daemonNotRunningErrMsg = "Network mode 'vsock' requires 'crc daemon' to be running, run it manually on different terminal/tab"
+
+var daemonRunningChecks = Check{
+	configKeySuffix:  "check-if-daemon-running",
+	checkDescription: "Checking if crc daemon is running",
+	check:            checkIfCRCDaemonRunning,
+	fixDescription:   daemonNotRunningErrMsg,
+	flags:            NoFix,
+}
+
+func checkIfCRCDaemonRunning() error {
+	l, err := net.Dial("unix", constants.DaemonSocketPath)
+	if err != nil {
+		// Log or report the error here
+		return errors.New(daemonNotRunningErrMsg)
+	}
+
+	defer func() {
+		if l != nil {
+			l.Close()
+		}
+	}()
+
+	return nil
+}
diff --git a/pkg/crc/preflight/preflight_linux.go b/pkg/crc/preflight/preflight_linux.go
index c64cbdf22..e7e270cb7 100644
--- a/pkg/crc/preflight/preflight_linux.go
+++ b/pkg/crc/preflight/preflight_linux.go
@@ -223,7 +223,8 @@ func getNetworkChecksForDistro(distro *linux.OsRelease, networkMode network.Mode
 	var checks []Check
 
 	if networkMode == network.VSockMode {
-		return append(checks, vsockPreflightChecks)
+		checks = append(checks, vsockPreflightChecks)
+		return append(checks, daemonRunningChecks)
 	}
 
 	switch {
diff --git a/pkg/crc/preflight/preflight_windows.go b/pkg/crc/preflight/preflight_windows.go
index 9ced5a2d9..268743d6a 100644
--- a/pkg/crc/preflight/preflight_windows.go
+++ b/pkg/crc/preflight/preflight_windows.go
@@ -148,6 +148,7 @@ func getPreflightChecks(experimentalFeatures bool, _ bool, networkMode network.M
 
 	if networkMode == network.VSockMode {
 		checks = append(checks, vsockChecks[:]...)
+		checks = append(checks, daemonRunningChecks)
 	}
 
 	// Experimental feature
diff --git a/pkg/crc/version/version.go b/pkg/crc/version/version.go
index ca1a70b2a..40f0d17d3 100644
--- a/pkg/crc/version/version.go
+++ b/pkg/crc/version/version.go
@@ -29,7 +29,7 @@ var (
 const (
 	releaseInfoLink = "https://mirror.openshift.com/pub/openshift-v4/clients/crc/latest/release-info.json"
 	// Tray version to be embedded in executable
-	crcMacTrayVersion = "1.0.1"
+	crcMacTrayVersion = "1.0.2"
 	// Windows forms application version type major.minor.buildnumber.revesion
 	crcWindowsTrayVersion = "0.4.0.0"
 )


Test patch:
diff --git a/pkg/crc/preflight/preflight_linux_test.go b/pkg/crc/preflight/preflight_linux_test.go
index 6bc0b3b3c..6837fac1c 100644
--- a/pkg/crc/preflight/preflight_linux_test.go
+++ b/pkg/crc/preflight/preflight_linux_test.go
@@ -109,6 +109,7 @@ var checkListForDistros = []checkListForDistro{
 			{check: checkMachineDriverLibvirtInstalled},
 			{cleanup: removeCrcVM},
 			{check: checkVsock},
+			{check: checkIfCRCDaemonRunning},
 			{check: checkBundleExtracted},
 		},
 	},
@@ -163,6 +164,7 @@ var checkListForDistros = []checkListForDistro{
 			{check: checkMachineDriverLibvirtInstalled},
 			{cleanup: removeCrcVM},
 			{check: checkVsock},
+			{check: checkIfCRCDaemonRunning},
 			{check: checkBundleExtracted},
 		},
 	},
@@ -217,6 +219,7 @@ var checkListForDistros = []checkListForDistro{
 			{check: checkMachineDriverLibvirtInstalled},
 			{cleanup: removeCrcVM},
 			{check: checkVsock},
+			{check: checkIfCRCDaemonRunning},
 			{check: checkBundleExtracted},
 		},
 	},
@@ -274,6 +277,7 @@ var checkListForDistros = []checkListForDistro{
 			{cleanup: removeCrcVM},
 			{configKeySuffix: "check-apparmor-profile-setup"},
 			{check: checkVsock},
+			{check: checkIfCRCDaemonRunning},
 			{check: checkBundleExtracted},
 		},
 	},
diff --git a/pkg/crc/preflight/preflight_windows_test.go b/pkg/crc/preflight/preflight_windows_test.go
index 77724abe0..34afd227a 100644
--- a/pkg/crc/preflight/preflight_windows_test.go
+++ b/pkg/crc/preflight/preflight_windows_test.go
@@ -11,13 +11,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, false, network.DefaultMode), 16)
 	assert.Len(t, getPreflightChecks(true, true, network.DefaultMode), 19)
 
-	assert.Len(t, getPreflightChecks(false, false, network.VSockMode), 17)
-	assert.Len(t, getPreflightChecks(true, true, network.VSockMode), 20)
+	assert.Len(t, getPreflightChecks(false, false, network.VSockMode), 18)
+	assert.Len(t, getPreflightChecks(true, true, network.VSockMode), 21)
 }