@@ -55,7 +55,7 @@ func runTroubleshoot(v *viper.Viper, arg string) error {
5555 httpClient = http .DefaultClient
5656 }
5757
58- collectorContent , err := loadSpec (v , arg )
58+ collectorContent , err := loadSupportBundleSpec (v , arg )
5959 if err != nil {
6060 return errors .Wrap (err , "failed to load collector spec" )
6161 }
@@ -73,7 +73,7 @@ func runTroubleshoot(v *viper.Viper, arg string) error {
7373
7474 additionalRedactors := & troubleshootv1beta2.Redactor {}
7575 for idx , redactor := range v .GetStringSlice ("redactors" ) {
76- redactorContent , err := loadSpec (v , redactor )
76+ redactorContent , err := loadRedactorSpec (v , redactor )
7777 if err != nil {
7878 return errors .Wrapf (err , "failed to load redactor spec #%d" , idx )
7979 }
@@ -247,13 +247,12 @@ the %s Admin Console to begin analysis.`
247247 return nil
248248}
249249
250- func loadSpec (v * viper.Viper , arg string ) ([]byte , error ) {
251- var err error
250+ func loadSupportBundleSpec (v * viper.Viper , arg string ) ([]byte , error ) {
252251 if strings .HasPrefix (arg , "secret/" ) {
253252 // format secret/namespace-name/secret-name
254253 pathParts := strings .Split (arg , "/" )
255254 if len (pathParts ) != 3 {
256- return nil , errors .Errorf ("path %s must have 3 components" , arg )
255+ return nil , errors .Errorf ("secret path %s must have 3 components" , arg )
257256 }
258257
259258 spec , err := specs .LoadFromSecret (pathParts [1 ], pathParts [2 ], "support-bundle-spec" )
@@ -264,6 +263,43 @@ func loadSpec(v *viper.Viper, arg string) ([]byte, error) {
264263 return spec , nil
265264 }
266265
266+ return loadSpec (v , arg )
267+ }
268+
269+ func loadRedactorSpec (v * viper.Viper , arg string ) ([]byte , error ) {
270+ if strings .HasPrefix (arg , "configmap/" ) {
271+ // format configmap/namespace-name/configmap-name[/data-key]
272+ pathParts := strings .Split (arg , "/" )
273+ if len (pathParts ) > 4 {
274+ return nil , errors .Errorf ("configmap path %s must have at most 4 components" , arg )
275+ }
276+ if len (pathParts ) < 3 {
277+ return nil , errors .Errorf ("configmap path %s must have at least 3 components" , arg )
278+ }
279+
280+ dataKey := "redactor-spec"
281+ if len (pathParts ) == 4 {
282+ dataKey = pathParts [3 ]
283+ }
284+
285+ spec , err := specs .LoadFromConfigMap (pathParts [1 ], pathParts [2 ], dataKey )
286+ if err != nil {
287+ return nil , errors .Wrap (err , "failed to get spec from configmap" )
288+ }
289+
290+ return spec , nil
291+ }
292+
293+ spec , err := loadSpec (v , arg )
294+ if err != nil {
295+ return nil , errors .Wrap (err , "failed to load spec" )
296+ }
297+
298+ return spec , nil
299+ }
300+
301+ func loadSpec (v * viper.Viper , arg string ) ([]byte , error ) {
302+ var err error
267303 if _ , err = os .Stat (arg ); err == nil {
268304 b , err := ioutil .ReadFile (arg )
269305 if err != nil {
0 commit comments