Repository: replicatedhq/troubleshoot (go)

Issue:
Postgres analyzer fails to parse postgres version
If you run the Postgres [support-bundle example](https://troubleshoot.sh/preflight/supported-postgres-version) against Postgres 10, the bundle includes the file `postgres/postgresql.json` with these contents:

```json
{"isConnected":true,"version":"10.14"}
```

The analyzer logs container the error `an analyzer failed to run: failed to compare postgres database conditional: failed to parse actual psotgres version: No Major.Minor.Patch elements found`

Pull request description:
Error Parsing Postgres Version 
@areed Hi! Regarding issue #254, the problem was that the semver version used only accepts version format major.minor.patch (eg. 10.2.3). This PR fix #254 

According to Postgres Versioning Policy, starting with version 10 on the version string will only have 2 parts, major.minor, that would make possible to simply add a 0 after the versions entered by the user and the one collected, but I think this solution is more robust.

I tested it against a dockerized Postgres DB and worked just fine.

Patch:
diff --git a/cmd/analyze/main.go b/cmd/analyze/main.go
index 738dacb9..c2a6dede 100644
--- a/cmd/analyze/main.go
+++ b/cmd/analyze/main.go
@@ -2,7 +2,7 @@ package main
 
 import (
 	"github.com/replicatedhq/troubleshoot/cmd/analyze/cli"
-	_ "k8s.io/client-go/plugin/pkg/client/auth"
+	_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
 )
 
 func main() {
diff --git a/cmd/preflight/main.go b/cmd/preflight/main.go
index 21d4e3ce..cd268fa6 100644
--- a/cmd/preflight/main.go
+++ b/cmd/preflight/main.go
@@ -2,7 +2,7 @@ package main
 
 import (
 	"github.com/replicatedhq/troubleshoot/cmd/preflight/cli"
-	_ "k8s.io/client-go/plugin/pkg/client/auth"
+	_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
 )
 
 func main() {
diff --git a/cmd/troubleshoot/main.go b/cmd/troubleshoot/main.go
index 2fbeed5e..9298aa35 100644
--- a/cmd/troubleshoot/main.go
+++ b/cmd/troubleshoot/main.go
@@ -2,7 +2,7 @@ package main
 
 import (
 	"github.com/replicatedhq/troubleshoot/cmd/troubleshoot/cli"
-	_ "k8s.io/client-go/plugin/pkg/client/auth"
+	_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
 )
 
 func main() {
diff --git a/pkg/analyze/database_shared.go b/pkg/analyze/database_shared.go
index f0b56f51..55fe8f5d 100644
--- a/pkg/analyze/database_shared.go
+++ b/pkg/analyze/database_shared.go
@@ -35,14 +35,18 @@ func compareDatabaseConditionalToActual(conditional string, result *collect.Data
 		return false, errors.New("unable to parse postgres connected analyzer")
 
 	case "version":
-		expectedRange, err := semver.ParseRange(fmt.Sprintf("%s %s", parts[1], parts[2]))
+		expected, err := semver.ParseTolerant(strings.Replace(parts[2], "x", "0", -1))
 		if err != nil {
-			return false, errors.Wrap(err, "failed to parse semver range")
+			return false, errors.Wrap(err, "failed to parse expected version")
+		}
+		actual, err := semver.ParseTolerant(strings.Replace(result.Version, "x", "0", -1))
+		if err != nil {
+			return false, errors.Wrap(err, "failed to parse postgres db actual version")
 		}
 
-		actual, err := semver.Parse(result.Version)
+		expectedRange, err := semver.ParseRange(fmt.Sprintf("%s %s", parts[1], expected.String()))
 		if err != nil {
-			return false, errors.Wrap(err, "failed to parse actual psotgres version")
+			return false, errors.Wrap(err, "failed to parse semver range")
 		}
 
 		return expectedRange(actual), nil
diff --git a/pkg/analyze/deployment_status.go b/pkg/analyze/deployment_status.go
index c013d8a4..5f2a5ab9 100644
--- a/pkg/analyze/deployment_status.go
+++ b/pkg/analyze/deployment_status.go
@@ -3,7 +3,7 @@ package analyzer
 import (
 	"encoding/json"
 	"fmt"
-	"path/filepath"
+	"path"
 
 	"github.com/pkg/errors"
 	troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
@@ -11,7 +11,7 @@ import (
 )
 
 func analyzeDeploymentStatus(analyzer *troubleshootv1beta2.DeploymentStatus, getCollectedFileContents func(string) ([]byte, error)) (*AnalyzeResult, error) {
-	collected, err := getCollectedFileContents(filepath.Join("cluster-resources", "deployments", fmt.Sprintf("%s.json", analyzer.Namespace)))
+	collected, err := getCollectedFileContents(path.Join("cluster-resources", "deployments", fmt.Sprintf("%s.json", analyzer.Namespace)))
 	if err != nil {
 		return nil, errors.Wrap(err, "failed to read collected deployments from namespace")
 	}
diff --git a/pkg/analyze/distribution.go b/pkg/analyze/distribution.go
index d8462370..9d9afa8b 100644
--- a/pkg/analyze/distribution.go
+++ b/pkg/analyze/distribution.go
@@ -2,7 +2,6 @@ package analyzer
 
 import (
 	"encoding/json"
-	"fmt"
 	"strings"
 
 	"github.com/pkg/errors"
@@ -20,8 +19,6 @@ type providers struct {
 	openShift     bool
 	kurl          bool
 	aks           bool
-	ibm           bool
-	minikube      bool
 }
 
 type Provider int
@@ -36,8 +33,6 @@ const (
 	openShift     Provider = iota
 	kurl          Provider = iota
 	aks           Provider = iota
-	ibm           Provider = iota
-	minikube      Provider = iota
 )
 
 func CheckOpenShift(foundProviders *providers, apiResources []*metav1.APIResourceList, provider string) string {
@@ -73,10 +68,6 @@ func ParseNodesForProviders(nodes []corev1.Node) (providers, string) {
 				foundProviders.aks = true
 				stringProvider = "aks"
 			}
-			if k == "minikube.k8s.io/version" {
-				foundProviders.minikube = true
-				stringProvider = "minikube"
-			}
 		}
 
 		if node.Status.NodeInfo.OSImage == "Docker Desktop" {
@@ -96,10 +87,6 @@ func ParseNodesForProviders(nodes []corev1.Node) (providers, string) {
 			foundProviders.gke = true
 			stringProvider = "gke"
 		}
-		if strings.HasPrefix(node.Spec.ProviderID, "ibm:") {
-			foundProviders.ibm = true
-			stringProvider = "ibm"
-		}
 	}
 
 	if foundMaster {
@@ -114,7 +101,6 @@ func ParseNodesForProviders(nodes []corev1.Node) (providers, string) {
 }
 
 func analyzeDistribution(analyzer *troubleshootv1beta2.Distribution, getCollectedFileContents func(string) ([]byte, error)) (*AnalyzeResult, error) {
-	var unknownDistribution string
 	collected, err := getCollectedFileContents("cluster-resources/nodes.json")
 	if err != nil {
 		return nil, errors.Wrap(err, "failed to get contents of nodes.json")
@@ -158,7 +144,7 @@ func analyzeDistribution(analyzer *troubleshootv1beta2.Distribution, getCollecte
 				return result, nil
 			}
 
-			isMatch, err := compareDistributionConditionalToActual(outcome.Fail.When, foundProviders, &unknownDistribution)
+			isMatch, err := compareDistributionConditionalToActual(outcome.Fail.When, foundProviders)
 			if err != nil {
 				return result, errors.Wrap(err, "failed to compare distribution conditional")
 			}
@@ -179,7 +165,7 @@ func analyzeDistribution(analyzer *troubleshootv1beta2.Distribution, getCollecte
 				return result, nil
 			}
 
-			isMatch, err := compareDistributionConditionalToActual(outcome.Warn.When, foundProviders, &unknownDistribution)
+			isMatch, err := compareDistributionConditionalToActual(outcome.Warn.When, foundProviders)
 			if err != nil {
 				return result, errors.Wrap(err, "failed to compare distribution conditional")
 			}
@@ -200,7 +186,7 @@ func analyzeDistribution(analyzer *troubleshootv1beta2.Distribution, getCollecte
 				return result, nil
 			}
 
-			isMatch, err := compareDistributionConditionalToActual(outcome.Pass.When, foundProviders, &unknownDistribution)
+			isMatch, err := compareDistributionConditionalToActual(outcome.Pass.When, foundProviders)
 			if err != nil {
 				return result, errors.Wrap(err, "failed to compare distribution conditional")
 			}
@@ -216,17 +202,10 @@ func analyzeDistribution(analyzer *troubleshootv1beta2.Distribution, getCollecte
 		}
 	}
 
-	result.IsWarn = true
-	if unknownDistribution != "" {
-		result.Message = unknownDistribution
-	} else {
-		result.Message = "None of the conditionals were met"
-	}
-
 	return result, nil
 }
 
-func compareDistributionConditionalToActual(conditional string, actual providers, unknownDistribution *string) (bool, error) {
+func compareDistributionConditionalToActual(conditional string, actual providers) (bool, error) {
 	parts := strings.Split(strings.TrimSpace(conditional), " ")
 
 	// we can make this a lot more flexible
@@ -244,7 +223,6 @@ func compareDistributionConditionalToActual(conditional string, actual providers
 	normalizedName := mustNormalizeDistributionName(parts[1])
 
 	if normalizedName == unknown {
-		*unknownDistribution += fmt.Sprintf("- Unknown distribution: %s ", parts[1])
 		return false, nil
 	}
 
@@ -266,10 +244,6 @@ func compareDistributionConditionalToActual(conditional string, actual providers
 		isMatch = actual.kurl
 	case aks:
 		isMatch = actual.aks
-	case ibm:
-		isMatch = actual.ibm
-	case minikube:
-		isMatch = actual.minikube
 	}
 
 	switch parts[0] {
@@ -300,10 +274,6 @@ func mustNormalizeDistributionName(raw string) Provider {
 		return kurl
 	case "aks":
 		return aks
-	case "ibm", "ibmcloud", "ibm cloud":
-		return ibm
-	case "minikube":
-		return minikube
 	}
 
 	return unknown
diff --git a/pkg/analyze/ingress.go b/pkg/analyze/ingress.go
index 4e349f8c..605a9bb6 100644
--- a/pkg/analyze/ingress.go
+++ b/pkg/analyze/ingress.go
@@ -3,14 +3,13 @@ package analyzer
 import (
 	"encoding/json"
 	"fmt"
-	"path/filepath"
 
 	troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
 	extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
 )
 
 func analyzeIngress(analyzer *troubleshootv1beta2.Ingress, getCollectedFileContents func(string) ([]byte, error)) (*AnalyzeResult, error) {
-	ingressData, err := getCollectedFileContents(filepath.Join("cluster-resources", "ingress", fmt.Sprintf("%s.json", analyzer.Namespace)))
+	ingressData, err := getCollectedFileContents("cluster-resources/storage-classes.json")
 	if err != nil {
 		return nil, err
 	}
diff --git a/pkg/analyze/statefulset_status.go b/pkg/analyze/statefulset_status.go
index 6b56a1ec..98585490 100644
--- a/pkg/analyze/statefulset_status.go
+++ b/pkg/analyze/statefulset_status.go
@@ -3,7 +3,7 @@ package analyzer
 import (
 	"encoding/json"
 	"fmt"
-	"path/filepath"
+	"path"
 
 	"github.com/pkg/errors"
 	troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
@@ -11,7 +11,7 @@ import (
 )
 
 func analyzeStatefulsetStatus(analyzer *troubleshootv1beta2.StatefulsetStatus, getCollectedFileContents func(string) ([]byte, error)) (*AnalyzeResult, error) {
-	collected, err := getCollectedFileContents(filepath.Join("cluster-resources", "statefulsets", fmt.Sprintf("%s.json", analyzer.Namespace)))
+	collected, err := getCollectedFileContents(path.Join("cluster-resources", "statefulsets", fmt.Sprintf("%s.json", analyzer.Namespace)))
 	if err != nil {
 		return nil, errors.Wrap(err, "failed to read collected statefulsets from namespace")
 	}
diff --git a/pkg/collect/run.go b/pkg/collect/run.go
index 578faab9..3c3bffb4 100644
--- a/pkg/collect/run.go
+++ b/pkg/collect/run.go
@@ -89,13 +89,6 @@ func runWithoutTimeout(ctx context.Context, c *Collector, pod *corev1.Pod, runCo
 			status.Status.Phase == corev1.PodSucceeded {
 			break
 		}
-		if status.Status.Phase == corev1.PodPending {
-			for _, v := range status.Status.ContainerStatuses {
-				if v.State.Waiting.Reason == "ImagePullBackOff" {
-					return nil, errors.Errorf("run pod aborted after getting pod status 'ImagePullBackOff'")
-				}
-			}
-		}
 		time.Sleep(time.Second * 1)
 	}
 
diff --git a/pkg/collect/secret.go b/pkg/collect/secret.go
index 931da8e4..06d92678 100644
--- a/pkg/collect/secret.go
+++ b/pkg/collect/secret.go
@@ -71,9 +71,7 @@ func secret(ctx context.Context, client *kubernetes.Clientset, secretCollector *
 
 	keyExists := false
 	keyData := ""
-	secretKey := ""
 	if secretCollector.Key != "" {
-		secretKey = secretCollector.Key
 		if val, ok := found.Data[secretCollector.Key]; ok {
 			keyExists = true
 			if secretCollector.IncludeValue {
@@ -85,7 +83,6 @@ func secret(ctx context.Context, client *kubernetes.Clientset, secretCollector *
 	secret := FoundSecret{
 		Namespace:    found.Namespace,
 		Name:         found.Name,
-		Key:          secretKey,
 		SecretExists: true,
 		KeyExists:    keyExists,
 		Value:        keyData,


Test patch:
diff --git a/pkg/analyze/distribution_test.go b/pkg/analyze/distribution_test.go
index 684ee7ed..42de3de0 100644
--- a/pkg/analyze/distribution_test.go
+++ b/pkg/analyze/distribution_test.go
@@ -9,7 +9,6 @@ import (
 )
 
 func Test_compareDistributionConditionalToActual(t *testing.T) {
-	var unknownDistribution string
 	tests := []struct {
 		name        string
 		conditional string
@@ -47,7 +46,7 @@ func Test_compareDistributionConditionalToActual(t *testing.T) {
 			defer scopetest.End()
 			req := require.New(t)
 
-			actual, err := compareDistributionConditionalToActual(test.conditional, test.input, &unknownDistribution)
+			actual, err := compareDistributionConditionalToActual(test.conditional, test.input)
 			req.NoError(err)
 
 			assert.Equal(t, test.expected, actual)