Add example breakout point for collector merging

Signed-off-by: Dan Jones <danj@replicated.com>
This commit is contained in:
Dan Jones
2022-08-26 11:16:07 +01:00
parent f5652df9da
commit b20a8e5321

View File

@@ -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)
}
}