Skip to content

Commit 8f6619b

Browse files
committed
apiextensions: always sort structural schema violations, not only in condition
1 parent b9ccdd2 commit 8f6619b

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/validation.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package schema
1818

1919
import (
2020
"reflect"
21+
"sort"
2122

2223
"k8s.io/apimachinery/pkg/util/validation/field"
2324
)
@@ -62,6 +63,12 @@ func ValidateStructural(s *Structural, fldPath *field.Path) field.ErrorList {
6263
allErrs = append(allErrs, validateStructuralInvariants(s, rootLevel, fldPath)...)
6364
allErrs = append(allErrs, validateStructuralCompleteness(s, fldPath)...)
6465

66+
// sort error messages. Otherwise, the errors slice will change every time due to
67+
// maps in the types and randomized iteration.
68+
sort.Slice(allErrs, func(i, j int) bool {
69+
return allErrs[i].Error() < allErrs[j].Error()
70+
})
71+
6572
return allErrs
6673
}
6774

staging/src/k8s.io/apiextensions-apiserver/pkg/controller/nonstructuralschema/nonstructuralschema_controller.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package nonstructuralschema
1818

1919
import (
2020
"fmt"
21-
"sort"
2221
"time"
2322

2423
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -115,12 +114,6 @@ func calculateCondition(in *apiextensions.CustomResourceDefinition) *apiextensio
115114
return nil
116115
}
117116

118-
// sort error messages. Otherwise, the condition message will change every sync due to
119-
// randomized map iteration.
120-
sort.Slice(allErrs, func(i, j int) bool {
121-
return allErrs[i].Error() < allErrs[j].Error()
122-
})
123-
124117
cond.Status = apiextensions.ConditionTrue
125118
cond.Reason = "Violations"
126119
cond.Message = allErrs.ToAggregate().Error()

0 commit comments

Comments
 (0)