diff --git a/pkg/supportbundle/execute.go b/pkg/supportbundle/execute.go index cb0f624fca..e2d07c21cd 100644 --- a/pkg/supportbundle/execute.go +++ b/pkg/supportbundle/execute.go @@ -171,11 +171,9 @@ func executeSupportBundleCollectRoutine(bundle *types.SupportBundle, progressCha Namespace: "", ProgressChan: progressChan, Redact: true, - RunHostCollectorsInPod: true, // always run host collectors in pod from KOTS regardless of the spec value } logger.Infof("Executing Collection go routine for support bundle ID: %s", bundle.ID) - logger.Infof("Always run host collectors in pod: %t", opts.RunHostCollectorsInPod) go func() { defer close(progressChan) diff --git a/pkg/supportbundle/spec.go b/pkg/supportbundle/spec.go index af00f1fefa..17a2782343 100644 --- a/pkg/supportbundle/spec.go +++ b/pkg/supportbundle/spec.go @@ -159,15 +159,11 @@ func mergeSupportBundleSpecs(builtBundles map[string]*troubleshootv1beta2.Suppor mergedBundle.Spec.Collectors = append(mergedBundle.Spec.Collectors, builtBundle.Spec.Collectors...) mergedBundle.Spec.Analyzers = append(mergedBundle.Spec.Analyzers, builtBundle.Spec.Analyzers...) mergedBundle.Spec.AfterCollection = append(mergedBundle.Spec.AfterCollection, builtBundle.Spec.AfterCollection...) - mergedBundle.Spec.HostCollectors = append(mergedBundle.Spec.HostCollectors, builtBundle.Spec.HostCollectors...) - mergedBundle.Spec.HostAnalyzers = append(mergedBundle.Spec.HostAnalyzers, builtBundle.Spec.HostAnalyzers...) } - mergedBundle.Spec.Collectors = Dedup(mergedBundle.Spec.Collectors) - mergedBundle.Spec.Analyzers = Dedup(mergedBundle.Spec.Analyzers) - mergedBundle.Spec.AfterCollection = Dedup(mergedBundle.Spec.AfterCollection) - mergedBundle.Spec.HostCollectors = Dedup(mergedBundle.Spec.HostCollectors) - mergedBundle.Spec.HostAnalyzers = Dedup(mergedBundle.Spec.HostAnalyzers) + mergedBundle = deduplicatedCollectors(mergedBundle) + mergedBundle = deduplicatedAnalyzers(mergedBundle) + mergedBundle = deduplicatedAfterCollection(mergedBundle) return mergedBundle } @@ -465,15 +461,11 @@ func addDiscoveredSpecs( supportBundle.Spec.Collectors = append(supportBundle.Spec.Collectors, sbObject.Spec.Collectors...) supportBundle.Spec.Analyzers = append(supportBundle.Spec.Analyzers, sbObject.Spec.Analyzers...) - supportBundle.Spec.HostCollectors = append(supportBundle.Spec.HostCollectors, sbObject.Spec.HostCollectors...) - supportBundle.Spec.HostAnalyzers = append(supportBundle.Spec.HostAnalyzers, sbObject.Spec.HostAnalyzers...) } - // remove duplicated specs if there are multiple support bundle upstream spec - supportBundle.Spec.Collectors = Dedup(supportBundle.Spec.Collectors) - supportBundle.Spec.Analyzers = Dedup(supportBundle.Spec.Analyzers) - supportBundle.Spec.HostCollectors = Dedup(supportBundle.Spec.HostCollectors) - supportBundle.Spec.HostAnalyzers = Dedup(supportBundle.Spec.HostAnalyzers) + // remove duplicated collectors and analyzers if there are multiple support bundle upstream spec + supportBundle = deduplicatedCollectors(supportBundle) + supportBundle = deduplicatedAnalyzers(supportBundle) return supportBundle } @@ -1253,26 +1245,3 @@ func removeKurlAnalyzers(analyzers []*troubleshootv1beta2.Analyze) []*troublesho return analyze } - -func Dedup[T any](objs []T) []T { - seen := make(map[string]bool) - out := []T{} - - if len(objs) == 0 { - return objs - } - - for _, o := range objs { - data, err := json.Marshal(o) - if err != nil { - out = append(out, o) - continue - } - key := string(data) - if _, ok := seen[key]; !ok { - out = append(out, o) - seen[key] = true - } - } - return out -} diff --git a/pkg/supportbundle/spec_test.go b/pkg/supportbundle/spec_test.go index 0ca623046c..89918af8fb 100644 --- a/pkg/supportbundle/spec_test.go +++ b/pkg/supportbundle/spec_test.go @@ -769,80 +769,3 @@ func createNamespaces(t *testing.T, clientset kubernetes.Interface, namespaces . require.NoError(t, err) } } - -func Test_mergeSupportBundleSpecs(t *testing.T) { - testBundle := &troubleshootv1beta2.SupportBundle{ - Spec: troubleshootv1beta2.SupportBundleSpec{ - Collectors: []*troubleshootv1beta2.Collect{ - { - ClusterResources: &troubleshootv1beta2.ClusterResources{ - CollectorMeta: troubleshootv1beta2.CollectorMeta{CollectorName: "first"}, - }, - }, - { - ClusterResources: &troubleshootv1beta2.ClusterResources{ - CollectorMeta: troubleshootv1beta2.CollectorMeta{CollectorName: "first"}, - }, - }, - { - ClusterResources: &troubleshootv1beta2.ClusterResources{}, - }, - }, - Analyzers: []*troubleshootv1beta2.Analyze{ - { - ClusterVersion: &troubleshootv1beta2.ClusterVersion{ - AnalyzeMeta: troubleshootv1beta2.AnalyzeMeta{CheckName: "first"}, - }, - }, - { - ClusterVersion: &troubleshootv1beta2.ClusterVersion{ - AnalyzeMeta: troubleshootv1beta2.AnalyzeMeta{CheckName: "first"}, - }, - }, - }, - AfterCollection: []*troubleshootv1beta2.AfterCollection{}, - HostCollectors: []*troubleshootv1beta2.HostCollect{ - { - CPU: &troubleshootv1beta2.CPU{}, - Memory: &troubleshootv1beta2.Memory{ - HostCollectorMeta: troubleshootv1beta2.HostCollectorMeta{CollectorName: "first"}, - }, - }, - { - CPU: &troubleshootv1beta2.CPU{}, - Memory: &troubleshootv1beta2.Memory{ - HostCollectorMeta: troubleshootv1beta2.HostCollectorMeta{CollectorName: "first"}, - }, - }, - { - CPU: &troubleshootv1beta2.CPU{}, - Memory: &troubleshootv1beta2.Memory{ - HostCollectorMeta: troubleshootv1beta2.HostCollectorMeta{CollectorName: "second"}, - }, - }, - }, - HostAnalyzers: []*troubleshootv1beta2.HostAnalyze{ - { - CPU: &troubleshootv1beta2.CPUAnalyze{ - AnalyzeMeta: troubleshootv1beta2.AnalyzeMeta{CheckName: "first"}, - }, - }, - { - CPU: &troubleshootv1beta2.CPUAnalyze{ - AnalyzeMeta: troubleshootv1beta2.AnalyzeMeta{CheckName: "first"}, - }, - }, - }, - }, - } - - builtBundles := map[string]*troubleshootv1beta2.SupportBundle{ - "first": testBundle, - } - merged := mergeSupportBundleSpecs(builtBundles) - - assert.Equal(t, 2, len(merged.Spec.Collectors)) - assert.Equal(t, 1, len(merged.Spec.Analyzers)) - assert.Equal(t, 2, len(merged.Spec.HostCollectors)) - assert.Equal(t, 1, len(merged.Spec.HostAnalyzers)) -} diff --git a/pkg/supportbundle/supportbundle.go b/pkg/supportbundle/supportbundle.go index 3dace009f5..0584fe1278 100644 --- a/pkg/supportbundle/supportbundle.go +++ b/pkg/supportbundle/supportbundle.go @@ -155,7 +155,7 @@ func CreateSupportBundleDependencies(app *apptypes.App, sequence int64, opts typ URI: GetSpecURI(app.GetSlug()), RedactURIs: redactURIs, Progress: types.SupportBundleProgress{ - CollectorCount: len(supportBundle.Spec.Collectors) + len(supportBundle.Spec.HostCollectors), + CollectorCount: len(supportBundle.Spec.Collectors), }, }