mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-14 11:57:48 +00:00
Signed-off-by: Mariam Fahmy <mariam.fahmy@nirmata.com> Co-authored-by: Mariam Fahmy <mariam.fahmy@nirmata.com>
This commit is contained in:
parent
2c570e007e
commit
cf65fc2f48
3 changed files with 30 additions and 6 deletions
|
@ -45,6 +45,13 @@ rules:
|
||||||
verbs:
|
verbs:
|
||||||
- list
|
- list
|
||||||
- watch
|
- watch
|
||||||
|
- apiGroups:
|
||||||
|
- kyverno.io
|
||||||
|
resources:
|
||||||
|
- clustercleanuppolicies/status
|
||||||
|
- cleanuppolicies/status
|
||||||
|
verbs:
|
||||||
|
- update
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
- ''
|
- ''
|
||||||
resources:
|
resources:
|
||||||
|
|
|
@ -43934,6 +43934,13 @@ rules:
|
||||||
verbs:
|
verbs:
|
||||||
- list
|
- list
|
||||||
- watch
|
- watch
|
||||||
|
- apiGroups:
|
||||||
|
- kyverno.io
|
||||||
|
resources:
|
||||||
|
- clustercleanuppolicies/status
|
||||||
|
- cleanuppolicies/status
|
||||||
|
verbs:
|
||||||
|
- update
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
- ''
|
- ''
|
||||||
resources:
|
resources:
|
||||||
|
|
|
@ -340,7 +340,10 @@ func (c *controller) reconcile(ctx context.Context, logger logr.Logger, key, nam
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
c.updateCleanupPolicyStatus(ctx, policy, namespace, *executionTime)
|
if err := c.updateCleanupPolicyStatus(ctx, policy, namespace, *executionTime); err != nil {
|
||||||
|
logger.Error(err, "failed to update the cleanup policy status")
|
||||||
|
return err
|
||||||
|
}
|
||||||
nextExecutionTime, err = policy.GetNextExecutionTime(*executionTime)
|
nextExecutionTime, err = policy.GetNextExecutionTime(*executionTime)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error(err, "failed to get the policy next execution time")
|
logger.Error(err, "failed to get the policy next execution time")
|
||||||
|
@ -357,19 +360,26 @@ func (c *controller) reconcile(ctx context.Context, logger logr.Logger, key, nam
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *controller) updateCleanupPolicyStatus(ctx context.Context, policy kyvernov2alpha1.CleanupPolicyInterface, namespace string, time time.Time) {
|
func (c *controller) updateCleanupPolicyStatus(ctx context.Context, policy kyvernov2alpha1.CleanupPolicyInterface, namespace string, time time.Time) error {
|
||||||
switch obj := policy.(type) {
|
switch obj := policy.(type) {
|
||||||
case *kyvernov2beta1.ClusterCleanupPolicy:
|
case *kyvernov2beta1.ClusterCleanupPolicy:
|
||||||
latest := obj.DeepCopy()
|
latest := obj.DeepCopy()
|
||||||
latest.Status.LastExecutionTime.Time = time
|
latest.Status.LastExecutionTime = metav1.NewTime(time)
|
||||||
|
|
||||||
new, _ := c.kyvernoClient.KyvernoV2beta1().ClusterCleanupPolicies().UpdateStatus(ctx, latest, metav1.UpdateOptions{})
|
new, err := c.kyvernoClient.KyvernoV2beta1().ClusterCleanupPolicies().UpdateStatus(ctx, latest, metav1.UpdateOptions{})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
logging.V(3).Info("updated cluster cleanup policy status", "name", policy.GetName(), "status", new.Status)
|
logging.V(3).Info("updated cluster cleanup policy status", "name", policy.GetName(), "status", new.Status)
|
||||||
case *kyvernov2beta1.CleanupPolicy:
|
case *kyvernov2beta1.CleanupPolicy:
|
||||||
latest := obj.DeepCopy()
|
latest := obj.DeepCopy()
|
||||||
latest.Status.LastExecutionTime.Time = time
|
latest.Status.LastExecutionTime = metav1.NewTime(time)
|
||||||
|
|
||||||
new, _ := c.kyvernoClient.KyvernoV2beta1().CleanupPolicies(namespace).UpdateStatus(ctx, latest, metav1.UpdateOptions{})
|
new, err := c.kyvernoClient.KyvernoV2beta1().CleanupPolicies(namespace).UpdateStatus(ctx, latest, metav1.UpdateOptions{})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
logging.V(3).Info("updated cleanup policy status", "name", policy.GetName(), "namespace", policy.GetNamespace(), "status", new.Status)
|
logging.V(3).Info("updated cleanup policy status", "name", policy.GetName(), "namespace", policy.GetNamespace(), "status", new.Status)
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue