diff --git a/pkg/supportbundle/spec.go b/pkg/supportbundle/spec.go index 17a2782343..e6f544d1f5 100644 --- a/pkg/supportbundle/spec.go +++ b/pkg/supportbundle/spec.go @@ -12,6 +12,7 @@ import ( "path/filepath" "reflect" "regexp" + "slices" "strings" "time" @@ -643,6 +644,20 @@ func deduplicatedCollectors(supportBundle *troubleshootv1beta2.SupportBundle) *t if reflect.DeepEqual(next.Spec.Collectors[i].ClusterResources.Namespaces, next.Spec.Collectors[j].ClusterResources.Namespaces) { next.Spec.Collectors = append(next.Spec.Collectors[:j], next.Spec.Collectors[j+1:]...) j-- + } else { + // if the next spec use all namespaces cluster resources collector, then overwrite the default one + if len(next.Spec.Collectors[j].ClusterResources.Namespaces) == 0 { + next.Spec.Collectors[i].ClusterResources.Namespaces = []string{} + } else { + // if the namespaces are different, add the missing namespaces to the default ClusterResources collector + for _, ns := range next.Spec.Collectors[j].ClusterResources.Namespaces { + if !slices.Contains(next.Spec.Collectors[i].ClusterResources.Namespaces, ns) { + next.Spec.Collectors[i].ClusterResources.Namespaces = append(next.Spec.Collectors[i].ClusterResources.Namespaces, ns) + } + } + } + next.Spec.Collectors = append(next.Spec.Collectors[:j], next.Spec.Collectors[j+1:]...) + j-- } } else if next.Spec.Collectors[i].ClusterInfo != nil && next.Spec.Collectors[j].ClusterInfo != nil { next.Spec.Collectors = append(next.Spec.Collectors[:j], next.Spec.Collectors[j+1:]...)