From bf21fbf6736a06f7b10066ad8cb4e54685bcf31d Mon Sep 17 00:00:00 2001 From: Marcus Vaal Date: Tue, 8 Aug 2023 02:03:59 -0500 Subject: [PATCH] fix: Fixed issue with AddVariable that prevented certain variables (#7981) When using a label or annotation with quoted dots, AddVariable was splitting inside the quote causing it to be improperly parsed and replaced Signed-off-by: mvaal --- pkg/engine/context/context.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/engine/context/context.go b/pkg/engine/context/context.go index 92b64abbf8..53230059a7 100644 --- a/pkg/engine/context/context.go +++ b/pkg/engine/context/context.go @@ -1,6 +1,7 @@ package context import ( + "encoding/csv" "encoding/json" "fmt" "strings" @@ -146,7 +147,13 @@ func (ctx *context) AddRequest(request admissionv1.AdmissionRequest) error { } func (ctx *context) AddVariable(key string, value interface{}) error { - return addToContext(ctx, value, strings.Split(key, ".")...) + reader := csv.NewReader(strings.NewReader(key)) + reader.Comma = '.' + if fields, err := reader.Read(); err != nil { + return err + } else { + return addToContext(ctx, value, fields...) + } } func (ctx *context) AddContextEntry(name string, dataRaw []byte) error {