Skip to content

Commit 0e2db5e

Browse files
committed
feat: add sort func for controller errors
added sort func to help make testing easy by having a consistent output for a list of errors Signed-off-by: ehila <ehila@redhat.com>
1 parent 5e8bc56 commit 0e2db5e

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

pkg/operator/configobserver/config_observer_controller.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ func (c ConfigObserver) sync(ctx context.Context, syncCtx factory.SyncContext) e
178178
if err := c.updateObservedConfig(ctx, syncCtx, existingConfig, mergedObservedConfig); err != nil {
179179
errs = []error{err}
180180
}
181+
182+
v1helpers.SortErrorsInLexicalOrder(errs)
183+
181184
configError := v1helpers.NewMultiLineAggregate(errs)
182185

183186
// update failing condition

pkg/operator/v1helpers/helpers.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,13 @@ func (agg aggregate) visit(f func(err error) bool) bool {
399399
return false
400400
}
401401

402+
// We sort errors to allow for consistent output for testing.
403+
func SortErrorsInLexicalOrder(errs []error) {
404+
sort.SliceStable(errs, func(i, j int) bool {
405+
return errs[i].Error() < errs[j].Error()
406+
})
407+
}
408+
402409
// MapToEnvVars converts a string-string map to a slice of corev1.EnvVar-s
403410
func MapToEnvVars(mapEnvVars map[string]string) []corev1.EnvVar {
404411
if mapEnvVars == nil {

0 commit comments

Comments
 (0)