mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Merge pull request #77726 from sttts/sttts-structural-schema-sort-errors
apiextensions: always sort structural schema violations, not only in condition
This commit is contained in:
commit
8fecbd8eca
@ -18,6 +18,7 @@ package schema
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"sort"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
"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, validateStructuralInvariants(s, rootLevel, fldPath)...)
|
||||||
allErrs = append(allErrs, validateStructuralCompleteness(s, 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
|
return allErrs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,6 @@ package nonstructuralschema
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
@ -115,12 +114,6 @@ func calculateCondition(in *apiextensions.CustomResourceDefinition) *apiextensio
|
|||||||
return nil
|
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.Status = apiextensions.ConditionTrue
|
||||||
cond.Reason = "Violations"
|
cond.Reason = "Violations"
|
||||||
cond.Message = allErrs.ToAggregate().Error()
|
cond.Message = allErrs.ToAggregate().Error()
|
||||||
|
Loading…
Reference in New Issue
Block a user