Skip to content

Commit 71293e1

Browse files
author
Jop Zitman
committed
Add migrations to scans which had already finished.
Unfortunately can't set the field to `nil` as Kubernetes complains about missing fields priority and type (on non existing elements...) Signed-off-by: Jop Zitman <jop.zitman@secura.com>
1 parent 05c3464 commit 71293e1

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

operator/controllers/execution/scans/hook_reconciler.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ func (r *ScanReconciler) migrateHookStatus(scan *executionv1.Scan) error {
8181
// Had already started ReadOnly hooks and should now check status.
8282
// No status for ReadOnly in old CRD, so mark everything as InProgress and let processInProgressHook update it later.
8383
hookStatus.State = executionv1.InProgress
84+
} else if scan.Status.State == "Done" {
85+
// Had completely finished
86+
hookStatus.State = executionv1.Completed
8487
}
8588

8689
r.Log.Info("Retrieved new ReadOnly hook Status", "New", hookStatus)
@@ -90,7 +93,9 @@ func (r *ScanReconciler) migrateHookStatus(scan *executionv1.Scan) error {
9093
}
9194

9295
scan.Status.OrderedHookStatuses = util.OrderHookStatusesInsideAPrioClass(append(readOnlyHooks, strSlice...))
93-
scan.Status.State = "HookProcessing"
96+
if scan.Status.State != "Done" {
97+
scan.Status.State = "HookProcessing"
98+
}
9499

95100
if err := r.Status().Update(ctx, scan); err != nil {
96101
r.Log.Error(err, "unable to update Scan status")

operator/controllers/execution/scans/scan_controller.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ func (r *ScanReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
8181

8282
// Handle Finalizer if the scan is getting deleted
8383
if !scan.ObjectMeta.DeletionTimestamp.IsZero() {
84+
// Check if this Scan has not yet been converted to new CRD
85+
if scan.Status.OrderedHookStatuses == nil && scan.Status.ReadAndWriteHookStatus != nil && scan.Status.State == "Done" {
86+
if err := r.migrateHookStatus(&scan); err != nil {
87+
return ctrl.Result{}, err
88+
}
89+
}
8490
if err := r.handleFinalizer(&scan); err != nil {
8591
r.Log.Error(err, "Failed to run Scan Finalizer")
8692
return ctrl.Result{}, err

0 commit comments

Comments
 (0)