1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00

fix mutate foreach auto-gen rules (#2507)

Signed-off-by: ShutingZhao <shutting06@gmail.com>
This commit is contained in:
shuting 2021-10-09 13:31:52 -07:00 committed by GitHub
parent 5c3f219197
commit 514a851d2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -726,7 +726,16 @@ func generateRuleForControllers(rule kyverno.Rule, controllers string, log logr.
if rule.Mutation.ForEachMutation != nil && rule.Mutation.ForEachMutation.PatchStrategicMerge != nil {
newForeachMutation := &kyverno.Mutation{
ForEachMutation: rule.Mutation.ForEachMutation,
ForEachMutation: &kyverno.ForEachMutation{
List: rule.Mutation.ForEachMutation.List,
Context: rule.Mutation.ForEachMutation.Context,
AnyAllConditions: rule.Mutation.ForEachMutation.AnyAllConditions,
PatchStrategicMerge: map[string]interface{}{
"spec": map[string]interface{}{
"template": rule.Mutation.ForEachMutation.PatchStrategicMerge,
},
},
},
}
controllerRule.Mutation = newForeachMutation.DeepCopy()
return *controllerRule
@ -745,15 +754,6 @@ func generateRuleForControllers(rule kyverno.Rule, controllers string, log logr.
return *controllerRule
}
if rule.Validation.ForEachValidation != nil && rule.Validation.ForEachValidation.Pattern != nil {
newForeachValidate := &kyverno.Validation{
Message: variables.FindAndShiftReferences(log, rule.Validation.Message, "spec/template", "pattern"),
ForEachValidation: rule.Validation.ForEachValidation,
}
controllerRule.Validation = newForeachValidate.DeepCopy()
return *controllerRule
}
if rule.Validation.AnyPattern != nil {
anyPatterns, err := rule.Validation.DeserializeAnyPattern()
@ -769,15 +769,16 @@ func generateRuleForControllers(rule kyverno.Rule, controllers string, log logr.
return *controllerRule
}
if rule.Validation.ForEachValidation != nil && rule.Validation.ForEachValidation.AnyPattern != nil {
controllerRule.Validation = &kyverno.Validation{
if rule.Validation.ForEachValidation != nil && rule.Validation.ForEachValidation.Pattern != nil {
newForeachValidate := &kyverno.Validation{
Message: variables.FindAndShiftReferences(log, rule.Validation.Message, "spec/template", "pattern"),
ForEachValidation: rule.Validation.ForEachValidation,
}
controllerRule.Validation = newForeachValidate.DeepCopy()
return *controllerRule
}
if rule.Validation.ForEachValidation != nil && rule.Validation.ForEachValidation.Deny != nil {
if rule.Validation.ForEachValidation != nil && rule.Validation.ForEachValidation.AnyPattern != nil {
controllerRule.Validation = &kyverno.Validation{
Message: variables.FindAndShiftReferences(log, rule.Validation.Message, "spec/template", "pattern"),
ForEachValidation: rule.Validation.ForEachValidation,