From b20a8e5321853a867a1160cb5eb74c8ff2da3ac8 Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Fri, 26 Aug 2022 11:16:07 +0100 Subject: [PATCH] Add example breakout point for collector merging Signed-off-by: Dan Jones --- .../v1beta2/supportbundle_interfaces.go | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/pkg/apis/troubleshoot/v1beta2/supportbundle_interfaces.go b/pkg/apis/troubleshoot/v1beta2/supportbundle_interfaces.go index bdaf111d..b852a6eb 100644 --- a/pkg/apis/troubleshoot/v1beta2/supportbundle_interfaces.go +++ b/pkg/apis/troubleshoot/v1beta2/supportbundle_interfaces.go @@ -1,9 +1,10 @@ package v1beta2 +// the intention with these appends is to swap them out at a later date with more specific handlers for merging the spec fields func (s *SupportBundle) ConcatSpec(bundle *SupportBundle) { - for _, v := range bundle.Spec.Collectors { - s.Spec.Collectors = append(s.Spec.Collectors, v) - } + + s.Spec.MergeCollectors(&bundle.Spec) + for _, v := range bundle.Spec.AfterCollection { s.Spec.AfterCollection = append(s.Spec.AfterCollection, v) } @@ -17,3 +18,27 @@ func (s *SupportBundle) ConcatSpec(bundle *SupportBundle) { s.Spec.Analyzers = append(s.Spec.Analyzers, v) } } + +func (s *SupportBundleSpec) MergeCollectors(spec *SupportBundleSpec) { + for _,c := range spec.Collectors { + + if c.ClusterInfo != nil { + // we only actually want one of these so skip if there's already one + y := 0 + // we want to move away from checking for specific collectors in favor of allowing collectors to expose their own merge method + for _,v := range s.Collectors{ + if v.ClusterInfo != nil { + y = 1 + } + } + if y != 1 { + s.Collectors = append(s.Collectors, c) + } + continue + } + + s.Collectors = append(s.Collectors, c) + + } +} +