Repository: code-ready/crc
Pull request #1835 (2021-01-13 14:02:35)

Update admin-helper: it is not compressed twice anymore
Also move the root check first.

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

This pull-request has been approved by: *<a href="https://github.com/code-ready/crc/pull/1835#" title="Author self-approved">guillaumerose</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)~~ [guillaumerose]

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: Can you elaborate on https://github.com/code-ready/crc/pull/1835/commits/54dd7ce4aca4236d58f936855a2f53dd9c55a83a one, like what is current scenario and after this patch what it would be?
guillaumerose: I added more details. Basically, if I'm root, podman-remote, etc binaries will be created in /root/.crc/bin and then crc will refuse to continue with the root check.
praveenkumar: > I added more details. Basically, if I'm root, podman-remote, etc binaries will be created in /root/.crc/bin and then crc will refuse to continue with the root check.

This is much better than you put in the commit log :) 
praveenkumar: /lgtm

Patch:
diff --git a/pkg/crc/adminhelper/hosts.go b/pkg/crc/adminhelper/hosts.go
index e0cda1d7c..e6845a5ac 100644
--- a/pkg/crc/adminhelper/hosts.go
+++ b/pkg/crc/adminhelper/hosts.go
@@ -12,7 +12,7 @@ var (
 
 // UpdateHostsFile updates the host's /etc/hosts file with Instance IP.
 func UpdateHostsFile(instanceIP string, hostnames ...string) error {
-	if err := RemoveFromHostsFile(instanceIP, hostnames...); err != nil {
+	if err := RemoveFromHostsFile(hostnames...); err != nil {
 		return err
 	}
 	if err := AddToHostsFile(instanceIP, hostnames...); err != nil {
@@ -25,11 +25,7 @@ func AddToHostsFile(instanceIP string, hostnames ...string) error {
 	return execute(append([]string{"add", instanceIP}, hostnames...)...)
 }
 
-func RemoveFromHostsFile(instanceIP string, hostnames ...string) error {
-	// If only instanceIP provided then remove all the entry from that instance IP
-	if len(hostnames) == 0 {
-		return execute("rm", instanceIP)
-	}
+func RemoveFromHostsFile(hostnames ...string) error {
 	return execute(append([]string{"rm"}, hostnames...)...)
 }
 
diff --git a/pkg/crc/constants/constants.go b/pkg/crc/constants/constants.go
index dd51d0ac6..e4d51771c 100644
--- a/pkg/crc/constants/constants.go
+++ b/pkg/crc/constants/constants.go
@@ -29,7 +29,7 @@ const (
 	DaemonLogFile             = "crcd.log"
 	CrcLandingPageURL         = "https://cloud.redhat.com/openshift/install/crc/installer-provisioned" // #nosec G101
 	DefaultPodmanURLBase      = "https://storage.googleapis.com/libpod-master-releases"
-	DefaultAdminHelperCliBase = "https://github.com/code-ready/admin-helper/releases/download/0.0.1"
+	DefaultAdminHelperCliBase = "https://github.com/code-ready/admin-helper/releases/download/0.0.2"
 	CRCMacTrayDownloadURL     = "https://github.com/code-ready/tray-macos/releases/download/v%s/crc-tray-macos.tar.gz"
 	CRCWindowsTrayDownloadURL = "https://github.com/code-ready/tray-windows/releases/download/v%s/crc-tray-windows.zip"
 	DefaultContext            = "admin"
@@ -58,9 +58,9 @@ func GetPodmanURL() string {
 }
 
 var adminHelperURLForOs = map[string]string{
-	"darwin":  fmt.Sprintf("%s/%s", DefaultAdminHelperCliBase, "admin-helper-macos-amd64.tar.xz"),
-	"linux":   fmt.Sprintf("%s/%s", DefaultAdminHelperCliBase, "admin-helper-linux-amd64.tar.xz"),
-	"windows": fmt.Sprintf("%s/%s", DefaultAdminHelperCliBase, "admin-helper-windows-amd64.tar.xz"),
+	"darwin":  fmt.Sprintf("%s/%s", DefaultAdminHelperCliBase, "admin-helper-darwin"),
+	"linux":   fmt.Sprintf("%s/%s", DefaultAdminHelperCliBase, "admin-helper-linux"),
+	"windows": fmt.Sprintf("%s/%s", DefaultAdminHelperCliBase, "admin-helper-windows.exe"),
 }
 
 func GetAdminHelperURLForOs(os string) string {
diff --git a/pkg/crc/constants/constants_darwin.go b/pkg/crc/constants/constants_darwin.go
index 54af654e6..c018bb767 100644
--- a/pkg/crc/constants/constants_darwin.go
+++ b/pkg/crc/constants/constants_darwin.go
@@ -6,7 +6,7 @@ const (
 	OcExecutableName          = "oc"
 	PodmanExecutableName      = "podman"
 	TrayExecutableName        = "CodeReady Containers.app"
-	AdminHelperExecutableName = "admin-helper"
+	AdminHelperExecutableName = "admin-helper-darwin"
 )
 
 var (
diff --git a/pkg/crc/constants/constants_linux.go b/pkg/crc/constants/constants_linux.go
index 4c701d651..6d05ab7fb 100644
--- a/pkg/crc/constants/constants_linux.go
+++ b/pkg/crc/constants/constants_linux.go
@@ -3,5 +3,5 @@ package constants
 const (
 	OcExecutableName          = "oc"
 	PodmanExecutableName      = "podman"
-	AdminHelperExecutableName = "admin-helper"
+	AdminHelperExecutableName = "admin-helper-linux"
 )
diff --git a/pkg/crc/constants/constants_windows.go b/pkg/crc/constants/constants_windows.go
index f773f6df0..e87fe9030 100644
--- a/pkg/crc/constants/constants_windows.go
+++ b/pkg/crc/constants/constants_windows.go
@@ -5,7 +5,7 @@ import "path/filepath"
 const (
 	OcExecutableName          = "oc.exe"
 	PodmanExecutableName      = "podman.exe"
-	AdminHelperExecutableName = "admin-helper.exe"
+	AdminHelperExecutableName = "admin-helper-windows.exe"
 	TrayExecutableName        = "tray-windows.exe"
 	DaemonServiceName         = "CodeReady Containers"
 	TrayShortcutName          = "tray-windows.lnk"
diff --git a/pkg/crc/preflight/preflight_darwin.go b/pkg/crc/preflight/preflight_darwin.go
index 0367f522f..cb551ce6c 100644
--- a/pkg/crc/preflight/preflight_darwin.go
+++ b/pkg/crc/preflight/preflight_darwin.go
@@ -113,8 +113,8 @@ func getAllPreflightChecks() []Check {
 func getPreflightChecks(experimentalFeatures bool, mode network.Mode) []Check {
 	checks := []Check{}
 
-	checks = append(checks, genericPreflightChecks[:]...)
 	checks = append(checks, nonWinPreflightChecks[:]...)
+	checks = append(checks, genericPreflightChecks[:]...)
 	checks = append(checks, hyperkitPreflightChecks(mode)...)
 	checks = append(checks, dnsPreflightChecks[:]...)
 
diff --git a/pkg/crc/preflight/preflight_linux.go b/pkg/crc/preflight/preflight_linux.go
index e2587c8c1..d7f817574 100644
--- a/pkg/crc/preflight/preflight_linux.go
+++ b/pkg/crc/preflight/preflight_linux.go
@@ -222,8 +222,8 @@ func getNetworkChecksForDistro(distro *linux.OsRelease, networkMode network.Mode
 
 func getPreflightChecksForDistro(distro *linux.OsRelease, networkMode network.Mode) []Check {
 	var checks []Check
-	checks = append(checks, genericPreflightChecks[:]...)
 	checks = append(checks, nonWinPreflightChecks[:]...)
+	checks = append(checks, genericPreflightChecks[:]...)
 	checks = append(checks, libvirtPreflightChecks(distro)...)
 	networkChecks := getNetworkChecksForDistro(distro, networkMode)
 	checks = append(checks, networkChecks...)


Test patch:
diff --git a/pkg/crc/preflight/preflight_linux_test.go b/pkg/crc/preflight/preflight_linux_test.go
index 393afeee0..4e76233b8 100644
--- a/pkg/crc/preflight/preflight_linux_test.go
+++ b/pkg/crc/preflight/preflight_linux_test.go
@@ -61,14 +61,14 @@ var checkListForDistros = []checkListForDistro{
 		distro:      &fedora,
 		networkMode: network.DefaultMode,
 		checks: []Check{
+			{check: checkIfRunningAsNormalUser},
+			{cleanup: adminhelper.CleanHostsFile},
 			{check: checkPodmanExecutableCached},
 			{check: checkAdminHelperExecutableCached},
 			{check: checkBundleExtracted},
 			{configKeySuffix: "check-ram"},
 			{cleanup: removeCRCMachinesDir},
 			{cleanup: removeOldLogs},
-			{check: checkIfRunningAsNormalUser},
-			{cleanup: adminhelper.CleanHostsFile},
 			{check: checkVirtualizationEnabled},
 			{check: checkKvmEnabled},
 			{check: checkLibvirtInstalled},
@@ -91,14 +91,14 @@ var checkListForDistros = []checkListForDistro{
 		distro:      &fedora,
 		networkMode: network.VSockMode,
 		checks: []Check{
+			{check: checkIfRunningAsNormalUser},
+			{cleanup: adminhelper.CleanHostsFile},
 			{check: checkPodmanExecutableCached},
 			{check: checkAdminHelperExecutableCached},
 			{check: checkBundleExtracted},
 			{configKeySuffix: "check-ram"},
 			{cleanup: removeCRCMachinesDir},
 			{cleanup: removeOldLogs},
-			{check: checkIfRunningAsNormalUser},
-			{cleanup: adminhelper.CleanHostsFile},
 			{check: checkVirtualizationEnabled},
 			{check: checkKvmEnabled},
 			{check: checkLibvirtInstalled},
@@ -114,14 +114,14 @@ var checkListForDistros = []checkListForDistro{
 		distro:      &rhel,
 		networkMode: network.DefaultMode,
 		checks: []Check{
+			{check: checkIfRunningAsNormalUser},
+			{cleanup: adminhelper.CleanHostsFile},
 			{check: checkPodmanExecutableCached},
 			{check: checkAdminHelperExecutableCached},
 			{check: checkBundleExtracted},
 			{configKeySuffix: "check-ram"},
 			{cleanup: removeCRCMachinesDir},
 			{cleanup: removeOldLogs},
-			{check: checkIfRunningAsNormalUser},
-			{cleanup: adminhelper.CleanHostsFile},
 			{check: checkVirtualizationEnabled},
 			{check: checkKvmEnabled},
 			{check: checkLibvirtInstalled},
@@ -143,14 +143,14 @@ var checkListForDistros = []checkListForDistro{
 		distro:      &rhel,
 		networkMode: network.VSockMode,
 		checks: []Check{
+			{check: checkIfRunningAsNormalUser},
+			{cleanup: adminhelper.CleanHostsFile},
 			{check: checkPodmanExecutableCached},
 			{check: checkAdminHelperExecutableCached},
 			{check: checkBundleExtracted},
 			{configKeySuffix: "check-ram"},
 			{cleanup: removeCRCMachinesDir},
 			{cleanup: removeOldLogs},
-			{check: checkIfRunningAsNormalUser},
-			{cleanup: adminhelper.CleanHostsFile},
 			{check: checkVirtualizationEnabled},
 			{check: checkKvmEnabled},
 			{check: checkLibvirtInstalled},
@@ -166,14 +166,14 @@ var checkListForDistros = []checkListForDistro{
 		distro:      &unexpected,
 		networkMode: network.DefaultMode,
 		checks: []Check{
+			{check: checkIfRunningAsNormalUser},
+			{cleanup: adminhelper.CleanHostsFile},
 			{check: checkPodmanExecutableCached},
 			{check: checkAdminHelperExecutableCached},
 			{check: checkBundleExtracted},
 			{configKeySuffix: "check-ram"},
 			{cleanup: removeCRCMachinesDir},
 			{cleanup: removeOldLogs},
-			{check: checkIfRunningAsNormalUser},
-			{cleanup: adminhelper.CleanHostsFile},
 			{check: checkVirtualizationEnabled},
 			{check: checkKvmEnabled},
 			{check: checkLibvirtInstalled},
@@ -195,14 +195,14 @@ var checkListForDistros = []checkListForDistro{
 		distro:      &unexpected,
 		networkMode: network.VSockMode,
 		checks: []Check{
+			{check: checkIfRunningAsNormalUser},
+			{cleanup: adminhelper.CleanHostsFile},
 			{check: checkPodmanExecutableCached},
 			{check: checkAdminHelperExecutableCached},
 			{check: checkBundleExtracted},
 			{configKeySuffix: "check-ram"},
 			{cleanup: removeCRCMachinesDir},
 			{cleanup: removeOldLogs},
-			{check: checkIfRunningAsNormalUser},
-			{cleanup: adminhelper.CleanHostsFile},
 			{check: checkVirtualizationEnabled},
 			{check: checkKvmEnabled},
 			{check: checkLibvirtInstalled},
@@ -218,14 +218,14 @@ var checkListForDistros = []checkListForDistro{
 		distro:      &ubuntu,
 		networkMode: network.DefaultMode,
 		checks: []Check{
+			{check: checkIfRunningAsNormalUser},
+			{cleanup: adminhelper.CleanHostsFile},
 			{check: checkPodmanExecutableCached},
 			{check: checkAdminHelperExecutableCached},
 			{check: checkBundleExtracted},
 			{configKeySuffix: "check-ram"},
 			{cleanup: removeCRCMachinesDir},
 			{cleanup: removeOldLogs},
-			{check: checkIfRunningAsNormalUser},
-			{cleanup: adminhelper.CleanHostsFile},
 			{check: checkVirtualizationEnabled},
 			{check: checkKvmEnabled},
 			{check: checkLibvirtInstalled},
@@ -249,14 +249,14 @@ var checkListForDistros = []checkListForDistro{
 		distro:      &ubuntu,
 		networkMode: network.VSockMode,
 		checks: []Check{
+			{check: checkIfRunningAsNormalUser},
+			{cleanup: adminhelper.CleanHostsFile},
 			{check: checkPodmanExecutableCached},
 			{check: checkAdminHelperExecutableCached},
 			{check: checkBundleExtracted},
 			{configKeySuffix: "check-ram"},
 			{cleanup: removeCRCMachinesDir},
 			{cleanup: removeOldLogs},
-			{check: checkIfRunningAsNormalUser},
-			{cleanup: adminhelper.CleanHostsFile},
 			{check: checkVirtualizationEnabled},
 			{check: checkKvmEnabled},
 			{check: checkLibvirtInstalled},