Skip to content

Commit 033524a

Browse files
committed
identify openshift clusters with distribution analyzer
1 parent 6467588 commit 033524a

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

pkg/analyze/distribution.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/pkg/errors"
88
troubleshootv1beta1 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1"
99
corev1 "k8s.io/api/core/v1"
10+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1011
)
1112

1213
type providers struct {
@@ -15,6 +16,7 @@ type providers struct {
1516
eks bool
1617
gke bool
1718
digitalOcean bool
19+
openShift bool
1820
}
1921

2022
type Provider int
@@ -26,6 +28,7 @@ const (
2628
eks Provider = iota
2729
gke Provider = iota
2830
digitalOcean Provider = iota
31+
openShift Provider = iota
2932
)
3033

3134
func analyzeDistribution(analyzer *troubleshootv1beta1.Distribution, getCollectedFileContents func(string) ([]byte, error)) (*AnalyzeResult, error) {
@@ -63,6 +66,20 @@ func analyzeDistribution(analyzer *troubleshootv1beta1.Distribution, getCollecte
6366
}
6467
}
6568

69+
apiResourcesBytes, err := getCollectedFileContents("cluster-resources/resources.json")
70+
if err != nil {
71+
return nil, errors.Wrap(err, "failed to get contents of resources.json")
72+
}
73+
var apiResources []*metav1.APIResourceList
74+
if err := json.Unmarshal(apiResourcesBytes, &apiResources); err != nil {
75+
return nil, errors.Wrap(err, "failed to unmarshal api resource list")
76+
}
77+
for _, resource := range apiResources {
78+
if strings.Contains(resource.GroupVersion, "openshift") {
79+
foundProviders.openShift = true
80+
}
81+
}
82+
6683
result := &AnalyzeResult{
6784
Title: "Kubernetes Distribution",
6885
}
@@ -172,6 +189,8 @@ func compareDistributionConditionalToActual(conditional string, actual providers
172189
isMatch = actual.gke
173190
case digitalOcean:
174191
isMatch = actual.digitalOcean
192+
case openShift:
193+
isMatch = actual.openShift
175194
}
176195

177196
switch parts[0] {
@@ -196,6 +215,8 @@ func mustNormalizeDistributionName(raw string) Provider {
196215
return gke
197216
case "digitalocean":
198217
return digitalOcean
218+
case "openshift":
219+
return openShift
199220
}
200221

201222
return unknown

0 commit comments

Comments
 (0)