Skip to content

Commit eb52498

Browse files
committed
Adjust logs for container auto-discovery
Add log for discovering new unscanned containers. Add log for discovering orphaned 'Trivy' scans. Remove repeated "Scan was already deleted" log messages. Signed-off-by: Boris Shek <boris.shek@iteratec.com>
1 parent 3436623 commit eb52498

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

auto-discovery/kubernetes/controllers/container_scan_controller.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ func podNotReady(pod corev1.Pod) bool {
114114
func (r *ContainerScanReconciler) checkIfNewScansNeedToBeCreated(ctx context.Context, pod corev1.Pod) {
115115
r.Log.V(8).Info("Pod is running", "pod", pod.Name, "namespace", pod.Namespace)
116116
nonScannedImageIDs := r.getNonScannedImageIDs(ctx, pod)
117+
//log if there are any unscanned containers
118+
if len(nonScannedImageIDs) > 0 {
119+
r.Log.Info("Discovered one or more new unscanned containers; scanning them now", "pod", pod.Name, "namespace", pod.Namespace)
120+
}
117121
r.createScheduledScans(ctx, pod, nonScannedImageIDs)
118122
}
119123

@@ -413,6 +417,10 @@ func (r *ContainerScanReconciler) checkIfScansNeedToBeDeleted(ctx context.Contex
413417
r.Log.V(8).Info("Pod will be deleted", "pod", pod.Name, "namespace", pod.Namespace, "timestamp", pod.DeletionTimestamp)
414418
allImageIDs := getImageIDsForPod(pod)
415419
imageIDsToBeDeleted := r.getOrphanedScanImageIDs(ctx, pod, allImageIDs)
420+
//log if there are any orphaned scans
421+
if len(imageIDsToBeDeleted) > 0 {
422+
r.Log.Info("Discovered one or more 'Trivy' scans related to a non-active container; deleting them now", "pod", pod.Name, "namespace", pod.Namespace)
423+
}
416424
r.deleteScans(ctx, pod, imageIDsToBeDeleted)
417425
}
418426

@@ -428,9 +436,7 @@ func (r *ContainerScanReconciler) getOrphanedScanImageIDs(ctx context.Context, p
428436
var scan executionv1.ScheduledScan
429437
err := r.Client.Get(ctx, types.NamespacedName{Name: scanName, Namespace: pod.Namespace}, &scan)
430438
if err != nil {
431-
if k8sErrors.IsNotFound(err) {
432-
r.Log.Info("Scan was already deleted, nothing to do", "name", scanName)
433-
} else {
439+
if !k8sErrors.IsNotFound(err) {
434440
r.Log.Error(err, "Unable to fetch scan", "name", scanName)
435441
}
436442
} else if !r.containerIDInUse(ctx, pod, imageID) {

0 commit comments

Comments
 (0)