1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-05 07:26:55 +00:00

fix(status): don't get the policy twice before status update (#11026)

* fix(status): don't compare uid

Signed-off-by: Khaled Emara <khaled.emara@nirmata.com>

* chore(webhook): logger message

Signed-off-by: Khaled Emara <khaled.emara@nirmata.com>

---------

Signed-off-by: Khaled Emara <khaled.emara@nirmata.com>
This commit is contained in:
Khaled Emara 2024-09-09 13:30:26 +03:00 committed by GitHub
parent 8e14e1e7c7
commit 0a4c14eb82
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -574,38 +574,30 @@ func (c *controller) updatePolicyStatuses(ctx context.Context) error {
}
for _, policy := range policies {
if policy.GetNamespace() == "" {
p, err := c.kyvernoClient.KyvernoV1().ClusterPolicies().Get(ctx, policy.GetName(), metav1.GetOptions{})
if err != nil {
logger.Error(err, "failed to get latest clusterpolicy for status reconciliation", "policy", policy.GetName())
continue
}
_, err = controllerutils.UpdateStatus(
ctx,
p,
policy.(*kyvernov1.ClusterPolicy),
c.kyvernoClient.KyvernoV1().ClusterPolicies(),
func(policy *kyvernov1.ClusterPolicy) error {
return updateStatusFunc(policy)
},
)
if err != nil {
return err
}
} else {
p, err := c.kyvernoClient.KyvernoV1().Policies(policy.GetNamespace()).Get(ctx, policy.GetName(), metav1.GetOptions{})
if err != nil {
logger.Error(err, "failed to get latest policy for status reconciliation", "namespace", policy.GetNamespace, "policy", policy.GetName())
logger.Error(err, "failed to update clusterpolicy status", "policy", policy.GetName())
continue
}
} else {
_, err = controllerutils.UpdateStatus(
ctx,
p,
policy.(*kyvernov1.Policy),
c.kyvernoClient.KyvernoV1().Policies(policy.GetNamespace()),
func(policy *kyvernov1.Policy) error {
return updateStatusFunc(policy)
},
)
if err != nil {
return err
logger.Error(err, "failed to update policy status", "namespace", policy.GetNamespace(), "policy", policy.GetName())
continue
}
}
}