1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-06 07:57:07 +00:00

removing context variables from variablesString

Signed-off-by: NoSkillGirl <singhpooja240393@gmail.com>
This commit is contained in:
NoSkillGirl 2021-08-02 16:45:54 +05:30
parent 05234d94e2
commit 15a63c109d

View file

@ -240,7 +240,7 @@ func applyCommandHelper(resourcePaths []string, cluster bool, policyReport bool,
} }
if variablesString != "" { if variablesString != "" {
setInStoreContext(mutatedPolicies, variables) variables = setInStoreContext(mutatedPolicies, variables)
} }
msgPolicies := "1 policy" msgPolicies := "1 policy"
@ -421,7 +421,7 @@ func createFileOrFolder(mutateLogPath string, mutateLogPathIsDir bool) error {
return nil return nil
} }
func setInStoreContext(mutatedPolicies []*v1.ClusterPolicy, variables map[string]string) { func setInStoreContext(mutatedPolicies []*v1.ClusterPolicy, variables map[string]string) map[string]string {
storePolices := make([]store.Policy, 0) storePolices := make([]store.Policy, 0)
for _, policy := range mutatedPolicies { for _, policy := range mutatedPolicies {
storeRules := make([]store.Rule, 0) storeRules := make([]store.Rule, 0)
@ -432,6 +432,7 @@ func setInStoreContext(mutatedPolicies []*v1.ClusterPolicy, variables map[string
for k, v := range variables { for k, v := range variables {
if strings.HasPrefix(k, contextVar.Name) { if strings.HasPrefix(k, contextVar.Name) {
contextVal[k] = v contextVal[k] = v
delete(variables, k)
} }
} }
} }
@ -439,7 +440,6 @@ func setInStoreContext(mutatedPolicies []*v1.ClusterPolicy, variables map[string
Name: rule.Name, Name: rule.Name,
Values: contextVal, Values: contextVal,
}) })
} }
} }
storePolices = append(storePolices, store.Policy{ storePolices = append(storePolices, store.Policy{
@ -451,4 +451,6 @@ func setInStoreContext(mutatedPolicies []*v1.ClusterPolicy, variables map[string
store.SetContext(store.Context{ store.SetContext(store.Context{
Policies: storePolices, Policies: storePolices,
}) })
return variables
} }