From 349e363a410e1726714b07fb4f46008f1e3e0eaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20W=C3=B6hrl?= Date: Mon, 22 Jan 2024 15:49:08 +0100 Subject: [PATCH] feat: support all valid jsonpatches in validation webhook (#9476) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lukas Wöhrl Co-authored-by: Charles-Edouard Brétéché --- pkg/validation/policy/validate.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/validation/policy/validate.go b/pkg/validation/policy/validate.go index d78806894f..d8fac4b237 100644 --- a/pkg/validation/policy/validate.go +++ b/pkg/validation/policy/validate.go @@ -89,10 +89,12 @@ func validateJSONPatch(patch string, ruleIdx int) error { } for _, operation := range decodedPatch { op := operation.Kind() - if op != "add" && op != "remove" && op != "replace" { + requiresValue := op != "remove" && op != "move" && op != "copy" + validOperation := op == "add" || op == "remove" || op == "replace" || op == "move" || op == "copy" || op == "test" + if !validOperation { return fmt.Errorf("unexpected kind: spec.rules[%d]: %s", ruleIdx, op) } - if op != "remove" { + if requiresValue { if _, err := operation.ValueInterface(); err != nil { return fmt.Errorf("invalid value: spec.rules[%d]: %s", ruleIdx, err) }