1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-04-08 10:04:25 +00:00

refactor: reduce policy mutations ()

Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>
This commit is contained in:
Charles-Edouard Brétéché 2022-04-05 10:28:33 +02:00 committed by GitHub
parent e716daa22e
commit f77220ad66
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -21,22 +21,22 @@ func GenerateJSONPatchesForDefaults(policy kyverno.PolicyInterface, log logr.Log
var patches [][]byte
var updateMsgs []string
spec := policy.GetSpec()
// default 'ValidationFailureAction'
if patch, updateMsg := defaultvalidationFailureAction(spec, log); patch != nil {
patches = append(patches, patch)
updateMsgs = append(updateMsgs, updateMsg)
}
// default 'Background'
if patch, updateMsg := defaultBackgroundFlag(spec, log); patch != nil {
patches = append(patches, patch)
updateMsgs = append(updateMsgs, updateMsg)
}
if patch, updateMsg := defaultFailurePolicy(spec, log); patch != nil {
patches = append(patches, patch)
updateMsgs = append(updateMsgs, updateMsg)
}
// if autogenInternals is enabled, we don't mutate rules in the webhook
// if autogenInternals is enabled, we don't mutate most of the policy fields
if !toggle.AutogenInternals() {
// default 'ValidationFailureAction'
if patch, updateMsg := defaultvalidationFailureAction(spec, log); patch != nil {
patches = append(patches, patch)
updateMsgs = append(updateMsgs, updateMsg)
}
// default 'Background'
if patch, updateMsg := defaultBackgroundFlag(spec, log); patch != nil {
patches = append(patches, patch)
updateMsgs = append(updateMsgs, updateMsg)
}
if patch, updateMsg := defaultFailurePolicy(spec, log); patch != nil {
patches = append(patches, patch)
updateMsgs = append(updateMsgs, updateMsg)
}
patch, errs := GeneratePodControllerRule(policy, log)
if len(errs) > 0 {
var errMsgs []string