8000 Handle conflict with ScheduledScan status updates with retry logic by Ilyesbdlala · Pull Request #2910 · secureCodeBox/secureCodeBox · GitHub
[go: up one dir, main page]

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions operator/controllers/execution/scheduledscan_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/go-logr/logr"
"github.com/robfig/cron"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -76,8 +77,17 @@ func (r *ScheduledScanReconciler) Reconcile(ctx context.Context, req ctrl.Reques
log.V(4).Info("Updating ScheduledScans Findings as they appear to have changed")
scheduledScan.Status.Findings = *lastFindings.DeepCopy()
if err := r.Status().Update(ctx, &scheduledScan); err != nil {
log.Error(err, "unable to update ScheduledScan status")
return ctrl.Result{}, err
if apierrors.IsConflict(err) {
r.Log.V(4).Info(
"Conflict while updating ScheduledScan status, retrying",
"scheduledScan", scheduledScan.Name,
"namespace", scheduledScan.Namespace,
)
return ctrl.Result{RequeueAfter: 10 * time.Second}, nil
} else {
log.Error(err, "unable to update ScheduledScan status")
return ctrl.Result{}, err
}
}
}
}
Expand Down Expand Up @@ -178,8 +188,17 @@ func (r *ScheduledScanReconciler) Reconcile(ctx context.Context, req ctrl.Reques
var now metav1.Time = metav1.Now()
scheduledScan.Status.LastScheduleTime = &now
if err := r.Status().Update(ctx, &scheduledScan); err != nil {
log.Error(err, "Unable to update ScheduledScan status")
return ctrl.Result{}, err
if apierrors.IsConflict(err) {
r.Log.V(4).Info(
"Conflict while updating ScheduledScan status, retrying",
"scheduledScan", scheduledScan.Name,
"namespace", scheduledScan.Namespace,
)
return ctrl.Result{RequeueAfter: 10 * time.Second}, nil
} else {
log.Error(err, "Unable to update ScheduledScan status")
return ctrl.Result{}, err
}
}

// Recalculate next schedule
Expand Down
Loading
0