Repository: code-ready/crc
Pull request #2189 (2021-04-06 08:59:43)

Ignore clean host file error in case admin helper binary is not present
If a user downlond the crc and execute `crc cleanup` as first command
it will fail with following error because there is no admin-helper
binary present.
```
fork/exec Users/crcqe/.crc/bin/admin-helper-darwin: no such file or directory
fork/exec /Users/crcqe/.crc/bin/admin-helper-darwin: no such file or directory
```

This patch validate the error and if it is because of file not present
the ignore that host file cleanup.

fixes: #2188


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

This pull-request has been approved by: *<a href="https://github.com/code-ready/crc/pull/2189#" 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":[]} -->
openshift-ci[bot]: @praveenkumar: The following test **failed**, say `/retest` to rerun all failed tests:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
ci/prow/e2e-crc | 305cc3af2cb3bf01e6f0e9f7aa3fbe32d6b8e710 | [link](https://prow.ci.openshift.org/view/gs/origin-ci-test/pr-logs/pull/code-ready_crc/2189/pull-ci-code-ready-crc-master-e2e-crc/1379362666069364736) | `/test e2e-crc`

[Full PR test history](https://prow.ci.openshift.org/pr-history?org=code-ready&repo=crc&pr=2189). [Your PR dashboard](https://prow.ci.openshift.org/pr?query=is:pr+state:open+author:praveenkumar).

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->

Patch:
diff --git a/packaging/darwin/Distribution.in b/packaging/darwin/Distribution.in
index 26861de12..2b458c3cf 100755
--- a/packaging/darwin/Distribution.in
+++ b/packaging/darwin/Distribution.in
@@ -10,6 +10,14 @@
     <installation-check script="installCheck();"/>
     <script>
 function installCheck() {
+	var apps = system.applications.fromIdentifier('com.redhat.codeready.containers');
+	if(apps) {
+        my.result.title = 'Update failed';
+        my.result.message = 'CodeReady Containers is running. Please stop the application before updating.';
+        my.result.type = 'Fatal';
+        return false;
+	}
+
     if(!(system.compareVersions(system.version.ProductVersion, '10.14.0') >= 0)) {
         my.result.title = 'Unable to install';
         my.result.message = 'CodeReady Containers requires macOS 10.14 or later.';
diff --git a/pkg/crc/preflight/preflight_checks_nonwin.go b/pkg/crc/preflight/preflight_checks_nonwin.go
index 95773446f..77098d85c 100644
--- a/pkg/crc/preflight/preflight_checks_nonwin.go
+++ b/pkg/crc/preflight/preflight_checks_nonwin.go
@@ -23,7 +23,7 @@ var nonWinPreflightChecks = [...]Check{
 	},
 	{
 		cleanupDescription: "Removing hosts file records added by CRC",
-		cleanup:            adminhelper.CleanHostsFile,
+		cleanup:            removeHostsFileEntry,
 		flags:              CleanUpOnly,
 	},
 }
@@ -67,3 +67,11 @@ func checkSuid(path string) error {
 
 	return nil
 }
+
+func removeHostsFileEntry() error {
+	err := adminhelper.CleanHostsFile()
+	if errors.Is(err, os.ErrNotExist) {
+		return nil
+	}
+	return err
+}
diff --git a/pkg/crc/version/version.go b/pkg/crc/version/version.go
index 22c849fd8..a7ef2ef33 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.5"
+	crcMacTrayVersion = "1.0.6"
 	// 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 f8f7d0dd3..8e15b6644 100644
--- a/pkg/crc/preflight/preflight_linux_test.go
+++ b/pkg/crc/preflight/preflight_linux_test.go
@@ -5,7 +5,6 @@ import (
 	"runtime"
 	"testing"
 
-	"github.com/code-ready/crc/pkg/crc/adminhelper"
 	"github.com/code-ready/crc/pkg/crc/cluster"
 	"github.com/code-ready/crc/pkg/crc/config"
 	"github.com/code-ready/crc/pkg/crc/network"
@@ -64,7 +63,7 @@ var checkListForDistros = []checkListForDistro{
 		systemdResolved: true,
 		checks: []Check{
 			{check: checkIfRunningAsNormalUser},
-			{cleanup: adminhelper.CleanHostsFile},
+			{cleanup: removeHostsFileEntry},
 			{check: checkPodmanExecutableCached},
 			{check: checkAdminHelperExecutableCached},
 			{configKeySuffix: "check-ram"},
@@ -97,7 +96,7 @@ var checkListForDistros = []checkListForDistro{
 		systemdResolved: false,
 		checks: []Check{
 			{check: checkIfRunningAsNormalUser},
-			{cleanup: adminhelper.CleanHostsFile},
+			{cleanup: removeHostsFileEntry},
 			{check: checkPodmanExecutableCached},
 			{check: checkAdminHelperExecutableCached},
 			{configKeySuffix: "check-ram"},
@@ -129,7 +128,7 @@ var checkListForDistros = []checkListForDistro{
 		systemdResolved: false,
 		checks: []Check{
 			{check: checkIfRunningAsNormalUser},
-			{cleanup: adminhelper.CleanHostsFile},
+			{cleanup: removeHostsFileEntry},
 			{check: checkPodmanExecutableCached},
 			{check: checkAdminHelperExecutableCached},
 			{configKeySuffix: "check-ram"},
@@ -156,7 +155,7 @@ var checkListForDistros = []checkListForDistro{
 		systemdResolved: true,
 		checks: []Check{
 			{check: checkIfRunningAsNormalUser},
-			{cleanup: adminhelper.CleanHostsFile},
+			{cleanup: removeHostsFileEntry},
 			{check: checkPodmanExecutableCached},
 			{check: checkAdminHelperExecutableCached},
 			{configKeySuffix: "check-ram"},
@@ -189,7 +188,7 @@ var checkListForDistros = []checkListForDistro{
 		systemdResolved: false,
 		checks: []Check{
 			{check: checkIfRunningAsNormalUser},
-			{cleanup: adminhelper.CleanHostsFile},
+			{cleanup: removeHostsFileEntry},
 			{check: checkPodmanExecutableCached},
 			{check: checkAdminHelperExecutableCached},
 			{configKeySuffix: "check-ram"},
@@ -221,7 +220,7 @@ var checkListForDistros = []checkListForDistro{
 		systemdResolved: false,
 		checks: []Check{
 			{check: checkIfRunningAsNormalUser},
-			{cleanup: adminhelper.CleanHostsFile},
+			{cleanup: removeHostsFileEntry},
 			{check: checkPodmanExecutableCached},
 			{check: checkAdminHelperExecutableCached},
 			{configKeySuffix: "check-ram"},
@@ -248,7 +247,7 @@ var checkListForDistros = []checkListForDistro{
 		systemdResolved: true,
 		checks: []Check{
 			{check: checkIfRunningAsNormalUser},
-			{cleanup: adminhelper.CleanHostsFile},
+			{cleanup: removeHostsFileEntry},
 			{check: checkPodmanExecutableCached},
 			{check: checkAdminHelperExecutableCached},
 			{configKeySuffix: "check-ram"},
@@ -281,7 +280,7 @@ var checkListForDistros = []checkListForDistro{
 		systemdResolved: false,
 		checks: []Check{
 			{check: checkIfRunningAsNormalUser},
-			{cleanup: adminhelper.CleanHostsFile},
+			{cleanup: removeHostsFileEntry},
 			{check: checkPodmanExecutableCached},
 			{check: checkAdminHelperExecutableCached},
 			{configKeySuffix: "check-ram"},
@@ -313,7 +312,7 @@ var checkListForDistros = []checkListForDistro{
 		systemdResolved: false,
 		checks: []Check{
 			{check: checkIfRunningAsNormalUser},
-			{cleanup: adminhelper.CleanHostsFile},
+			{cleanup: removeHostsFileEntry},
 			{check: checkPodmanExecutableCached},
 			{check: checkAdminHelperExecutableCached},
 			{configKeySuffix: "check-ram"},
@@ -340,7 +339,7 @@ var checkListForDistros = []checkListForDistro{
 		systemdResolved: true,
 		checks: []Check{
 			{check: checkIfRunningAsNormalUser},
-			{cleanup: adminhelper.CleanHostsFile},
+			{cleanup: removeHostsFileEntry},
 			{check: checkPodmanExecutableCached},
 			{check: checkAdminHelperExecutableCached},
 			{configKeySuffix: "check-ram"},
@@ -374,7 +373,7 @@ var checkListForDistros = []checkListForDistro{
 		systemdResolved: false,
 		checks: []Check{
 			{check: checkIfRunningAsNormalUser},
-			{cleanup: adminhelper.CleanHostsFile},
+			{cleanup: removeHostsFileEntry},
 			{check: checkPodmanExecutableCached},
 			{check: checkAdminHelperExecutableCached},
 			{configKeySuffix: "check-ram"},
@@ -407,7 +406,7 @@ var checkListForDistros = []checkListForDistro{
 		systemdResolved: false,
 		checks: []Check{
 			{check: checkIfRunningAsNormalUser},
-			{cleanup: adminhelper.CleanHostsFile},
+			{cleanup: removeHostsFileEntry},
 			{check: checkPodmanExecutableCached},
 			{check: checkAdminHelperExecutableCached},
 			{configKeySuffix: "check-ram"},