From 74457306de7f2e6b3e8b50d6157425962c6ccdc5 Mon Sep 17 00:00:00 2001 From: Dexter Yan Date: Thu, 21 Nov 2024 19:21:40 +1300 Subject: [PATCH] feat(support-bundle): allow cluster resource to be overwrite by different spec or update namespace --- pkg/supportbundle/spec.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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:]...)