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

Commit 1b4fbe2

Browse files
committed
Rework comments and log messages in ScheduledScan Controller
1 parent 254cbc1 commit 1b4fbe2

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

operator/controllers/execution/scheduledscan_controller.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,24 @@ func (r *ScheduledScanReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
6464
log.Error(err, "unable to list child Scans")
6565
return ctrl.Result{}, err
6666
}
67+
log.V(8).Info("Got Child Scans for ScheduledScan", "count", len(childScans.Items))
6768

68-
log.Info("Got Scans", "count", len(childScans.Items))
69-
69+
// Get a sorted list of all successful child scans.
7070
var completedScans []executionv1.Scan
7171
for _, scan := range childScans.Items {
7272
if scan.Status.State == "Done" {
7373
completedScans = append(completedScans, scan)
7474
}
7575
}
76-
7776
sort.Slice(completedScans, func(i, j int) bool {
7877
return completedScans[i].ObjectMeta.CreationTimestamp.Before(&completedScans[j].ObjectMeta.CreationTimestamp)
7978
})
8079

80+
// Update findingsStats of ScheduledScan to match the most recent Scan
8181
if len(completedScans) >= 1 {
8282
lastFindings := completedScans[len(completedScans)-1].Status.Findings
8383
if !reflect.DeepEqual(lastFindings, scheduledScan.Status.Findings) {
84-
log.V(2).Info("Updating ScheduledScans Findings as they appear to have changed")
84+
log.V(4).Info("Updating ScheduledScans Findings as they appear to have changed")
8585
scheduledScan.Status.Findings = *lastFindings.DeepCopy()
8686
if err := r.Status().Update(ctx, &scheduledScan); err != nil {
8787
log.Error(err, "unable to update ScheduledScan status")
@@ -90,31 +90,29 @@ func (r *ScheduledScanReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
9090
}
9191
}
9292

93+
// Delete Old Scans when exceeding the history limit
9394
for i, scan := range completedScans {
9495
if int64(i) >= int64(len(completedScans))-scheduledScan.Spec.HistoryLimit {
9596
break
9697
}
9798
if err := r.Delete(ctx, &scan, client.PropagationPolicy(metav1.DeletePropagationBackground)); (err) != nil {
98-
log.Error(err, "unable to delete old scan", "scan", scan)
99+
log.Error(err, "Unable to delete old Scan", "scan", scan.Name)
99100
} else {
100-
log.V(0).Info("deleted old successful job", "scan", scan)
101+
log.V(2).Info("Deleted old successful Scan", "scan", scan.Name)
101102
}
102103
}
103104

104-
log.Info("ScanInterval parsed", "interval", scheduledScan.Spec.Interval)
105-
105+
// Calculate the next schedule
106106
var nextSchedule time.Time
107107
if scheduledScan.Status.LastScheduleTime != nil {
108108
nextSchedule = scheduledScan.Status.LastScheduleTime.Add(scheduledScan.Spec.Interval.Duration)
109109
} else {
110110
nextSchedule = time.Now().Add(-1 * time.Second)
111111
}
112112

113-
// check if it is time to start the scans
113+
// check if it is time to start the next Scan
114114
if !time.Now().Before(nextSchedule) {
115115
// It's time!
116-
log.Info("Should start scans here")
117-
118116
var scan = &executionv1.Scan{
119117
ObjectMeta: metav1.ObjectMeta{
120118
Namespace: scheduledScan.Namespace,
@@ -124,19 +122,19 @@ func (r *ScheduledScanReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
124122
}
125123
scan.Name = fmt.Sprintf("%s-%d", scheduledScan.Name, nextSchedule.Unix())
126124
if err := ctrl.SetControllerReference(&scheduledScan, scan, r.Scheme); err != nil {
127-
log.Error(err, "unable to set owner reference on scan")
125+
log.Error(err, "Unable to set owner reference on Scan")
128126
return ctrl.Result{}, err
129127
}
130128

131129
if err := r.Create(ctx, scan); err != nil {
132-
log.Error(err, "unable to create Scan for ScheduledScan", "scan", scan)
130+
log.Error(err, "Unable to create Scan for ScheduledScan")
133131
return ctrl.Result{}, err
134132
}
135133

136134
var now metav1.Time = metav1.Now()
137135
scheduledScan.Status.LastScheduleTime = &now
138136
if err := r.Status().Update(ctx, &scheduledScan); err != nil {
139-
log.Error(err, "unable to update ScheduledScan status")
137+
log.Error(err, "Unable to update ScheduledScan status")
140138
return ctrl.Result{}, err
141139
}
142140

0 commit comments

Comments
 (0)