From 033524a83a45bc9b8e39b76c4fa96566bfe862a3 Mon Sep 17 00:00:00 2001 From: Andrew Lavery Date: Wed, 8 Jan 2020 15:38:32 -0800 Subject: [PATCH] identify openshift clusters with distribution analyzer --- pkg/analyze/distribution.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pkg/analyze/distribution.go b/pkg/analyze/distribution.go index 0365962a0..7dd934ac5 100644 --- a/pkg/analyze/distribution.go +++ b/pkg/analyze/distribution.go @@ -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 { @@ -15,6 +16,7 @@ type providers struct { eks bool gke bool digitalOcean bool + openShift bool } type Provider int @@ -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) { @@ -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", } @@ -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] { @@ -196,6 +215,8 @@ func mustNormalizeDistributionName(raw string) Provider { return gke case "digitalocean": return digitalOcean + case "openshift": + return openShift } return unknown