From cc24ec409746a855046c3fb154380604ee4801bd Mon Sep 17 00:00:00 2001 From: Evans Mungai Date: Thu, 23 Nov 2023 18:41:42 +0000 Subject: [PATCH] fix(support-bundle): default in-cluster collectors in host support bundle Ensure cluster-resources and cluster-info collectors are present only when a support bundle spec contains in-cluster collectors. --- cmd/troubleshoot/cli/run.go | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/cmd/troubleshoot/cli/run.go b/cmd/troubleshoot/cli/run.go index 89f471701..08a30abc3 100644 --- a/cmd/troubleshoot/cli/run.go +++ b/cmd/troubleshoot/cli/run.go @@ -311,18 +311,20 @@ func loadSpecs(ctx context.Context, args []string, client kubernetes.Interface) mainBundle.Spec.HostCollectors = append(mainBundle.Spec.HostCollectors, hc.Spec.Collectors...) } - // Ensure cluster info and cluster resources collectors are in the merged spec - // We need to add them here so when we --dry-run, these collectors are included. - // supportbundle.runCollectors duplicates this bit. We'll need to refactor it out later - // when its clearer what other code depends on this logic e.g KOTS - mainBundle.Spec.Collectors = collect.EnsureCollectorInList( - mainBundle.Spec.Collectors, - troubleshootv1beta2.Collect{ClusterInfo: &troubleshootv1beta2.ClusterInfo{}}, - ) - mainBundle.Spec.Collectors = collect.EnsureCollectorInList( - mainBundle.Spec.Collectors, - troubleshootv1beta2.Collect{ClusterResources: &troubleshootv1beta2.ClusterResources{}}, - ) + if len(mainBundle.Spec.Collectors) > 0 { + // If we have in-cluster collectors, ensure cluster info and cluster resources + // collectors are in the merged spec. We need to add them here so when we --dry-run, + // these collectors are included. supportbundle.runCollectors duplicates this bit. + // We'll need to refactor it out later when its clearer what other code depends on this logic e.g KOTS + mainBundle.Spec.Collectors = collect.EnsureCollectorInList( + mainBundle.Spec.Collectors, + troubleshootv1beta2.Collect{ClusterInfo: &troubleshootv1beta2.ClusterInfo{}}, + ) + mainBundle.Spec.Collectors = collect.EnsureCollectorInList( + mainBundle.Spec.Collectors, + troubleshootv1beta2.Collect{ClusterResources: &troubleshootv1beta2.ClusterResources{}}, + ) + } additionalRedactors := &troubleshootv1beta2.Redactor{ TypeMeta: metav1.TypeMeta{