@@ -37,7 +37,6 @@ func isExcluded(excludeVal multitype.BoolOrString) (bool, error) {
3737}
3838
3939func Analyze (analyzer * troubleshootv1beta1.Analyze , getFile getCollectedFileContents , findFiles getChildCollectedFileContents ) ([]* AnalyzeResult , error ) {
40- results := []* AnalyzeResult {}
4140 if analyzer .ClusterVersion != nil {
4241 isExcluded , err := isExcluded (analyzer .ClusterVersion .Exclude )
4342 if err != nil {
@@ -50,7 +49,7 @@ func Analyze(analyzer *troubleshootv1beta1.Analyze, getFile getCollectedFileCont
5049 if err != nil {
5150 return nil , err
5251 }
53- results = append ( results , result )
52+ return [] * AnalyzeResult { result }, nil
5453 }
5554 if analyzer .StorageClass != nil {
5655 isExcluded , err := isExcluded (analyzer .StorageClass .Exclude )
@@ -64,7 +63,7 @@ func Analyze(analyzer *troubleshootv1beta1.Analyze, getFile getCollectedFileCont
6463 if err != nil {
6564 return nil , err
6665 }
67- results = append ( results , result )
66+ return [] * AnalyzeResult { result }, nil
6867 }
6968 if analyzer .CustomResourceDefinition != nil {
7069 isExcluded , err := isExcluded (analyzer .CustomResourceDefinition .Exclude )
@@ -78,7 +77,7 @@ func Analyze(analyzer *troubleshootv1beta1.Analyze, getFile getCollectedFileCont
7877 if err != nil {
7978 return nil , err
8079 }
81- results = append ( results , result )
80+ return [] * AnalyzeResult { result }, nil
8281 }
8382 if analyzer .Ingress != nil {
8483 isExcluded , err := isExcluded (analyzer .Ingress .Exclude )
@@ -92,7 +91,7 @@ func Analyze(analyzer *troubleshootv1beta1.Analyze, getFile getCollectedFileCont
9291 if err != nil {
9392 return nil , err
9493 }
95- results = append ( results , result )
94+ return [] * AnalyzeResult { result }, nil
9695 }
9796 if analyzer .Secret != nil {
9897 isExcluded , err := isExcluded (analyzer .Secret .Exclude )
@@ -106,7 +105,7 @@ func Analyze(analyzer *troubleshootv1beta1.Analyze, getFile getCollectedFileCont
106105 if err != nil {
107106 return nil , err
108107 }
109- results = append ( results , result )
108+ return [] * AnalyzeResult { result }, nil
110109 }
111110 if analyzer .ImagePullSecret != nil {
112111 isExcluded , err := isExcluded (analyzer .ImagePullSecret .Exclude )
@@ -120,7 +119,7 @@ func Analyze(analyzer *troubleshootv1beta1.Analyze, getFile getCollectedFileCont
120119 if err != nil {
121120 return nil , err
122121 }
123- results = append ( results , result )
122+ return [] * AnalyzeResult { result }, nil
124123 }
125124 if analyzer .DeploymentStatus != nil {
126125 isExcluded , err := isExcluded (analyzer .DeploymentStatus .Exclude )
@@ -134,7 +133,7 @@ func Analyze(analyzer *troubleshootv1beta1.Analyze, getFile getCollectedFileCont
134133 if err != nil {
135134 return nil , err
136135 }
137- results = append ( results , result )
136+ return [] * AnalyzeResult { result }, nil
138137 }
139138 if analyzer .StatefulsetStatus != nil {
140139 isExcluded , err := isExcluded (analyzer .StatefulsetStatus .Exclude )
@@ -148,7 +147,7 @@ func Analyze(analyzer *troubleshootv1beta1.Analyze, getFile getCollectedFileCont
148147 if err != nil {
149148 return nil , err
150149 }
151- results = append ( results , result )
150+ return [] * AnalyzeResult { result }, nil
152151 }
153152 if analyzer .ContainerRuntime != nil {
154153 isExcluded , err := isExcluded (analyzer .ContainerRuntime .Exclude )
@@ -162,7 +161,7 @@ func Analyze(analyzer *troubleshootv1beta1.Analyze, getFile getCollectedFileCont
162161 if err != nil {
163162 return nil , err
164163 }
165- results = append ( results , result )
164+ return [] * AnalyzeResult { result }, nil
166165 }
167166 if analyzer .Distribution != nil {
168167 isExcluded , err := isExcluded (analyzer .Distribution .Exclude )
@@ -176,7 +175,7 @@ func Analyze(analyzer *troubleshootv1beta1.Analyze, getFile getCollectedFileCont
176175 if err != nil {
177176 return nil , err
178177 }
179- results = append ( results , result )
178+ return [] * AnalyzeResult { result }, nil
180179 }
181180 if analyzer .NodeResources != nil {
182181 isExcluded , err := isExcluded (analyzer .NodeResources .Exclude )
@@ -190,7 +189,7 @@ func Analyze(analyzer *troubleshootv1beta1.Analyze, getFile getCollectedFileCont
190189 if err != nil {
191190 return nil , err
192191 }
193- results = append ( results , result )
192+ return [] * AnalyzeResult { result }, nil
194193 }
195194 if analyzer .TextAnalyze != nil {
196195 isExcluded , err := isExcluded (analyzer .TextAnalyze .Exclude )
@@ -204,7 +203,7 @@ func Analyze(analyzer *troubleshootv1beta1.Analyze, getFile getCollectedFileCont
204203 if err != nil {
205204 return nil , err
206205 }
207- results = append ( results , multiResult ... )
206+ return multiResult , nil
208207 }
209208 if analyzer .Postgres != nil {
210209 isExcluded , err := isExcluded (analyzer .Postgres .Exclude )
@@ -218,7 +217,7 @@ func Analyze(analyzer *troubleshootv1beta1.Analyze, getFile getCollectedFileCont
218217 if err != nil {
219218 return nil , err
220219 }
221- results = append ( results , result )
220+ return [] * AnalyzeResult { result }, nil
222221 }
223222 if analyzer .Mysql != nil {
224223 isExcluded , err := isExcluded (analyzer .Mysql .Exclude )
@@ -232,7 +231,7 @@ func Analyze(analyzer *troubleshootv1beta1.Analyze, getFile getCollectedFileCont
232231 if err != nil {
233232 return nil , err
234233 }
235- results = append ( results , result )
234+ return [] * AnalyzeResult { result }, nil
236235 }
237236 if analyzer .Redis != nil {
238237 isExcluded , err := isExcluded (analyzer .Redis .Exclude )
@@ -246,11 +245,8 @@ func Analyze(analyzer *troubleshootv1beta1.Analyze, getFile getCollectedFileCont
246245 if err != nil {
247246 return nil , err
248247 }
249- results = append ( results , result )
248+ return [] * AnalyzeResult { result }, nil
250249 }
250+ return nil , errors .New ("invalid analyzer" )
251251
252- if len (results ) == 0 {
253- return nil , errors .New ("invalid analyzer" )
254- }
255- return results , nil
256252}
0 commit comments