Skip to content
This repository was archived by the owner on Oct 14, 2020. It is now read-only.

Commit fd07091

Browse files
committed
Add completion timestamp to scans once finished
This also allows to track the total runtime by comparing it against the .metadata.creationTimestamp of the scan.
1 parent b38a73b commit fd07091

File tree

5 files changed

+21
-1
lines changed

5 files changed

+21
-1
lines changed

operator/apis/execution/v1/scan_types.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ type ScanSpec struct {
4343
type ScanStatus struct {
4444
State string `json:"state,omitempty"`
4545

46-
ErrorDescription string `json:"errorDescription,omitempty"`
46+
// FinishedAt contains the time where the scan (including parser & hooks) has been marked as "Done"
47+
FinishedAt *metav1.Time `json:"finishedAt,omitempty"`
48+
ErrorDescription string `json:"errorDescription,omitempty"`
4749

4850
// RawResultType determines which kind of ParseDefinition will be used to turn the raw results of the scanner into findings
4951
RawResultType string `json:"rawResultType,omitempty"`

operator/apis/execution/v1/zz_generated.deepcopy.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

operator/config/crd/bases/execution.experimental.securecodebox.io_scans.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,11 @@ spec:
252252
type: integer
253253
type: object
254254
type: object
255+
finishedAt:
256+
description: FinishedAt contains the time where the scan (including
257+
parser & hooks) has been marked as "Done"
258+
format: date-time
259+
type: string
255260
rawResultFile:
256261
description: RawResultFile Filename of the result file of the scanner.
257262
e.g. `nmap-result.xml`

operator/controllers/execution/scans/hook_reconciler.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ func (r *ScanReconciler) startReadOnlyHooks(scan *executionv1.Scan) error {
217217
if len(readOnlyHooks) == 0 {
218218
r.Log.Info("Marked scan as done as without running ReadOnly hooks as non were configured", "ScanName", scan.Name)
219219
scan.Status.State = "Done"
220+
var now metav1.Time = metav1.Now()
221+
scan.Status.FinishedAt = &now
220222
if err := r.Status().Update(ctx, scan); err != nil {
221223
r.Log.Error(err, "Unable to update Scan status")
222224
return err
@@ -281,6 +283,8 @@ func (r *ScanReconciler) checkIfReadOnlyHookIsCompleted(scan *executionv1.Scan)
281283
if readOnlyHookCompletion == completed {
282284
r.Log.V(7).Info("All ReadOnlyHooks have completed")
283285
scan.Status.State = "Done"
286+
var now metav1.Time = metav1.Now()
287+
scan.Status.FinishedAt = &now
284288
if err := r.Status().Update(ctx, scan); err != nil {
285289
r.Log.Error(err, "Unable to update Scan status")
286290
return err

operator/crds/execution.experimental.securecodebox.io_scans.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,11 @@ spec:
252252
type: integer
253253
type: object
254254
type: object
255+
finishedAt:
256+
description: FinishedAt contains the time where the scan (including
257+
parser & hooks) has been marked as "Done"
258+
format: date-time
259+
type: string
255260
rawResultFile:
256261
description: RawResultFile Filename of the result file of the scanner.
257262
e.g. `nmap-result.xml`

0 commit comments

Comments
 (0)