mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-06 16:06:56 +00:00
* feat: remove policy mutation code Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * fix Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * refactor: support Audit and Enforce failure actions Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * codegen Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * fix Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * typo Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * update changelog Signed-off-by: ShutingZhao <shuting@nirmata.com> Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> Signed-off-by: ShutingZhao <shuting@nirmata.com> Co-authored-by: shuting <shuting@nirmata.com> Co-authored-by: Vyankatesh Kudtarkar <vyankateshkd@gmail.com>
29 lines
849 B
Go
29 lines
849 B
Go
package engine
|
|
|
|
import (
|
|
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
|
|
"github.com/kyverno/kyverno/pkg/engine/response"
|
|
)
|
|
|
|
// IsResponseSuccessful return true if all responses are successful
|
|
func IsResponseSuccessful(engineReponses []*response.EngineResponse) bool {
|
|
for _, er := range engineReponses {
|
|
if !er.IsSuccessful() {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
// BlockRequest returns true when:
|
|
// 1. a policy fails (i.e. creates a violation) and validationFailureAction is set to 'enforce'
|
|
// 2. a policy has a processing error and failurePolicy is set to 'Fail`
|
|
func BlockRequest(er *response.EngineResponse, failurePolicy kyvernov1.FailurePolicyType) bool {
|
|
if er.IsFailed() && er.GetValidationFailureAction().Enforce() {
|
|
return true
|
|
}
|
|
if er.IsError() && failurePolicy == kyvernov1.Fail {
|
|
return true
|
|
}
|
|
return false
|
|
}
|