@@ -233,7 +233,7 @@ the %s Admin Console to begin analysis.`
233233}
234234
235235// loadSupportBundleSpecsFromURIs loads support bundle specs from URIs
236- func loadSupportBundleSpecsFromURIs (ctx context.Context , kinds * loader.TroubleshootKinds ) ( * loader. TroubleshootKinds , error ) {
236+ func loadSupportBundleSpecsFromURIs (ctx context.Context , kinds * loader.TroubleshootKinds ) error {
237237 remoteRawSpecs := []string {}
238238 for _ , s := range kinds .SupportBundlesV1Beta2 {
239239 if s .Spec .Uri != "" && util .IsURL (s .Spec .Uri ) {
@@ -252,12 +252,18 @@ func loadSupportBundleSpecsFromURIs(ctx context.Context, kinds *loader.Troublesh
252252 }
253253
254254 if len (remoteRawSpecs ) == 0 {
255- return kinds , nil
255+ return nil
256256 }
257257
258- return loader .LoadSpecs (ctx , loader.LoadOptions {
258+ moreKinds , err := loader .LoadSpecs (ctx , loader.LoadOptions {
259259 RawSpecs : remoteRawSpecs ,
260260 })
261+ if err != nil {
262+ return err
263+ }
264+
265+ kinds .Add (moreKinds )
266+ return nil
261267}
262268
263269func loadSpecs (ctx context.Context , args []string , client kubernetes.Interface ) (* troubleshootv1beta2.SupportBundle , * troubleshootv1beta2.Redactor , error ) {
@@ -270,11 +276,9 @@ func loadSpecs(ctx context.Context, args []string, client kubernetes.Interface)
270276
271277 // Load additional specs from support bundle URIs
272278 if ! viper .GetBool ("no-uri" ) {
273- moreKinds , err := loadSupportBundleSpecsFromURIs (ctx , kinds )
279+ err := loadSupportBundleSpecsFromURIs (ctx , kinds )
274280 if err != nil {
275281 klog .Warningf ("unable to load support bundles from URIs: %v" , err )
276- } else {
277- kinds .Add (moreKinds )
278282 }
279283 }
280284
@@ -304,25 +308,27 @@ func loadSpecs(ctx context.Context, args []string, client kubernetes.Interface)
304308 }
305309
306310 for _ , c := range kinds .CollectorsV1Beta2 {
307- mainBundle .Spec .Collectors = append (mainBundle .Spec .Collectors , c .Spec .Collectors ... )
311+ mainBundle .Spec .Collectors = util . Append (mainBundle .Spec .Collectors , c .Spec .Collectors )
308312 }
309313
310314 for _ , hc := range kinds .HostCollectorsV1Beta2 {
311- mainBundle .Spec .HostCollectors = append (mainBundle .Spec .HostCollectors , hc .Spec .Collectors ... )
315+ mainBundle .Spec .HostCollectors = util . Append (mainBundle .Spec .HostCollectors , hc .Spec .Collectors )
312316 }
313317
314- // Ensure cluster info and cluster resources collectors are in the merged spec
315- // We need to add them here so when we --dry-run, these collectors are included.
316- // supportbundle.runCollectors duplicates this bit. We'll need to refactor it out later
317- // when its clearer what other code depends on this logic e.g KOTS
318- mainBundle .Spec .Collectors = collect .EnsureCollectorInList (
319- mainBundle .Spec .Collectors ,
320- troubleshootv1beta2.Collect {ClusterInfo : & troubleshootv1beta2.ClusterInfo {}},
321- )
322- mainBundle .Spec .Collectors = collect .EnsureCollectorInList (
323- mainBundle .Spec .Collectors ,
324- troubleshootv1beta2.Collect {ClusterResources : & troubleshootv1beta2.ClusterResources {}},
325- )
318+ if mainBundle .Spec .Collectors != nil {
319+ // If we have in-cluster collectors, ensure cluster info and cluster resources
320+ // collectors are in the merged spec. We need to add them here so when we --dry-run,
321+ // these collectors are included. supportbundle.runCollectors duplicates this bit.
322+ // We'll need to refactor it out later when its clearer what other code depends on this logic e.g KOTS
323+ mainBundle .Spec .Collectors = collect .EnsureCollectorInList (
324+ mainBundle .Spec .Collectors ,
325+ troubleshootv1beta2.Collect {ClusterInfo : & troubleshootv1beta2.ClusterInfo {}},
326+ )
327+ mainBundle .Spec .Collectors = collect .EnsureCollectorInList (
328+ mainBundle .Spec .Collectors ,
329+ troubleshootv1beta2.Collect {ClusterResources : & troubleshootv1beta2.ClusterResources {}},
330+ )
331+ }
326332
327333 additionalRedactors := & troubleshootv1beta2.Redactor {
328334 TypeMeta : metav1.TypeMeta {
@@ -334,7 +340,7 @@ func loadSpecs(ctx context.Context, args []string, client kubernetes.Interface)
334340 },
335341 }
336342 for _ , r := range kinds .RedactorsV1Beta2 {
337- additionalRedactors .Spec .Redactors = append (additionalRedactors .Spec .Redactors , r .Spec .Redactors ... )
343+ additionalRedactors .Spec .Redactors = util . Append (additionalRedactors .Spec .Redactors , r .Spec .Redactors )
338344 }
339345
340346 return mainBundle , additionalRedactors , nil
0 commit comments