1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-15 17:51:20 +00:00
kyverno/pkg/engine/generation.go
Charles-Edouard Brétéché a5e082303d
refactor: introduce autogen interface (#11418)
* refactor: introduce autogen interface

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* fix linter

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

---------

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2024-10-16 15:24:37 +02:00

23 lines
716 B
Go

package engine
import (
"github.com/go-logr/logr"
"github.com/kyverno/kyverno/pkg/autogen"
engineapi "github.com/kyverno/kyverno/pkg/engine/api"
"github.com/kyverno/kyverno/pkg/engine/internal"
)
// GenerateResponse checks for validity of generate rule on the resource
func (e *engine) generateResponse(
logger logr.Logger,
policyContext engineapi.PolicyContext,
) engineapi.PolicyResponse {
resp := engineapi.NewPolicyResponse()
for _, rule := range autogen.Default.ComputeRules(policyContext.Policy(), "") {
logger := internal.LoggerWithRule(logger, rule)
if ruleResp := e.filterRule(rule, logger, policyContext); ruleResp != nil {
resp.Rules = append(resp.Rules, *ruleResp)
}
}
return resp
}