1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-05 15:37:19 +00:00

Merge pull request #2222 from NoSkillGirl/2180_backwards_compatibility

Added backward compatibility | Resolving variables from the resource passed | CLI
This commit is contained in:
Pooja Singh 2021-08-01 23:33:40 +05:30 committed by GitHub
commit 3dd53c6ad2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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)