Skip to content

Commit 8a30f2d

Browse files
authored
Merge pull request #269 from manavellamnimble/distributionEnhacement
Distribution enhacement
2 parents 58261cd + 0ea4e1d commit 8a30f2d

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

pkg/analyze/distribution.go

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package analyzer
22

33
import (
44
"encoding/json"
5+
"fmt"
56
"strings"
67

78
"github.com/pkg/errors"
@@ -19,6 +20,8 @@ type providers struct {
1920
openShift bool
2021
kurl bool
2122
aks bool
23+
ibm bool
24+
minikube bool
2225
}
2326

2427
type Provider int
@@ -33,6 +36,8 @@ const (
3336
openShift Provider = iota
3437
kurl Provider = iota
3538
aks Provider = iota
39+
ibm Provider = iota
40+
minikube Provider = iota
3641
)
3742

3843
func CheckOpenShift(foundProviders *providers, apiResources []*metav1.APIResourceList, provider string) string {
@@ -68,6 +73,10 @@ func ParseNodesForProviders(nodes []corev1.Node) (providers, string) {
6873
foundProviders.aks = true
6974
stringProvider = "aks"
7075
}
76+
if k == "minikube.k8s.io/version" {
77+
foundProviders.minikube = true
78+
stringProvider = "minikube"
79+
}
7180
}
7281

7382
if node.Status.NodeInfo.OSImage == "Docker Desktop" {
@@ -87,6 +96,10 @@ func ParseNodesForProviders(nodes []corev1.Node) (providers, string) {
8796
foundProviders.gke = true
8897
stringProvider = "gke"
8998
}
99+
if strings.HasPrefix(node.Spec.ProviderID, "ibm:") {
100+
foundProviders.ibm = true
101+
stringProvider = "ibm"
102+
}
90103
}
91104

92105
if foundMaster {
@@ -101,6 +114,7 @@ func ParseNodesForProviders(nodes []corev1.Node) (providers, string) {
101114
}
102115

103116
func analyzeDistribution(analyzer *troubleshootv1beta2.Distribution, getCollectedFileContents func(string) ([]byte, error)) (*AnalyzeResult, error) {
117+
var unknownDistribution string
104118
collected, err := getCollectedFileContents("cluster-resources/nodes.json")
105119
if err != nil {
106120
return nil, errors.Wrap(err, "failed to get contents of nodes.json")
@@ -144,7 +158,7 @@ func analyzeDistribution(analyzer *troubleshootv1beta2.Distribution, getCollecte
144158
return result, nil
145159
}
146160

147-
isMatch, err := compareDistributionConditionalToActual(outcome.Fail.When, foundProviders)
161+
isMatch, err := compareDistributionConditionalToActual(outcome.Fail.When, foundProviders, &unknownDistribution)
148162
if err != nil {
149163
return result, errors.Wrap(err, "failed to compare distribution conditional")
150164
}
@@ -165,7 +179,7 @@ func analyzeDistribution(analyzer *troubleshootv1beta2.Distribution, getCollecte
165179
return result, nil
166180
}
167181

168-
isMatch, err := compareDistributionConditionalToActual(outcome.Warn.When, foundProviders)
182+
isMatch, err := compareDistributionConditionalToActual(outcome.Warn.When, foundProviders, &unknownDistribution)
169183
if err != nil {
170184
return result, errors.Wrap(err, "failed to compare distribution conditional")
171185
}
@@ -186,7 +200,7 @@ func analyzeDistribution(analyzer *troubleshootv1beta2.Distribution, getCollecte
186200
return result, nil
187201
}
188202

189-
isMatch, err := compareDistributionConditionalToActual(outcome.Pass.When, foundProviders)
203+
isMatch, err := compareDistributionConditionalToActual(outcome.Pass.When, foundProviders, &unknownDistribution)
190204
if err != nil {
191205
return result, errors.Wrap(err, "failed to compare distribution conditional")
192206
}
@@ -202,10 +216,17 @@ func analyzeDistribution(analyzer *troubleshootv1beta2.Distribution, getCollecte
202216
}
203217
}
204218

219+
result.IsWarn = true
220+
if unknownDistribution != "" {
221+
result.Message = unknownDistribution
222+
} else {
223+
result.Message = "None of the conditionals were met"
224+
}
225+
205226
return result, nil
206227
}
207228

208-
func compareDistributionConditionalToActual(conditional string, actual providers) (bool, error) {
229+
func compareDistributionConditionalToActual(conditional string, actual providers, unknownDistribution *string) (bool, error) {
209230
parts := strings.Split(strings.TrimSpace(conditional), " ")
210231

211232
// we can make this a lot more flexible
@@ -223,6 +244,7 @@ func compareDistributionConditionalToActual(conditional string, actual providers
223244
normalizedName := mustNormalizeDistributionName(parts[1])
224245

225246
if normalizedName == unknown {
247+
*unknownDistribution += fmt.Sprintf("- Unknown distribution: %s ", parts[1])
226248
return false, nil
227249
}
228250

@@ -244,6 +266,10 @@ func compareDistributionConditionalToActual(conditional string, actual providers
244266
isMatch = actual.kurl
245267
case aks:
246268
isMatch = actual.aks
269+
case ibm:
270+
isMatch = actual.ibm
271+
case minikube:
272+
isMatch = actual.minikube
247273
}
248274

249275
switch parts[0] {
@@ -274,6 +300,10 @@ func mustNormalizeDistributionName(raw string) Provider {
274300
return kurl
275301
case "aks":
276302
return aks
303+
case "ibm", "ibmcloud", "ibm cloud":
304+
return ibm
305+
case "minikube":
306+
return minikube
277307
}
278308

279309
return unknown

pkg/analyze/distribution_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
)
1010

1111
func Test_compareDistributionConditionalToActual(t *testing.T) {
12+
var unknownDistribution string
1213
tests := []struct {
1314
name string
1415
conditional string
@@ -46,7 +47,7 @@ func Test_compareDistributionConditionalToActual(t *testing.T) {
4647
defer scopetest.End()
4748
req := require.New(t)
4849

49-
actual, err := compareDistributionConditionalToActual(test.conditional, test.input)
50+
actual, err := compareDistributionConditionalToActual(test.conditional, test.input, &unknownDistribution)
5051
req.NoError(err)
5152

5253
assert.Equal(t, test.expected, actual)

0 commit comments

Comments
 (0)