Repository: replicatedhq/troubleshoot (go)

Issue:
Secret analyzer fails when key is set
The following spec fails after creating the secret with the uri key set.

```
apiVersion: troubleshoot.sh/v1beta2
kind: Preflight
metadata:
  name: preflight-sample
spec:
  collectors:
    - secret:
        name: my-app-postgres
        namespace: default
        key: uri
        includeValue: false
  analyzers:
    - secret:
        checkName: Postgres URI Secret
        secretName: my-app-postgres
        namespace: default
        key: uri
        outcomes:
          - fail:
              message: The `my-app-postgres` secret was not found or the `uri` key was not detected.
          - pass:
              message: The Postgres URI was found in a secret in the cluster.
```

Pull request:
Secret analyzer fixed
@areed @divolgin The problem was not the analyzer, but the collector. Fix #265 

Patch:
diff --git a/pkg/analyze/database_shared.go b/pkg/analyze/database_shared.go
index 55fe8f5d..f0b56f51 100644
--- a/pkg/analyze/database_shared.go
+++ b/pkg/analyze/database_shared.go
@@ -35,18 +35,14 @@ func compareDatabaseConditionalToActual(conditional string, result *collect.Data
 		return false, errors.New("unable to parse postgres connected analyzer")
 
 	case "version":
-		expected, err := semver.ParseTolerant(strings.Replace(parts[2], "x", "0", -1))
+		expectedRange, err := semver.ParseRange(fmt.Sprintf("%s %s", parts[1], parts[2]))
 		if err != nil {
-			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")
+			return false, errors.Wrap(err, "failed to parse semver range")
 		}
 
-		expectedRange, err := semver.ParseRange(fmt.Sprintf("%s %s", parts[1], expected.String()))
+		actual, err := semver.Parse(result.Version)
 		if err != nil {
-			return false, errors.Wrap(err, "failed to parse semver range")
+			return false, errors.Wrap(err, "failed to parse actual psotgres version")
 		}
 
 		return expectedRange(actual), nil
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/collect/secret.go b/pkg/collect/secret.go
index 931da8e4..5fab9b53 100644
--- a/pkg/collect/secret.go
+++ b/pkg/collect/secret.go
@@ -67,7 +67,7 @@ func secret(ctx context.Context, client *kubernetes.Clientset, secretCollector *
 	}
 
 	ns = found.Namespace
-	path = fmt.Sprintf("%s.json", filepath.Join(ns, secretCollector.SecretName, secretCollector.Key))
+	path = fmt.Sprintf("%s.json", filepath.Join(ns, secretCollector.SecretName))
 
 	keyExists := false
 	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)