Repository: code-ready/crc
Pull request #2281 (2021-04-28 06:39:14)

Issue #2276 Check if interface is nil before trying to convert it
This fixes the panic during interface conversion when the daemon is provided unexpected data
like: `echo '{"command":"setconfig", "args":{}}' | nc -U ~/.crc/crc.sock`

which results in the following panic:
```
DEBU rpc:0xc000114048: Received request: {"command":"setconfig", "args":{}}
panic: interface conversion: interface {} is nil, not map[string]interface {}

goroutine 88 [running]:
github.com/code-ready/crc/pkg/crc/api.(*Handler).SetConfig(0xc0005a80c0, 0xc00011a118, 0x2, 0x8, 0x0, 0x0)
	/home/anjan/github.com/code-ready/crc/pkg/crc/api/handlers.go:146 +0x717
github.com/code-ready/crc/pkg/crc/api.Server.handleRequest(0xc0005a80c0, 0x155bb60, 0xc0005a2240, 0xc00011a130, 0x9, 0xc00011a118, 0x2, 0x8, 0x156c1e0, 0xc000114048)
	/home/anjan/github.com/code-ready/crc/pkg/crc/api/api.go:61 +0x425
created by github.com/code-ready/crc/pkg/crc/api.Server.handleConnections
	/home/anjan/github.com/code-ready/crc/pkg/crc/api/api.go:92 +0x3c7

```

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

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

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":[]} -->

Patch:
diff --git a/Makefile b/Makefile
index 526458a8c..2dbd5a4eb 100644
--- a/Makefile
+++ b/Makefile
@@ -190,7 +190,7 @@ fmt:
 	@gofmt -l -w $(SOURCE_DIRS)
 
 $(GOPATH)/bin/golangci-lint:
-	pushd /tmp && GO111MODULE=on go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.37.1 && popd
+	pushd /tmp && GO111MODULE=on go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.39.0 && popd
 
 # Run golangci-lint against code
 .PHONY: lint cross-lint
diff --git a/pkg/crc/api/handlers.go b/pkg/crc/api/handlers.go
index 2f7a50870..d0c2202ed 100644
--- a/pkg/crc/api/handlers.go
+++ b/pkg/crc/api/handlers.go
@@ -143,7 +143,11 @@ func (h *Handler) SetConfig(args json.RawMessage) string {
 		return encodeStructToJSON(setConfigResult)
 	}
 
-	configs := a["properties"].(map[string]interface{})
+	configs, ok := a["properties"].(map[string]interface{})
+	if !ok {
+		setConfigResult.Error = "No config keys provided"
+		return encodeStructToJSON(setConfigResult)
+	}
 
 	// successProps slice contains the properties that were successfully set
 	var successProps []string
diff --git a/pkg/crc/cache/cache.go b/pkg/crc/cache/cache.go
index 8b6ca6051..ca9612a4e 100644
--- a/pkg/crc/cache/cache.go
+++ b/pkg/crc/cache/cache.go
@@ -65,10 +65,6 @@ func getVersionGeneric(executablePath string, args ...string) (string, error) {
 	return strings.TrimSpace(parsedOutput[1]), nil
 }
 
-func NewPodmanCache() *Cache {
-	return New(constants.PodmanExecutableName, constants.GetPodmanURL(), constants.CrcBinDir, "", nil)
-}
-
 func NewAdminHelperCache() *Cache {
 	url := constants.GetAdminHelperURL()
 	version := path.Base(path.Dir(url))
diff --git a/pkg/crc/constants/constants.go b/pkg/crc/constants/constants.go
index 01c8e8479..3d034d347 100644
--- a/pkg/crc/constants/constants.go
+++ b/pkg/crc/constants/constants.go
@@ -42,20 +42,6 @@ const (
 	AppsDomain    = ".apps-crc.testing"
 )
 
-var podmanURLForOs = map[string]string{
-	"darwin":  fmt.Sprintf("%s/%s", DefaultPodmanURLBase, "podman-remote-latest-master-darwin-amd64.zip"),
-	"linux":   fmt.Sprintf("%s/%s", DefaultPodmanURLBase, "podman-remote-latest-master-linux---amd64.zip"),
-	"windows": fmt.Sprintf("%s/%s", DefaultPodmanURLBase, "podman-remote-latest-master-windows-amd64.zip"),
-}
-
-func GetPodmanURLForOs(os string) string {
-	return podmanURLForOs[os]
-}
-
-func GetPodmanURL() string {
-	return podmanURLForOs[runtime.GOOS]
-}
-
 var adminHelperURLForOs = map[string]string{
 	"darwin":  fmt.Sprintf("%s/%s", DefaultAdminHelperCliBase, "admin-helper-darwin"),
 	"linux":   fmt.Sprintf("%s/%s", DefaultAdminHelperCliBase, "admin-helper-linux"),
diff --git a/pkg/crc/constants/constants_darwin.go b/pkg/crc/constants/constants_darwin.go
index 29cac35c0..f8e306116 100644
--- a/pkg/crc/constants/constants_darwin.go
+++ b/pkg/crc/constants/constants_darwin.go
@@ -8,7 +8,6 @@ import (
 
 const (
 	OcExecutableName          = "oc"
-	PodmanExecutableName      = "podman"
 	TrayExecutableName        = "CodeReady Containers.app"
 	AdminHelperExecutableName = "admin-helper-darwin"
 )
diff --git a/pkg/crc/constants/constants_linux.go b/pkg/crc/constants/constants_linux.go
index d6152b678..8aa5ea5f0 100644
--- a/pkg/crc/constants/constants_linux.go
+++ b/pkg/crc/constants/constants_linux.go
@@ -6,7 +6,6 @@ import (
 
 const (
 	OcExecutableName          = "oc"
-	PodmanExecutableName      = "podman"
 	AdminHelperExecutableName = "admin-helper-linux"
 	TapSocketPath             = ""
 )
diff --git a/pkg/crc/constants/constants_windows.go b/pkg/crc/constants/constants_windows.go
index 60891fb33..7fd8270e2 100644
--- a/pkg/crc/constants/constants_windows.go
+++ b/pkg/crc/constants/constants_windows.go
@@ -7,7 +7,6 @@ import (
 
 const (
 	OcExecutableName            = "oc.exe"
-	PodmanExecutableName        = "podman.exe"
 	AdminHelperExecutableName   = "admin-helper-windows.exe"
 	TrayExecutableName          = "tray-windows.exe"
 	TrayShortcutName            = "tray-windows.lnk"
diff --git a/pkg/crc/preflight/preflight_checks_common.go b/pkg/crc/preflight/preflight_checks_common.go
index efd0ee713..99c5f8a3a 100644
--- a/pkg/crc/preflight/preflight_checks_common.go
+++ b/pkg/crc/preflight/preflight_checks_common.go
@@ -30,13 +30,6 @@ var bundleCheck = Check{
 }
 
 var genericPreflightChecks = [...]Check{
-	{
-		configKeySuffix:  "check-podman-cached",
-		checkDescription: "Checking if podman remote executable is cached",
-		check:            checkPodmanExecutableCached,
-		fixDescription:   "Caching podman remote executable",
-		fix:              fixPodmanExecutableCached,
-	},
 	{
 		configKeySuffix:  "check-admin-helper-cached",
 		checkDescription: "Checking if admin-helper executable is cached",
@@ -140,22 +133,6 @@ func fixBundleExtracted() error {
 	return nil
 }
 
-// Check if podman executable is cached or not
-func checkPodmanExecutableCached() error {
-	// Disable the podman cache until further notice
-	logging.Debug("Currently podman remote is not supported")
-	return nil
-}
-
-func fixPodmanExecutableCached() error {
-	podman := cache.NewPodmanCache()
-	if err := podman.EnsureIsCached(); err != nil {
-		return fmt.Errorf("Unable to download podman remote executable %v", err)
-	}
-	logging.Debug("podman remote executable cached")
-	return nil
-}
-
 // Check if helper executable is cached or not
 func checkAdminHelperExecutableCached() error {
 	if version.IsMacosInstallPathSet() {


Test patch:
diff --git a/pkg/crc/preflight/preflight_darwin_test.go b/pkg/crc/preflight/preflight_darwin_test.go
index 3d7d6847a..fbb35915e 100644
--- a/pkg/crc/preflight/preflight_darwin_test.go
+++ b/pkg/crc/preflight/preflight_darwin_test.go
@@ -12,13 +12,13 @@ import (
 func TestCountConfigurationOptions(t *testing.T) {
 	cfg := config.New(config.NewEmptyInMemoryStorage())
 	RegisterSettings(cfg)
-	assert.Len(t, cfg.AllConfigs(), 11)
+	assert.Len(t, cfg.AllConfigs(), 10)
 }
 
 func TestCountPreflights(t *testing.T) {
-	assert.Len(t, getPreflightChecks(true, false, network.DefaultMode), 17)
-	assert.Len(t, getPreflightChecks(true, true, network.DefaultMode), 17)
+	assert.Len(t, getPreflightChecks(true, false, network.DefaultMode), 16)
+	assert.Len(t, getPreflightChecks(true, true, network.DefaultMode), 16)
 
-	assert.Len(t, getPreflightChecks(true, false, network.VSockMode), 16)
-	assert.Len(t, getPreflightChecks(true, true, network.VSockMode), 16)
+	assert.Len(t, getPreflightChecks(true, false, network.VSockMode), 15)
+	assert.Len(t, getPreflightChecks(true, true, network.VSockMode), 15)
 }
diff --git a/pkg/crc/preflight/preflight_linux_test.go b/pkg/crc/preflight/preflight_linux_test.go
index d12b340f3..f49dd3184 100644
--- a/pkg/crc/preflight/preflight_linux_test.go
+++ b/pkg/crc/preflight/preflight_linux_test.go
@@ -63,7 +63,6 @@ var checkListForDistros = []checkListForDistro{
 		systemdResolved: true,
 		checks: []Check{
 			{check: checkIfRunningAsNormalUser},
-			{check: checkPodmanExecutableCached},
 			{check: checkAdminHelperExecutableCached},
 			{check: checkSupportedCPUArch},
 			{configKeySuffix: "check-ram"},
@@ -97,7 +96,6 @@ var checkListForDistros = []checkListForDistro{
 		systemdResolved: false,
 		checks: []Check{
 			{check: checkIfRunningAsNormalUser},
-			{check: checkPodmanExecutableCached},
 			{check: checkAdminHelperExecutableCached},
 			{check: checkSupportedCPUArch},
 			{configKeySuffix: "check-ram"},
@@ -130,7 +128,6 @@ var checkListForDistros = []checkListForDistro{
 		systemdResolved: false,
 		checks: []Check{
 			{check: checkIfRunningAsNormalUser},
-			{check: checkPodmanExecutableCached},
 			{check: checkAdminHelperExecutableCached},
 			{check: checkSupportedCPUArch},
 			{configKeySuffix: "check-ram"},
@@ -157,7 +154,6 @@ var checkListForDistros = []checkListForDistro{
 		systemdResolved: true,
 		checks: []Check{
 			{check: checkIfRunningAsNormalUser},
-			{check: checkPodmanExecutableCached},
 			{check: checkAdminHelperExecutableCached},
 			{check: checkSupportedCPUArch},
 			{configKeySuffix: "check-ram"},
@@ -191,7 +187,6 @@ var checkListForDistros = []checkListForDistro{
 		systemdResolved: false,
 		checks: []Check{
 			{check: checkIfRunningAsNormalUser},
-			{check: checkPodmanExecutableCached},
 			{check: checkAdminHelperExecutableCached},
 			{check: checkSupportedCPUArch},
 			{configKeySuffix: "check-ram"},
@@ -224,7 +219,6 @@ var checkListForDistros = []checkListForDistro{
 		systemdResolved: false,
 		checks: []Check{
 			{check: checkIfRunningAsNormalUser},
-			{check: checkPodmanExecutableCached},
 			{check: checkAdminHelperExecutableCached},
 			{check: checkSupportedCPUArch},
 			{configKeySuffix: "check-ram"},
@@ -251,7 +245,6 @@ var checkListForDistros = []checkListForDistro{
 		systemdResolved: true,
 		checks: []Check{
 			{check: checkIfRunningAsNormalUser},
-			{check: checkPodmanExecutableCached},
 			{check: checkAdminHelperExecutableCached},
 			{check: checkSupportedCPUArch},
 			{configKeySuffix: "check-ram"},
@@ -285,7 +278,6 @@ var checkListForDistros = []checkListForDistro{
 		systemdResolved: false,
 		checks: []Check{
 			{check: checkIfRunningAsNormalUser},
-			{check: checkPodmanExecutableCached},
 			{check: checkAdminHelperExecutableCached},
 			{check: checkSupportedCPUArch},
 			{configKeySuffix: "check-ram"},
@@ -318,7 +310,6 @@ var checkListForDistros = []checkListForDistro{
 		systemdResolved: false,
 		checks: []Check{
 			{check: checkIfRunningAsNormalUser},
-			{check: checkPodmanExecutableCached},
 			{check: checkAdminHelperExecutableCached},
 			{check: checkSupportedCPUArch},
 			{configKeySuffix: "check-ram"},
@@ -345,7 +336,6 @@ var checkListForDistros = []checkListForDistro{
 		systemdResolved: true,
 		checks: []Check{
 			{check: checkIfRunningAsNormalUser},
-			{check: checkPodmanExecutableCached},
 			{check: checkAdminHelperExecutableCached},
 			{check: checkSupportedCPUArch},
 			{configKeySuffix: "check-ram"},
@@ -380,7 +370,6 @@ var checkListForDistros = []checkListForDistro{
 		systemdResolved: false,
 		checks: []Check{
 			{check: checkIfRunningAsNormalUser},
-			{check: checkPodmanExecutableCached},
 			{check: checkAdminHelperExecutableCached},
 			{check: checkSupportedCPUArch},
 			{configKeySuffix: "check-ram"},
@@ -414,7 +403,6 @@ var checkListForDistros = []checkListForDistro{
 		systemdResolved: false,
 		checks: []Check{
 			{check: checkIfRunningAsNormalUser},
-			{check: checkPodmanExecutableCached},
 			{check: checkAdminHelperExecutableCached},
 			{check: checkSupportedCPUArch},
 			{configKeySuffix: "check-ram"},
diff --git a/pkg/crc/preflight/preflight_windows_test.go b/pkg/crc/preflight/preflight_windows_test.go
index da9068383..40ba6336c 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(), 13)
+	assert.Len(t, cfg.AllConfigs(), 12)
 }
 
 func TestCountPreflights(t *testing.T) {
-	assert.Len(t, getPreflightChecks(false, false, network.DefaultMode), 18)
-	assert.Len(t, getPreflightChecks(true, true, network.DefaultMode), 21)
+	assert.Len(t, getPreflightChecks(false, false, network.DefaultMode), 17)
+	assert.Len(t, getPreflightChecks(true, true, network.DefaultMode), 20)
 
-	assert.Len(t, getPreflightChecks(false, false, network.VSockMode), 19)
-	assert.Len(t, getPreflightChecks(true, true, network.VSockMode), 22)
+	assert.Len(t, getPreflightChecks(false, false, network.VSockMode), 18)
+	assert.Len(t, getPreflightChecks(true, true, network.VSockMode), 21)
 }