fixed generate flow
@@ -40,10 +40,7 @@ func (ws *WebhookServer) HandleGenerate(request *v1beta1.AdmissionRequest, polic
logger := ws.log.WithValues("action", "generation", "uid", request.UID, "kind", request.Kind, "namespace", request.Namespace, "name", request.Name, "operation", request.Operation, "gvk", request.Kind.String())
logger.V(4).Info("incoming request")
var engineResponses []*response.EngineResponse
- if request.Operation == v1beta1.Create || request.Operation == v1beta1.Update {
- if len(policies) == 0 {
- return
- }
+ if (request.Operation == v1beta1.Create || request.Operation == v1beta1.Update) && len(policies) != 0 {
// convert RAW to unstructured
new, old, err := kyvernoutils.ExtractResources(nil, request)
if err != nil {
@@ -179,8 +176,12 @@ func (ws *WebhookServer) handleUpdateTargetResource(request *v1beta1.AdmissionRe
targetSourceName := newRes.GetName()
targetSourceKind := newRes.GetKind()
- for _, policy := range policies {
- if policy.GetName() == policyName {
+ policy, err := ws.kyvernoClient.KyvernoV1().ClusterPolicies().Get(contextdefault.TODO(), policyName, metav1.GetOptions{})
+ if err != nil {
+ logger.Error(err, "failed to get policy from kyverno client.", "policy name", policyName)
+ return
+ }
+
for _, rule := range policy.Spec.Rules {
if rule.Generation.Kind == targetSourceKind && rule.Generation.Name == targetSourceName {
updatedRule, err := getGeneratedByResource(newRes, resLabels, ws.client, rule, logger)
@@ -213,8 +214,6 @@ func (ws *WebhookServer) handleUpdateTargetResource(request *v1beta1.AdmissionRe
}
}
}
- }
- }
if enqueueBool {
grName := resLabels["policy.kyverno.io/gr-name"]
