@@ -2,6 +2,7 @@ package analyzer
22
33import (
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
2427type 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
3843func 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
103116func 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
0 commit comments