From 2eff4f2f3ea77b2cf9f1f527079a71933189c085 Mon Sep 17 00:00:00 2001 From: NoSkillGirl Date: Sun, 1 Aug 2021 16:27:47 +0530 Subject: [PATCH] added backward compatibility Signed-off-by: NoSkillGirl --- pkg/kyverno/common/common.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pkg/kyverno/common/common.go b/pkg/kyverno/common/common.go index a08af77a41..948ad1fba8 100644 --- a/pkg/kyverno/common/common.go +++ b/pkg/kyverno/common/common.go @@ -387,6 +387,7 @@ func GetVariable(variablesString, valuesFile string, fs billy.Filesystem, isGit valuesMapRule := make(map[string]map[string]Rule) namespaceSelectorMap := make(map[string]map[string]string) variables := make(map[string]string) + reqObjVars := "" var yamlFile []byte var err error @@ -395,7 +396,10 @@ func GetVariable(variablesString, valuesFile string, fs billy.Filesystem, isGit for _, kvpair := range kvpairs { kvs := strings.Split(strings.Trim(kvpair, " "), "=") if strings.Contains(kvs[0], "request.object") { - return variables, valuesMapResource, namespaceSelectorMap, sanitizederror.NewWithError("variable request.object.* is handled by kyverno. please do not pass value for request.object variables ", err) + if !strings.Contains(reqObjVars, kvs[0]) { + reqObjVars = reqObjVars + "," + kvs[0] + } + continue } variables[strings.Trim(kvs[0], " ")] = strings.Trim(kvs[1], " ") @@ -432,7 +436,11 @@ func GetVariable(variablesString, valuesFile string, fs billy.Filesystem, isGit for _, r := range p.Resources { for variableInFile := range r.Values { if strings.Contains(variableInFile, "request.object") { - return variables, valuesMapResource, namespaceSelectorMap, sanitizederror.NewWithError("variable request.object.* is handled by kyverno. please do not pass value for request.object variables ", err) + if !strings.Contains(reqObjVars, variableInFile) { + reqObjVars = reqObjVars + "," + variableInFile + } + delete(r.Values, variableInFile) + continue } } resourceMap[r.Name] = r @@ -453,6 +461,10 @@ func GetVariable(variablesString, valuesFile string, fs billy.Filesystem, isGit } } + if reqObjVars != "" { + fmt.Printf(("\nvariable request.object.* is handled by kyverno. ignoring value of variables: `%v` passed by the user.\n"), reqObjVars) + } + storePolices := make([]store.Policy, 0) for policyName, ruleMap := range valuesMapRule { storeRules := make([]store.Rule, 0)