@@ -179,18 +179,21 @@ func runCollectors(v *viper.Viper, collector troubleshootv1beta1.Collector, prog
179179 continue
180180 }
181181
182- collectorDir , err := parseAndSaveCollectorOutput (string (result ), bundlePath )
182+ newCollectorDirs , err := parseAndSaveCollectorOutput (string (result ), bundlePath )
183183 if err != nil {
184184 progressChan <- fmt .Errorf ("failed to parse collector spec %q: %v" , collector .GetDisplayName (), err )
185185 continue
186186 }
187187
188- if collectorDir == "" {
188+ if len ( newCollectorDirs ) == 0 {
189189 continue
190190 }
191191
192- progressChan <- collectorDir
193- collectorDirs = append (collectorDirs , collectorDir )
192+ // TODO: better progress....
193+ for _ , d := range newCollectorDirs {
194+ progressChan <- d
195+ }
196+ collectorDirs = append (collectorDirs , newCollectorDirs ... )
194197 }
195198
196199 tarGz := archiver.TarGz {
@@ -219,53 +222,58 @@ func runCollectors(v *viper.Viper, collector troubleshootv1beta1.Collector, prog
219222 return filename , nil
220223}
221224
222- func parseAndSaveCollectorOutput (output string , bundlePath string ) (string , error ) {
223- dir := ""
225+ func parseAndSaveCollectorOutput (output string , bundlePath string ) ([] string , error ) {
226+ rootDirs := make ( map [ string ] bool )
224227
225228 input := make (map [string ]interface {})
226229 if err := json .Unmarshal ([]byte (output ), & input ); err != nil {
227- return "" , errors .Wrap (err , "unmarshal output" )
230+ return nil , errors .Wrap (err , "unmarshal output" )
228231 }
229232
230233 for filename , maybeContents := range input {
231234 fileDir , fileName := filepath .Split (filename )
232235 outPath := filepath .Join (bundlePath , fileDir )
233- dir = outPath
236+ rootDirs [ outPath ] = true
234237
235238 if err := os .MkdirAll (outPath , 0777 ); err != nil {
236- return "" , errors .Wrap (err , "create output file" )
239+ return nil , errors .Wrap (err , "create output file" )
237240 }
238241
239242 switch maybeContents .(type ) {
240243 case string :
241244 decoded , err := base64 .StdEncoding .DecodeString (maybeContents .(string ))
242245 if err != nil {
243- return "" , errors .Wrap (err , "decode collector output" )
246+ return nil , errors .Wrap (err , "decode collector output" )
244247 }
245248
246249 if err := writeFile (filepath .Join (outPath , fileName ), decoded ); err != nil {
247- return "" , errors .Wrap (err , "write collector output" )
250+ return nil , errors .Wrap (err , "write collector output" )
248251 }
249252
250253 case map [string ]interface {}:
251254 for k , v := range maybeContents .(map [string ]interface {}) {
252255 s , _ := filepath .Split (filepath .Join (outPath , fileName , k ))
253256 if err := os .MkdirAll (s , 0777 ); err != nil {
254- return "" , errors .Wrap (err , "write output directories" )
257+ return nil , errors .Wrap (err , "write output directories" )
255258 }
256259
257260 decoded , err := base64 .StdEncoding .DecodeString (v .(string ))
258261 if err != nil {
259- return "" , errors .Wrap (err , "decode output" )
262+ return nil , errors .Wrap (err , "decode output" )
260263 }
261264 if err := writeFile (filepath .Join (outPath , fileName , k ), decoded ); err != nil {
262- return "" , errors .Wrap (err , "write output" )
265+ return nil , errors .Wrap (err , "write output" )
263266 }
264267 }
265268 }
266269 }
267270
268- return dir , nil
271+ dirs := make ([]string , 0 )
272+ for dir := range rootDirs {
273+ dirs = append (dirs , dir )
274+ }
275+
276+ return dirs , nil
269277}
270278
271279func uploadSupportBundle (r * troubleshootv1beta1.ResultRequest , archivePath string ) error {
0 commit comments