update policy status to false if error occurs
@@ -373,8 +373,10 @@ func (m *webhookConfigManager) reconcileWebhook(namespace, name string) error {
return err
}
+ ready := true
if err := m.updateWebhookConfig(webhooks); err != nil {
- return errors.Wrapf(err, "failed to update webhook configurations for policy %s/%s", namespace, name)
+ ready = false
+ logger.Error(err, "failed to update webhook configurations for policy")
}
// DELETION of the policy
@@ -382,11 +384,13 @@ func (m *webhookConfigManager) reconcileWebhook(namespace, name string) error {
return nil
}
- if err := m.updateStatus(policy); err != nil {
+ if err := m.updateStatus(policy, ready); err != nil {
return errors.Wrapf(err, "failed to update policy status %s/%s", namespace, name)
}
+ if ready {
logger.Info("policy is ready to serve admission requests")
+ }
return nil
}
@@ -635,9 +639,9 @@ func (m *webhookConfigManager) compareAndUpdateWebhook(webhookKind, webhookName
return nil
}
-func (m *webhookConfigManager) updateStatus(policy *kyverno.ClusterPolicy) error {
+func (m *webhookConfigManager) updateStatus(policy *kyverno.ClusterPolicy, status bool) error {
policyCopy := policy.DeepCopy()
- policyCopy.Status.Ready = true
+ policyCopy.Status.Ready = status
if policy.GetNamespace() == "" {
_, err := m.kyvernoClient.KyvernoV1().ClusterPolicies().UpdateStatus(context.TODO(), policyCopy, v1.UpdateOptions{})
return err
