Skip to content

Commit

Permalink
Add example breakout point for collector merging
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Jones <danj@replicated.com>
  • Loading branch information
danj-replicated committed Aug 26, 2022
1 parent f5652df commit b20a8e5
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions 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)
}
Expand All @@ -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)

}
}

0 comments on commit b20a8e5

Please sign in to comment.