mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-30 19:35:06 +00:00
fix: make reponse order predictable (#5079)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> make response order predictable
This commit is contained in:
parent
fa178ebd82
commit
e5b9af44e7
2 changed files with 19 additions and 2 deletions
|
@ -2,6 +2,7 @@ package validate
|
|||
|
||||
import (
|
||||
"container/list"
|
||||
"sort"
|
||||
|
||||
commonAnchors "github.com/kyverno/kyverno/pkg/engine/anchor"
|
||||
)
|
||||
|
@ -34,7 +35,15 @@ func hasNestedAnchors(pattern interface{}) bool {
|
|||
// getSortedNestedAnchorResource - sorts anchors key
|
||||
func getSortedNestedAnchorResource(resources map[string]interface{}) *list.List {
|
||||
sortedResourceKeys := list.New()
|
||||
for k, v := range resources {
|
||||
|
||||
keys := make([]string, 0, len(resources))
|
||||
for k := range resources {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
|
||||
for _, k := range keys {
|
||||
v := resources[k]
|
||||
if commonAnchors.IsGlobalAnchor(k) {
|
||||
sortedResourceKeys.PushFront(k)
|
||||
continue
|
||||
|
|
|
@ -2,6 +2,7 @@ package validate
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strconv"
|
||||
|
||||
"github.com/go-logr/logr"
|
||||
|
@ -121,8 +122,15 @@ func validateMap(log logr.Logger, resourceMap, patternMap map[string]interface{}
|
|||
// Phase 2 : Evaluate non-anchors
|
||||
anchors, resources := anchor.GetAnchorsResourcesFromMap(patternMap)
|
||||
|
||||
keys := make([]string, 0, len(anchors))
|
||||
for k := range anchors {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
|
||||
// Evaluate anchors
|
||||
for key, patternElement := range anchors {
|
||||
for _, key := range keys {
|
||||
patternElement := anchors[key]
|
||||
// get handler for each pattern in the pattern
|
||||
// - Conditional
|
||||
// - Existence
|
||||
|
|
Loading…
Add table
Reference in a new issue