Skip to content

Commit

Permalink
Merge pull request #113 from laverya/distribution-analyzer-openshift-…
Browse files Browse the repository at this point in the history
…support

identify openshift clusters with distribution analyzer
  • Loading branch information
laverya authored Jan 9, 2020
2 parents 6467588 + 033524a commit ff97a4e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pkg/analyze/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/pkg/errors"
troubleshootv1beta1 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type providers struct {
Expand All @@ -15,6 +16,7 @@ type providers struct {
eks bool
gke bool
digitalOcean bool
openShift bool
}

type Provider int
Expand All @@ -26,6 +28,7 @@ const (
eks Provider = iota
gke Provider = iota
digitalOcean Provider = iota
openShift Provider = iota
)

func analyzeDistribution(analyzer *troubleshootv1beta1.Distribution, getCollectedFileContents func(string) ([]byte, error)) (*AnalyzeResult, error) {
Expand Down Expand Up @@ -63,6 +66,20 @@ func analyzeDistribution(analyzer *troubleshootv1beta1.Distribution, getCollecte
}
}

apiResourcesBytes, err := getCollectedFileContents("cluster-resources/resources.json")
if err != nil {
return nil, errors.Wrap(err, "failed to get contents of resources.json")
}
var apiResources []*metav1.APIResourceList
if err := json.Unmarshal(apiResourcesBytes, &apiResources); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal api resource list")
}
for _, resource := range apiResources {
if strings.Contains(resource.GroupVersion, "openshift") {
foundProviders.openShift = true
}
}

result := &AnalyzeResult{
Title: "Kubernetes Distribution",
}
Expand Down Expand Up @@ -172,6 +189,8 @@ func compareDistributionConditionalToActual(conditional string, actual providers
isMatch = actual.gke
case digitalOcean:
isMatch = actual.digitalOcean
case openShift:
isMatch = actual.openShift
}

switch parts[0] {
Expand All @@ -196,6 +215,8 @@ func mustNormalizeDistributionName(raw string) Provider {
return gke
case "digitalocean":
return digitalOcean
case "openshift":
return openShift
}

return unknown
Expand Down

0 comments on commit ff97a4e

Please sign in to comment.