@@ -31,7 +31,7 @@ import (
3131 "k8s.io/client-go/rest"
3232)
3333
34- func runTroubleshoot (v * viper.Viper , arg string ) error {
34+ func runTroubleshoot (v * viper.Viper , arg [] string ) error {
3535 interactive := v .GetBool ("interactive" ) && isatty .IsTerminal (os .Stdout .Fd ())
3636
3737 if interactive {
@@ -68,51 +68,58 @@ func runTroubleshoot(v *viper.Viper, arg string) error {
6868 })
6969 }
7070
71- collectorContent , err := supportbundle .LoadSupportBundleSpec (arg )
72- if err != nil {
73- return errors .Wrap (err , "failed to load collector spec" )
74- }
75-
76- multidocs := strings .Split (string (collectorContent ), "\n ---\n " )
77-
78- // we support both raw collector kinds and supportbundle kinds here
79- supportBundle , err := supportbundle .ParseSupportBundleFromDoc ([]byte (multidocs [0 ]))
80- if err != nil {
81- return errors .Wrap (err , "failed to parse collector" )
82- }
71+ var mainBundle * troubleshootv1beta2.SupportBundle
8372
8473 troubleshootclientsetscheme .AddToScheme (scheme .Scheme )
8574 decode := scheme .Codecs .UniversalDeserializer ().Decode
86-
8775 additionalRedactors := & troubleshootv1beta2.Redactor {}
88- for idx , redactor := range v .GetStringSlice ("redactors" ) {
89- redactorObj , err := supportbundle .GetRedactorFromURI (redactor )
76+ for i , v := range arg {
77+
78+ collectorContent , err := supportbundle .LoadSupportBundleSpec (v )
9079 if err != nil {
91- return errors .Wrapf (err , "failed to get redactor spec %s, #%d" , redactor , idx )
80+ return errors .Wrap (err , "failed to load collector spec" )
9281 }
93-
94- if redactorObj != nil {
95- additionalRedactors .Spec .Redactors = append (additionalRedactors .Spec .Redactors , redactorObj .Spec .Redactors ... )
82+ multidocs := strings .Split (string (collectorContent ), "\n ---\n " )
83+ supportBundle , err := supportbundle .ParseSupportBundleFromDoc ([]byte (multidocs [0 ]))
84+ if err != nil {
85+ return errors .Wrap (err , "failed to parse collector" )
9686 }
97- }
9887
99- for i , additionalDoc := range multidocs {
10088 if i == 0 {
101- continue
89+ mainBundle = supportBundle
90+ } else {
91+ mainBundle = supportbundle .ConcatSpec (mainBundle , supportBundle )
10292 }
103- additionalDoc , err := docrewrite .ConvertToV1Beta2 ([]byte (additionalDoc ))
104- if err != nil {
105- return errors .Wrap (err , "failed to convert to v1beta2" )
93+
94+ for i , additionalDoc := range multidocs {
95+ if i == 0 {
96+ continue
97+ }
98+ additionalDoc , err := docrewrite .ConvertToV1Beta2 ([]byte (additionalDoc ))
99+ if err != nil {
100+ return errors .Wrap (err , "failed to convert to v1beta2" )
101+ }
102+ obj , _ , err := decode (additionalDoc , nil , nil )
103+ if err != nil {
104+ return errors .Wrapf (err , "failed to parse additional doc %d" , i )
105+ }
106+ multidocRedactors , ok := obj .(* troubleshootv1beta2.Redactor )
107+ if ! ok {
108+ continue
109+ }
110+ additionalRedactors .Spec .Redactors = append (additionalRedactors .Spec .Redactors , multidocRedactors .Spec .Redactors ... )
106111 }
107- obj , _ , err := decode (additionalDoc , nil , nil )
112+ }
113+
114+ for idx , redactor := range v .GetStringSlice ("redactors" ) {
115+ redactorObj , err := supportbundle .GetRedactorFromURI (redactor )
108116 if err != nil {
109- return errors .Wrapf (err , "failed to parse additional doc % d" , i )
117+ return errors .Wrapf (err , "failed to get redactor spec %s, #% d" , redactor , idx )
110118 }
111- multidocRedactors , ok := obj .( * troubleshootv1beta2. Redactor )
112- if ! ok {
113- continue
119+
120+ if redactorObj != nil {
121+ additionalRedactors . Spec . Redactors = append ( additionalRedactors . Spec . Redactors , redactorObj . Spec . Redactors ... )
114122 }
115- additionalRedactors .Spec .Redactors = append (additionalRedactors .Spec .Redactors , multidocRedactors .Spec .Redactors ... )
116123 }
117124
118125 var collectorCB func (chan interface {}, string )
@@ -193,7 +200,7 @@ func runTroubleshoot(v *viper.Viper, arg string) error {
193200 c .Println (fmt .Sprintf ("\r %s\r " , cursor .ClearEntireLine ()))
194201 }
195202
196- response , err := supportbundle .CollectSupportBundleFromSpec (& supportBundle .Spec , additionalRedactors , createOpts )
203+ response , err := supportbundle .CollectSupportBundleFromSpec (& mainBundle .Spec , additionalRedactors , createOpts )
197204 if err != nil {
198205 return errors .Wrap (err , "failed to run collect and analyze process" )
199206 }
@@ -202,7 +209,7 @@ func runTroubleshoot(v *viper.Viper, arg string) error {
202209 close (finishedCh ) // this removes the spinner
203210 isFinishedChClosed = true
204211
205- if err := showInteractiveResults (supportBundle .Name , response .AnalyzerResults ); err != nil {
212+ if err := showInteractiveResults (mainBundle .Name , response .AnalyzerResults ); err != nil {
206213 interactive = false
207214 }
208215 } else {
@@ -211,7 +218,7 @@ func runTroubleshoot(v *viper.Viper, arg string) error {
211218 }
212219
213220 if ! response .FileUploaded {
214- if appName := supportBundle .Labels ["applicationName" ]; appName != "" {
221+ if appName := mainBundle .Labels ["applicationName" ]; appName != "" {
215222 f := `A support bundle for %s has been created in this directory
216223named %s. Please upload it on the Troubleshoot page of
217224the %s Admin Console to begin analysis.`
0 commit comments