Merge pull request #77726 from sttts/sttts-structural-schema-sort-errors

apiextensions: always sort structural schema violations, not only in condition
k3s-v1.15.3
Kubernetes Prow Robot 2019-05-10 02:17:59 -07:00 committed by GitHub
commit 8fecbd8eca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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()