github.com/cilium/statedb@v0.3.2/reconciler/helpers.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package reconciler 5 6 import ( 7 "errors" 8 "fmt" 9 "slices" 10 ) 11 12 var closedWatchChannel = func() <-chan struct{} { 13 ch := make(chan struct{}) 14 close(ch) 15 return ch 16 }() 17 18 const ( 19 // maxJoinedErrors limits the number of errors to join and return from 20 // failed reconciliation. This avoids constructing a massive error for 21 // health status when many operations fail at once. 22 maxJoinedErrors = 10 23 ) 24 25 func omittedError(n int) error { 26 return fmt.Errorf("%d further errors omitted", n) 27 } 28 29 func joinErrors(errs []error) error { 30 if len(errs) > maxJoinedErrors { 31 errs = append(slices.Clone(errs)[:maxJoinedErrors], omittedError(len(errs)-maxJoinedErrors)) 32 } 33 return errors.Join(errs...) 34 }