mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-24 08:36:46 +00:00
feat: skip applying a VP which is converted to VAP (#12312)
* feat: skip vpol application if it's converted to vap Signed-off-by: ShutingZhao <shuting@nirmata.com> * fix: add missing error checks Signed-off-by: ShutingZhao <shuting@nirmata.com> --------- Signed-off-by: ShutingZhao <shuting@nirmata.com>
This commit is contained in:
parent
4b4e6cc415
commit
d7a37924a9
2 changed files with 16 additions and 2 deletions
|
@ -161,6 +161,13 @@ func (r *policyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
|
|||
if err != nil {
|
||||
return ctrl.Result{}, err
|
||||
}
|
||||
|
||||
if policy.GetStatus().Generated {
|
||||
r.lock.Lock()
|
||||
defer r.lock.Unlock()
|
||||
delete(r.policies, req.NamespacedName.String())
|
||||
return ctrl.Result{}, nil
|
||||
}
|
||||
// get exceptions that match the policy
|
||||
exceptions, err := r.ListExceptions(policy.GetName())
|
||||
if err != nil {
|
||||
|
|
|
@ -519,14 +519,21 @@ func (c *controller) updatePolicyStatus(ctx context.Context, policy engineapi.Ge
|
|||
latest.Status.ValidatingAdmissionPolicy.Generated = generated
|
||||
latest.Status.ValidatingAdmissionPolicy.Message = msg
|
||||
|
||||
new, _ := c.kyvernoClient.KyvernoV1().ClusterPolicies().UpdateStatus(ctx, latest, metav1.UpdateOptions{})
|
||||
new, err := c.kyvernoClient.KyvernoV1().ClusterPolicies().UpdateStatus(ctx, latest, metav1.UpdateOptions{})
|
||||
if err != nil {
|
||||
logging.Error(err, "failed to update cluster policy status", cpol.GetName(), "status", new.Status)
|
||||
}
|
||||
logging.V(3).Info("updated cluster policy status", "name", cpol.GetName(), "status", new.Status)
|
||||
} else if vpol := policy.AsValidatingPolicy(); vpol != nil {
|
||||
latest := vpol.DeepCopy()
|
||||
latest.Status.Generated = generated
|
||||
latest.Status.Message = msg
|
||||
|
||||
new, _ := c.kyvernoClient.PoliciesV1alpha1().ValidatingPolicies().UpdateStatus(ctx, latest, metav1.UpdateOptions{})
|
||||
new, err := c.kyvernoClient.PoliciesV1alpha1().ValidatingPolicies().UpdateStatus(ctx, latest, metav1.UpdateOptions{})
|
||||
if err != nil {
|
||||
logging.Error(err, "failed to update validating policy status", vpol.GetName(), "status", new.Status)
|
||||
}
|
||||
|
||||
logging.V(3).Info("updated validating policy status", "name", vpol.GetName(), "status", new.Status)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue