apiextensions: always sort structural schema violations, not only in condition

This commit is contained in:
Dr. Stefan Schimanski 2019-05-10 09:37:54 +02:00
parent b9ccdd2824
commit 8f6619bc21
2 changed files with 7 additions and 7 deletions

View File

@ -18,6 +18,7 @@ package schema
import (
"reflect"
"sort"
"k8s.io/apimachinery/pkg/util/validation/field"
)
@ -62,6 +63,12 @@ func ValidateStructural(s *Structural, fldPath *field.Path) field.ErrorList {
allErrs = append(allErrs, validateStructuralInvariants(s, rootLevel, fldPath)...)
allErrs = append(allErrs, validateStructuralCompleteness(s, fldPath)...)
// sort error messages. Otherwise, the errors slice will change every time due to
// maps in the types and randomized iteration.
sort.Slice(allErrs, func(i, j int) bool {
return allErrs[i].Error() < allErrs[j].Error()
})
return allErrs
}

View File

@ -18,7 +18,6 @@ package nonstructuralschema
import (
"fmt"
"sort"
"time"
apierrors "k8s.io/apimachinery/pkg/api/errors"
@ -115,12 +114,6 @@ func calculateCondition(in *apiextensions.CustomResourceDefinition) *apiextensio
return nil
}
// sort error messages. Otherwise, the condition message will change every sync due to
// randomized map iteration.
sort.Slice(allErrs, func(i, j int) bool {
return allErrs[i].Error() < allErrs[j].Error()
})
cond.Status = apiextensions.ConditionTrue
cond.Reason = "Violations"
cond.Message = allErrs.ToAggregate().Error()