Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion mainhandler/handlerequests.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,14 +405,19 @@ func (mainHandler *MainHandler) HandleImageScanningScopedRequest(ctx context.Con
continue
}

noContainerSlug, _ := instanceID.GetSlug(true)
if ok := slugs[noContainerSlug]; ok {
// container profile already scanned for this workload, skip remaining containers
continue
}

// get container data
containerData, err := utils.PodToContainerData(mainHandler.k8sAPI, pod, instanceID, mainHandler.config.ClusterName())
if err != nil {
// if pod is not running, we can't get the image id
continue
}

noContainerSlug, _ := instanceID.GetSlug(true)
if profile := utils.GetContainerProfileForRelevancyScan(ctx, mainHandler.ksStorageClient, noContainerSlug, ns); profile != nil {
cmd := utils.GetContainerProfileScanCommand(profile, pod)

Expand Down
3 changes: 3 additions & 0 deletions utils/containerprofile.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ func SkipContainerProfile(annotations map[string]string) (bool, error) {
return true, fmt.Errorf("no annotations") // skip
}

if _, ok := annotations[helpersv1.ReportSeriesIdMetadataKey]; ok {
return true, nil // skip TS profiles
}
Comment on lines +29 to +31
Copy link
Copy Markdown

@coderabbitai coderabbitai bot Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Scope this TS skip to relevancy flow only (Line 29).

This early return changes behavior for every caller of utils.SkipContainerProfile, including watcher/containerprofilewatcher.go (snippet 1), not just relevancy scans. Profiles carrying helpersv1.ReportSeriesIdMetadataKey will now be globally skipped.

Please keep generic validation in SkipContainerProfile and move TS-specific skipping into a relevancy-specific helper/call path.

Proposed refactor to limit behavior change to relevancy scan path
 func SkipContainerProfile(annotations map[string]string) (bool, error) {
@@
-	if _, ok := annotations[helpersv1.ReportSeriesIdMetadataKey]; ok {
-		return true, nil // skip TS profiles
-	}
 	if status, ok := annotations[helpersv1.StatusMetadataKey]; ok && !slices.Contains(ann, status) {
 		return true, fmt.Errorf("invalid status")
 	}
@@
 	return false, nil // do not skip
 }
+
+func SkipContainerProfileForRelevancyScan(annotations map[string]string) (bool, error) {
+	if _, ok := annotations[helpersv1.ReportSeriesIdMetadataKey]; ok {
+		return true, nil // skip TS profiles only for relevancy scans
+	}
+	return SkipContainerProfile(annotations)
+}
@@
-		if skip, err := SkipContainerProfile(profile.Annotations); skip {
+		if skip, err := SkipContainerProfileForRelevancyScan(profile.Annotations); skip {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if _, ok := annotations[helpersv1.ReportSeriesIdMetadataKey]; ok {
return true, nil // skip TS profiles
}
// SkipContainerProfile performs generic validation on container profile annotations
if status, ok := annotations[helpersv1.StatusMetadataKey]; ok && !slices.Contains(ann, status) {
return true, fmt.Errorf("invalid status")
}
return false, nil // do not skip
}
// SkipContainerProfileForRelevancyScan skips profiles for the relevancy scan path only
func SkipContainerProfileForRelevancyScan(annotations map[string]string) (bool, error) {
if _, ok := annotations[helpersv1.ReportSeriesIdMetadataKey]; ok {
return true, nil // skip TS profiles only for relevancy scans
}
return SkipContainerProfile(annotations)
}
// In the relevancy scan caller:
if skip, err := SkipContainerProfileForRelevancyScan(profile.Annotations); skip {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@utils/containerprofile.go` around lines 29 - 31, The SkipContainerProfile
function currently returns early for any profile with
helpersv1.ReportSeriesIdMetadataKey which globally changes behavior; revert that
TS-specific check out of SkipContainerProfile and restore generic validation
there, then add a new relevancy-specific helper or extend the relevancy scan
call path (e.g., in watcher/containerprofilewatcher.go or the relevancy scorer)
to perform the ReportSeriesIdMetadataKey check and skip TS profiles only during
relevancy scans; update callers of SkipContainerProfile to call the new
relevancy helper where appropriate so only the relevancy flow excludes
ReportSeriesIdMetadataKey profiles.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's on purpose, we should not react on TS profiles

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matthyx, understood — skipping TS profiles (those carrying helpersv1.ReportSeriesIdMetadataKey) globally across all callers of SkipContainerProfile is intentional, not just for the relevancy scan path. Thanks for the clarification!


✏️ Learnings added
Learnt from: matthyx
Repo: kubescape/operator PR: 362
File: utils/containerprofile.go:29-31
Timestamp: 2026-03-26T15:05:03.285Z
Learning: In `kubescape/operator`, TS (time-series) container profiles — identified by the presence of `helpersv1.ReportSeriesIdMetadataKey` in their annotations — should be globally skipped across all callers of `utils.SkipContainerProfile` in `utils/containerprofile.go`. This is intentional design: no code path should react to TS profiles.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

if status, ok := annotations[helpersv1.StatusMetadataKey]; ok && !slices.Contains(ann, status) {
return true, fmt.Errorf("invalid status")
}
Expand Down
Loading