1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-13 19:28:55 +00:00

fix: reduce number of queries to detect delete operations (#7620)

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
Charles-Edouard Brétéché 2023-06-21 09:59:54 +02:00 committed by GitHub
parent 76139ea0ce
commit 6caea187f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -324,14 +324,13 @@ func DefaultVariableResolver(ctx context.EvalInterface, variable string) (interf
}
func substituteVariablesIfAny(log logr.Logger, ctx context.EvalInterface, vr VariableResolver) jsonUtils.Action {
isDeleteRequest := isDeleteRequest(ctx)
return jsonUtils.OnlyForLeafsAndKeys(func(data *jsonUtils.ActionData) (interface{}, error) {
value, ok := data.Element.(string)
if !ok {
return data.Element, nil
}
isDeleteRequest := IsDeleteRequest(ctx)
vars := regex.RegexVariables.FindAllString(value, -1)
for len(vars) > 0 {
originalPattern := value
@ -404,16 +403,14 @@ func substituteVariablesIfAny(log logr.Logger, ctx context.EvalInterface, vr Var
})
}
func IsDeleteRequest(ctx context.EvalInterface) bool {
func isDeleteRequest(ctx context.EvalInterface) bool {
if ctx == nil {
return false
}
operation, err := ctx.Query("request.operation")
if err == nil && operation == "DELETE" {
return true
}
return false
}