Skip to content

chore: deprecate old profiletypes in favor of containerprofiles - #351

Open
entlein wants to merge 17 commits into
kubescape:mainfrom
k8sstormcenter:migrate/sbob
Open

chore: deprecate old profiletypes in favor of containerprofiles#351
entlein wants to merge 17 commits into
kubescape:mainfrom
k8sstormcenter:migrate/sbob

Conversation

@entlein

@entlein entlein commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Removing all code relating to AP NN or ug

Summary by CodeRabbit

  • New Features

    • Network policies are generated from eligible container profiles and combined at the workload level.
    • Added execution, policy, and call-stack profile information.
    • Migration tooling supports container and seccomp profiles, including large numeric values.
  • Breaking Changes

    • Application profile and network neighborhood resources and endpoints have been removed.
  • Bug Fixes

    • Completed container profiles can no longer regress to Learning status.
    • Improved handling of unavailable profiles, policy generation, and migration errors.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d2319678-8dcd-4c3c-b3a2-3b075da6f10f

📥 Commits

Reviewing files that changed from the base of the PR and between 7b6b0f4 and 5a2781e.

⛔ Files ignored due to path filters (1)
  • pkg/generated/openapi/zz_generated.openapi.go is excluded by !**/generated/**
📒 Files selected for processing (1)
  • pkg/registry/file/containerprofile_headers_smd_test.go

📝 Walkthrough

Walkthrough

The change removes ApplicationProfile and NetworkNeighborhood API and storage paths, makes network-policy generation ContainerProfile-based, updates ContainerProfile processing and configuration, and narrows Gob migration support to ContainerProfile and SeccompProfile with integration coverage.

Changes

ContainerProfile migration

Layer / File(s) Summary
Remove legacy API contracts
pkg/apis/softwarecomposition/..., pkg/apis/softwarecomposition/v1beta1/..., cmd/migration/main.go
Removes legacy profile types, generated support, registrations, and related references. Adds execution policy and call-stack types.
Generate policies from ContainerProfiles
pkg/apis/softwarecomposition/networkpolicy/v2/..., pkg/registry/file/generatednetworkpolicy.go, pkg/registry/file/generatednetworkpolicy_*test.go
Generates workload policies from available ContainerProfiles and validates aggregation, selectors, known servers, DNS, ports, and naming.
Retire legacy storage paths
pkg/apiserver/apiserver.go, pkg/config/*, pkg/registry/file/*, pkg/registry/softwarecomposition/*
Removes legacy processors, storage wrappers, REST registrations, merged-profile operations, and aggregation. Updates sizing, cleanup, completed-status protection, deflation, and key handling.
Update Gob migration
cmd/migration/*, pkg/registry/file/storage.go, pkg/registry/file/storage_test.go
Targets ContainerProfile or SeccompProfile during migration. Tests numeric preservation and failure paths.

Estimated code review effort: 5 (Critical) | ~120 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers: matthyx

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.34% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: removing legacy profile types and moving functionality to ContainerProfiles.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Comment thread cmd/migration/main.go
@@ -0,0 +1,185 @@
{

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.

chicken, whats this name "golden", that is not descriptive at all. same for window_*.json
put in your memory: descriptive short names without implementation details

if relevancyEnabled {
logger.L().Debug("relevancy is enabled, adding additional cleanup handlers")
resourceKindToHandler["applicationprofiles"] = append(resourceKindToHandler["applicationprofiles"], deleteMissingInstanceIdAnnotation, deleteMissingWlidAnnotation)
resourceKindToHandler["containerprofiles"] = append(resourceKindToHandler["containerprofiles"], deleteMissingInstanceIdAnnotation, deleteMissingWlidAnnotation)

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.

chicken, we need a test for this, cause cps have a different lifecycle than APs did. Lets have an exact contract here.

Comment on lines -71 to -76
func (f *fakeStorage) SaveMergedContainerProfile(ctx context.Context, observedKey string, profile *softwarecomposition.ContainerProfile) error {
return nil
}
func (f *fakeStorage) GetMergedContainerProfile(ctx context.Context, observedKey string) (softwarecomposition.ContainerProfile, error) {
return softwarecomposition.ContainerProfile{}, storage.NewKeyNotFoundError(observedKey, 0)
}

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.

chicken, why are we removing these?

@entlein entlein changed the title deprecate old profiletypes in favor of containerprofiles chore: deprecate old profiletypes in favor of containerprofiles Jul 29, 2026
@matthyx matthyx moved this to WIP in KS PRs tracking Jul 30, 2026
@entlein

entlein commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

Test-coverage gaps to close — ContainerProfile migration surface

Audit of the migration surface, prioritized by risk. Note two "green test, wrong mechanism" cases — a test exists but can't catch the real contract (the same failure shape as the GeneratedNetworkPolicy singular/plural bug that shipped in rc5k).

HIGH

  • cmd/migration/main.go0%. The one-shot gob→JSON migration decoder has no test/fixture; a field-decode bug silently corrupts every migrated profile. Golden test: encode a known legacy gob → decode → assert JSON round-trips each legacy uint64 field (LegacyArg, LegacySyscall.ErrnoRet) + the spec shape; plus unsupported-type and corrupt-stream error cases.
  • pkg/registry/softwarecomposition/containerprofile/{etcd,strategy}.go0%. The CP REST strategy is copy-paste-named from SbomSyft (SbomSyftStrategy, MatchWorkloadConfigurationScan); a wrong SelectableFields/GetAttrs ships undetected. Strategy unit tests: SelectableFields/GetAttrs expose the CP namespace/name/workload labels; NamespaceScoped(); create/update hooks.
  • Completed-immutability guard (containerprofile_processor.go PreSave, ~165-201). The revert logic is tested only against a fake whose GetContainerProfileMetadataNoLock aliases the locking read — so the whole reason the no-lock variant exists (avoiding the GuaranteedUpdate self-deadlock) is never exercised; swapping back to the locking call keeps tests green and deadlocks in production. Drive the guard through the real GuaranteedUpdate + sqlite pool; add the stored-TooLarge consolidated case.

MED

  • sqlite.go ECS/Host BuildContainerProfileKey/ParseContainerProfileKey/ECSKeysToPath/HostKeysToPath0% for non-K8s hosts (only K8s branch tested); a segment-order mismatch mis-scopes profiles. Round-trip table test per HostType (K8s new/legacy, ECS-EC2, ECS-Fargate, Host) + malformed-parts error branches.
  • generatednetworkpolicy.go Get/GetList — untested: the IsAvailable exclusion (a non-available/Learning profile must be excluded — a regression that included it would pass), the knownservers-lookup failure, and the per-workload generate-error skip (aggregateWorkloadPolicy err → continue silently drops a workload).
  • Consolidation dispatch getAggregatedData / sendConsolidatedSlugToChannel0%; listNamespaces0%; interleaved concurrent writes to the same CP key have no correctness test.

LOW

  • Is/NormalizeContainerProfileKind — only one branch hit (the plural→singular key-matching lynchpin); workloadPolicyName no-kind-label skip path.
  • networkpolicy/v2 + CIDR-collapse residual IP-parse/hash error branches (already 87–97%).

Already solid (for reference): the GNP workload-aggregation contract is now genuinely pinned (correct singular containerprofile key, cross-container union, one-policy-per-workload); networkpolicy/v2 87–97%; CIDR collapse 88–100%.

Entlein and others added 15 commits July 30, 2026 19:39
…NN merge

Migrate the server-side user-managed overlay merge (buildMergedProfile) from
the legacy ug- ApplicationProfile + NetworkNeighborhood pair to a single ug-
ContainerProfile via a new mergeUserCPIntoCP (flat single-container union that
mirrors the node-agent client-side merge). Provenance now stamps the ug- CP
source key/RV.

The AP/NN merge helpers and their provenance keys are marked deprecated. The
AP/NN CRD *types* are deliberately left untouched so this change carries no
generated-code (openapi/protobuf/deepcopy) impact; the type-level deprecation
and the full x86 codegen regeneration belong to the eventual CRD-removal change.
Tests migrated to feed a ug- ContainerProfile with equivalent merge assertions.

Signed-off-by: entlein <einentlein@gmail.com>
Remove the ApplicationProfile and NetworkNeighborhood custom resources
entirely: their API types, registration, aggregated-apiserver storage
backends, processors, and REST strategy/etcd wiring are gone, and the
generated code (deepcopy, clientset, listers, informers, applyconfiguration,
openapi, protobuf) is regenerated without them. ContainerProfile is the sole
runtime/user-facing profile resource.

- GeneratedNetworkPolicy is reworked to source from ContainerProfile (it
  projects the CP into the internal NetworkNeighborhood shape used by the
  policy generator), so that feature is preserved. The NetworkNeighborhood
  Go struct is retained as an internal, non-served intermediate only.
- The user-managed "ug-" overlay merge is ContainerProfile-only.
- Deprecated AP/NN merge helpers removed; tests migrated to ContainerProfile
  or dropped where they covered removed CRD-specific behaviour.

Signed-off-by: entlein <einentlein@gmail.com>
The kindQueues default config still spun up applicationprofiles/networkneighborhoods
queue workers, and the relevancy cleanup path still targeted applicationprofiles,
after the CRDs were removed. Point them at containerprofiles.

Signed-off-by: entlein <einentlein@gmail.com>
Rename MaxApplicationProfileSize -> MaxContainerProfileSize; drop the
ApplicationProfile decode path from cmd/migration; neutralize AP/NN comments
and the dead gob type-name default. The intentional GNP ContainerProfile->
NetworkNeighborhood projection is retained.

Signed-off-by: entlein <einentlein@gmail.com>
The ug-<workload> user-managed merge (an additive overlay unioned onto the
learned/observed ContainerProfile and republished as a derived merged profile)
has no consumers. Remove the merge engine (buildMergedProfile/mergeUserCPIntoCP),
the merged-first REST wrapper, the per-tick merged refresh + merged-CP GC, and
the Save/Get/Delete Merged storage-interface methods and their wiring. The
observed/learned ContainerProfile and the user-defined authoritative
ContainerProfile remain the only profile mechanisms.

Signed-off-by: entlein <einentlein@gmail.com>
Signed-off-by: entlein <einentlein@gmail.com>
The migrated network-policy fixtures (cp-operator.json + the np-operator/np.new
goldens) were moved but not yet consumed by a test. Add
TestGenerateNetworkPolicyFromFile: it loads the v1beta1 ContainerProfile fixture,
converts it to the internal type as the read path does, generates a policy, and
asserts the result reproduces the pre-migration golden output under the
generator's deterministic sort -- a diff-oracle that generating directly from a
ContainerProfile matches the removed NetworkNeighborhood intermediate path.

Add TestGenerateNetworkPolicy_PerContainerProfiles: two per-container profiles
for one workload each generate their own policy reflecting only that container's
network, with no cross-container bleed -- pinning the <label>-<containerName>
per-container binding contract on the storage side.

Signed-off-by: entlein <einentlein@gmail.com>
TestConsolidateData ran the fixtures through ConsolidateTimeSeries but asserted
only one field, so the consolidated output was never pinned. Add
TestConsolidateContainerProfileGolden: three time-series window fixtures folded
via mergeContainerProfileTS then DeflateContainerProfileSpec, frozen to a golden
(UPDATE_GOLDEN=1 to regenerate). Exercises opens wildcard collapse, arch/cap/
syscall dedup+sort, endpoint merge, rule-policy union, and ingress CIDR collapse.
Golden-regression freeze (complements the CP->NetworkPolicy differential oracle).

Signed-off-by: entlein <einentlein@gmail.com>
cp-operator.json carried over the deprecated singular dns/ipAddress fields from
the NetworkNeighborhood form it was migrated from. Author it in the
ContainerProfile-native representation instead: dnsNames/ipAddresses lists, no
deprecated backwards-compat fields. The golden GeneratedNetworkPolicy is
unchanged, confirming the native list fields generate the identical policy.

Signed-off-by: entlein <einentlein@gmail.com>
A direct client patch of a consolidated ContainerProfile could regress its
status from completed back to learning, because PreSave only guarded the
time-series ingestion path. Add the guard to the consolidated (non-TS) update
path: if the stored profile is already Completed and the incoming status is
Learning, revert it to Completed (the update still succeeds). Reading existing
metadata inside GuaranteedUpdate (which already holds the key's write lock)
needed a lock-free reader (GetContainerProfileMetadataNoLock) to avoid
self-deadlock. Pins Test_15_CompletedApCannotBecomeReadyAgain; Completed->
Completed amendments (Test_17) are unaffected.

Signed-off-by: entlein <einentlein@gmail.com>
…edNetworkPolicy

A GeneratedNetworkPolicy is workload-level: a NetworkPolicy selects pods, and
all containers of a pod share the network namespace, so a workload's policy
must union every container's ingress/egress. Before the ContainerProfile
migration this held because the store read one workload-level
NetworkNeighborhood per workload.

After the migration the store reads per-container ContainerProfiles
(replicaset-named, one object per container), but Get still did a single
literal-key lookup and GetList emitted one policy per profile. A
multi-container workload therefore produced one policy per container, and a
workload-level Get (<lower(kind)>-<name>, e.g. deployment-<name>) returned
NotFound because no ContainerProfile is named that way. Reproduced on a
two-container workload: two per-container profiles with split egress, a
workload-level Get returning NotFound, and an empty list.

Resolve by grouping a namespace's ContainerProfiles by the workload-kind /
workload-name labels (<lower(kind)>-<name>, the same name GenerateNetworkPolicy
derives), unioning their neighbors, and generating one policy per workload. Get
aggregates the requested workload's profiles; GetList emits one policy per
workload. The internal listing is forced to full-spec because the default list
path returns metadata only, which lacks the ingress/egress needed to generate.

Add generatednetworkpolicy_multicontainer_test.go pinning workload-level Get
aggregation and one-policy-per-workload GetList (both fail pre-fix), and correct
the two Get subtests that requested a profile by its object name rather than the
workload-level name.

Signed-off-by: entlein <einentlein@gmail.com>
… storage kind

ContainerProfiles are written under the SINGULAR storage kind segment
"containerprofile" (ContainerProfileKind) — the processor keys them via
BuildContainerProfileKey(id, "containerprofile"). The GeneratedNetworkPolicy
aggregation looked them up under the plural "containerprofiles" (only the REST
resource name), so the metadata query WHERE kind = 'containerprofiles' matched
zero rows: Get returned NotFound and GetList returned empty for every workload.

Observed live on a cluster: a two-container workload's per-container
ContainerProfiles persisted correctly, but `get generatednetworkpolicy
deployment-<name>` returned NotFound and the list was empty in every namespace,
including real learned profiles in kube-system.

Use ContainerProfileKind (the singular kind) for the internal lookup so the
listing matches the stored keys.

The unit tests masked this by seeding the fake store with the plural key; seed
them with the singular "containerprofile" segment the real storage uses, so a
plural lookup now misses and the tests fail on the pre-fix code.

Signed-off-by: entlein <einentlein@gmail.com>
…der load

Under sustained concurrent writes (many container profiles consolidating at
once, on slow emptyDir I/O) a writer could wait past SQLite's default 10s busy
timeout for the single-writer lock and fail with 'database is locked'. The insert
was dropped, so the container profile never reached Completed and consumers hung
— reproduced by component tests Test_09/20/21 timing out at 20m waiting for
completion (storage logs: 'insert metadata: sqlite: step: database is locked').

The pool already opens connections in WAL mode (sqlitex defaults Flags=0 to
OpenWAL); raise the busy timeout to 60s via PrepareConn so contended writes wait
for the lock instead of failing, and re-assert WAL + synchronous=NORMAL
explicitly so the config survives a Flags change.

Signed-off-by: entlein <einentlein@gmail.com>
… drop under load"

This reverts commit 809b840.

Signed-off-by: entlein <einentlein@gmail.com>
- cmd/migration: golden gob->JSON test (legacy uint64 fields round-trip verbatim
  incl. max-uint64; spec shape; unsupported-type/corrupt-stream/missing-file).
- containerprofile REST strategy: GetAttrs/SelectableFields expose the CP
  namespace/name/workload labels (catches the SBOMSyft copy-paste), NamespaceScoped,
  create/update/validate hooks.
- completed-immutability guard driven through the REAL GuaranteedUpdate + sqlite
  pool (not the aliasing fake): Completed->Learning reverts, TooLarge short-circuits;
  pointing the guard at the locking read deadlocks (proves the no-lock variant).
- ECS/Host key Build/Parse round-trips for all HostTypes + malformed branches.
- Is/NormalizeContainerProfileKind + workloadPolicyName table tests.
- GeneratedNetworkPolicy excludes non-available (TooLarge) profiles from Get/GetList.

Test-only; no production changes.

Signed-off-by: entlein <einentlein@gmail.com>
@entlein
entlein marked this pull request as ready for review July 30, 2026 19:07
@entlein

entlein commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

chicken is claiming this is ready for review... chicken also tried to delete a repo.. twice.. today. I wouldnt trust it.
@rabbit your turn, please review together with node-agent kubescape/node-agent#864
and take into account https://github.com/k8sstormcenter/node-agent/actions/runs/30534641643
and the helm chart PR
and the backend PR kubescape/backend#55
and the synchronizer PR kubescape/synchronizer#168

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 6

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
pkg/apis/softwarecomposition/v1beta1/generated.proto (1)

226-264: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Stale WARNING comment left over from ApplicationProfile removal.

Line 227 still says // WARNING report fields from ApplicationProfileContainer here, referencing a type that no longer exists. The sibling comment for the network fields (line 258) was correctly updated to "network fields", and pkg/apis/softwarecomposition/v1beta1/types.go line 236 already uses the correct wording ("execution/profile fields") for this same field group — this generated file appears to not have been fully regenerated/synced.

📝 Proposed fix
 message ContainerProfileSpec {
-  // WARNING report fields from ApplicationProfileContainer here
+  // WARNING report the execution/profile fields here
   repeated string architectures = 1;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/apis/softwarecomposition/v1beta1/generated.proto` around lines 226 - 264,
Update the stale warning comment in ContainerProfileSpec above architectures to
describe the execution/profile fields rather than referencing the removed
ApplicationProfileContainer type, matching the wording used by
ContainerProfileSpec in types.go; leave the field definitions and network
warning unchanged.
pkg/apiserver/apiserver.go (1)

141-144: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Stale comment references a removed second processor.

These comments still describe "processors" (plural) and "application/container storage backends," but the application-profile processor was removed — only containerProfileProcessor remains and only its CollapseSettings is wired (line 176). Update the comments to reflect the single-processor reality to avoid confusing future maintainers.

📝 Proposed fix
-	// Construct processors first so we can wire the CollapseConfiguration
-	// CRD provider into them AFTER the application/container storage
-	// backends are built — chicken-and-egg: the provider needs storage to
-	// read the CR, processors are baked into the storage backend.
+	// Construct the processor first so we can wire the CollapseConfiguration
+	// CRD provider into it AFTER the container storage backend is built —
+	// chicken-and-egg: the provider needs storage to read the CR, and the
+	// processor is baked into the storage backend.
-	// Wire the CollapseConfiguration CRD into the live deflate path: both
-	// processors read effective thresholds from CollapseConfiguration/default
+	// Wire the CollapseConfiguration CRD into the live deflate path: the
+	// container profile processor reads effective thresholds from CollapseConfiguration/default
	// (cluster-scoped) on every compaction, falling back to compiled-in
	// defaults when the CR is absent. Without this the CRD endpoint
	// registered below stores the manifest but never consults it — applying
	// the artifacts/collapseconfiguration-default-sample.yaml manifest would
	// be a no-op (matthyx review on apiserver.go:164, 2026-05-27).
-	//
-	// One shared provider closure is wired into both processors so a single
-	// CR update affects both compaction paths consistently.

Also applies to: 165-174

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/apiserver/apiserver.go` around lines 141 - 144, Update the comments
around containerProfileProcessor initialization and CollapseSettings wiring to
refer to the single container-profile processor, not plural processors or
application/container storage backends. Describe only the remaining processor
and its CollapseConfiguration provider dependency, keeping the implementation
unchanged.
🧹 Nitpick comments (10)
pkg/apis/softwarecomposition/networkpolicy/v2/networkpolicy_test.go (2)

443-489: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Duplicate table entry. The policy_with_known_servers case at Lines 443-588 is byte-identical in name, input and expectations to the one at Lines 297-442; t.Run will just suffix the second subtest name. Drop one.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/apis/softwarecomposition/networkpolicy/v2/networkpolicy_test.go` around
lines 443 - 489, Remove the duplicate policy_with_known_servers table entry,
keeping only one identical test case and its expectations in the surrounding
table-driven test.

299-337: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Migrated expectations outside ingress/egress are unverified. compareNP diffs only Spec.Spec.Ingress/Egress, so every metadata, name, apiVersion and PoliciesRef expectation in the tests and goldens is inert — which is why the divergences below all pass unnoticed.

  • pkg/apis/softwarecomposition/networkpolicy/v2/networkpolicy_test.go#L299-L337: assert PoliciesRef (and Spec.Spec.PodSelector) explicitly for the known-servers case, and normalize the stale .../v1 TypeMeta.APIVersion to .../v1beta1.
  • pkg/apis/softwarecomposition/networkpolicy/v2/testdata/cp-operator.json#L13-L22: either add kubescape.io/workload-container-name to both goldens' metadata.labels or drop it from the fixture.
  • pkg/apis/softwarecomposition/networkpolicy/v2/testdata/np.new.json#L50-L52: set the embedded NetworkPolicy name to deployment-operator, matching the generator and np-operator.json.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/apis/softwarecomposition/networkpolicy/v2/networkpolicy_test.go` around
lines 299 - 337, Update
pkg/apis/softwarecomposition/networkpolicy/v2/networkpolicy_test.go:299-337 to
explicitly assert PoliciesRef and Spec.Spec.PodSelector for the known-servers
case, and normalize the expected TypeMeta.APIVersion to the v1beta1 value. In
pkg/apis/softwarecomposition/networkpolicy/v2/testdata/cp-operator.json:13-22,
add kubescape.io/workload-container-name to both golden metadata.labels entries
or remove it from the fixture. In
pkg/apis/softwarecomposition/networkpolicy/v2/testdata/np.new.json:50-52, change
the embedded NetworkPolicy name to deployment-operator.
pkg/apis/softwarecomposition/networkpolicy/v2/networkpolicy.go (1)

24-50: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider not mutating and not aliasing the caller's label map.

Line 39 deletes from cp.Labels in place, and Lines 50/77 alias that same map into both output objects. Callers now pass pointers into a listed []ContainerProfile (generatednetworkpolicy.go Get/GetList), so the input is silently modified and the two generated objects share one map. Behavior is unchanged from the previous nn version, but a shallow copy would make this robust.

♻️ Proposed defensive copy
-	delete(cp.Labels, helpersv1.TemplateHashKey)
+	labels := make(map[string]string, len(cp.Labels))
+	for k, v := range cp.Labels {
+		if k == helpersv1.TemplateHashKey {
+			continue
+		}
+		labels[k] = v
+	}

Then use labels (and a second copy) for networkPolicy.ObjectMeta.Labels and generatedNetworkPolicy.ObjectMeta.Labels.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/apis/softwarecomposition/networkpolicy/v2/networkpolicy.go` around lines
24 - 50, Update GenerateNetworkPolicy to create a defensive copy of cp.Labels
before removing TemplateHashKey, so the caller’s ContainerProfile is not
mutated. Use the cleaned labels for networkPolicy.ObjectMeta.Labels and provide
a separate copy for generatedNetworkPolicy.ObjectMeta.Labels, preventing the two
output objects from sharing the same map.
pkg/apis/softwarecomposition/networkpolicy/v2/testdata/cp-operator.json (1)

13-22: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Fixture labels diverge from the goldens' labels.

kubescape.io/workload-container-name is set here, but neither golden's metadata.labels (np-operator.json Lines 6-13, np.new.json Lines 8-15) contains it, and the generator only strips instance-template-hash. This passes solely because compareNP ignores metadata, which weakens the "diff-oracle" claim in networkpolicy_file_test.go. Either add the label to the goldens or drop it from the fixture.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/apis/softwarecomposition/networkpolicy/v2/testdata/cp-operator.json`
around lines 13 - 22, Align the fixture and golden metadata labels by either
adding kubescape.io/workload-container-name to both golden files or removing it
from cp-operator.json; keep compareNP unchanged so metadata differences remain
detectable by networkpolicy_file_test.go.
pkg/apis/softwarecomposition/networkpolicy/v2/networkpolicy_file_test.go (1)

44-61: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Decode known-servers through the v1beta1 conversion path.

known-servers.json is currently decoded into []softwarecomposition.KnownServer, which works only because Go matches the camelCase JSON keys (ipBlock, server, name) to the internal exported fields; this is fragile and diverges from the profile fixture path. Decode as softwarecompositionv1beta1.KnownServer and convert to the internal type for consistency.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/apis/softwarecomposition/networkpolicy/v2/networkpolicy_file_test.go`
around lines 44 - 61, Update the known-servers fixture setup in the test to
unmarshal into a slice of softwarecompositionv1beta1.KnownServer, then convert
each entry through the v1beta1 conversion path into the internal
[]softwarecomposition.KnownServer used by the generator. Replace the direct
json.Unmarshal into knownServers while preserving the existing fixture error
handling and resulting internal collection.
pkg/registry/file/dynamicpathdetector/tests/execargs_wildcard_ap_test.go (1)

39-39: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Test names still say "AP" but now test ContainerProfile.

execAP/matchAP were fully replaced by execCP/matchCP, but the enclosing test function names (TestAP_LiteralStarArg_DoesNotBroaden, TestAP_DynamicArg_IsSingleSegmentWildcard, TestAP_MultiArgWildcard_AbsorbsTail, TestAP_LiteralStarVsDynamic_DivergeOnSameInput) weren't renamed, which could mislead future readers into thinking these exercise ApplicationProfile.

Also applies to: 62-62, 85-85, 111-111

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/registry/file/dynamicpathdetector/tests/execargs_wildcard_ap_test.go` at
line 39, Rename the affected test functions from the AP prefix to CP to match
the ContainerProfile behavior exercised by execCP and matchCP. Update
TestAP_LiteralStarArg_DoesNotBroaden, TestAP_DynamicArg_IsSingleSegmentWildcard,
TestAP_MultiArgWildcard_AbsorbsTail, and
TestAP_LiteralStarVsDynamic_DivergeOnSameInput without changing their test
logic.
pkg/registry/file/networkneighborhood_ipcollapse.go (1)

25-47: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value

Minor aliasing risk when merging duplicate identifiers.

out[index].DNSNames/.Ports still reference the first occurrence's backing array; the in-place append at Lines 34-35 can mutate that shared array before it's replaged by DeflateSortString/DeflateStringer. Low risk given current callers discard in after the call, but worth a defensive copy to avoid surprises if this helper is reused elsewhere.

♻️ Suggested defensive copy
 		if index, ok := seen[item.Identifier]; ok {
-			out[index].DNSNames = append(out[index].DNSNames, item.DNSNames...)
-			out[index].Ports = append(out[index].Ports, item.Ports...)
+			out[index].DNSNames = append(append([]string(nil), out[index].DNSNames...), item.DNSNames...)
+			out[index].Ports = append(append([]softwarecomposition.NetworkPort(nil), out[index].Ports...), item.Ports...)
 			toDeflate.Add(index)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/registry/file/networkneighborhood_ipcollapse.go` around lines 25 - 47,
Update deflateNetworkNeighbors so the first occurrence’s DNSNames and Ports
slices are defensively copied before duplicate items are appended, preventing
merged output from sharing backing arrays with input data. Preserve the existing
duplicate aggregation and deflation behavior.
pkg/registry/file/containerprofile_processor_test.go (1)

184-242: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Concurrent consolidation test no longer verifies output correctness.

TestConsolidateTimeSeries_Concurrent_NoDeadlock now only checks for deadlocks and pool leaks after removing the AP verification block; it no longer confirms the consolidated ContainerProfile content is correct under concurrent dispatch (same staged inputs as TestConsolidateData). A regression that produces wrong-but-non-deadlocking output would slip through.

♻️ Suggested addition before the pool-leak check
	conn, err := pool.Take(ctx)
	require.NoError(t, err)
	containerProfile := softwarecomposition.ContainerProfile{}
	key := "/spdx.softwarecomposition.kubescape.io/containerprofile/kube-system/replicaset-coredns-5d78c9869d-coredns-185f-129c"
	require.NoError(t, s.GetWithConn(ctx, conn, key, storage.GetOptions{}, &containerProfile))
	assert.Equal(t, softwarecomposition.CallID("test-call-id"), containerProfile.Spec.IdentifiedCallStacks[0].CallID)
	pool.Put(conn)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/registry/file/containerprofile_processor_test.go` around lines 184 - 242,
Restore an output-correctness assertion in
TestConsolidateTimeSeries_Concurrent_NoDeadlock after the final consolidation
and before the pool-leak check. Reuse pool, s, and ctx to acquire a connection,
fetch the expected consolidated ContainerProfile with GetWithConn for the known
coredns key, assert its first identified call stack has CallID "test-call-id",
and return the connection to the pool while preserving the existing deadlock and
leak checks.
cmd/migration/main_test.go (1)

284-286: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Drop the import-keeper instead of a package-level blank var.

softwarecomposition isn't otherwise needed in this test file; removing the import is cleaner than anchoring it with var _ = softwarecomposition.HTTPEndpoint{}.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/migration/main_test.go` around lines 284 - 286, Remove the package-level
blank variable referencing softwarecomposition.HTTPEndpoint and delete the
now-unused softwarecomposition import from the test file, leaving the
surrounding migration fixture unchanged.
pkg/registry/softwarecomposition/containerprofile/strategy_test.go (1)

120-124: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider renaming the copy-pasted symbols this guard pins.

The guard asserts on SbomSyftStrategy inside the containerprofile package (same for MatchWorkloadConfigurationScan at Line 76) — exactly the copy-paste heritage the file header warns about. Renaming these in strategy.go to ContainerProfileStrategy/MatchContainerProfile would make the tests self-documenting; the package is internal so the churn is contained.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/registry/softwarecomposition/containerprofile/strategy_test.go` around
lines 120 - 124, Rename the copy-pasted strategy symbols in strategy.go from
SbomSyftStrategy to ContainerProfileStrategy and MatchWorkloadConfigurationScan
to MatchContainerProfile, then update all references in the containerprofile
package, including the compile-time interface guards and tests. Preserve the
existing behavior and interfaces.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cmd/migration/main_test.go`:
- Line 48: Replace both exec.Command call sites in the migration test with
exec.CommandContext, including the build invocation and the second command
around the affected lines. Add the context import and pass an appropriate
test-scoped context so hung build or run processes are bounded while preserving
the existing arguments and behavior.

In `@pkg/apis/softwarecomposition/networkpolicy/v2/testdata/np.new.json`:
- Around line 50-52: Update the embedded NetworkPolicy metadata name in
np.new.json to match the generator’s deployment-operator naming and the sibling
golden fixture, replacing the stale replicaset-based name while preserving the
namespace and policy rules.

In `@pkg/registry/file/cleanup.go`:
- Around line 72-77: The cleanup registration for "containerprofiles" lacks
coverage for both relevancy states. Add a unit test near the cleanup setup that
verifies relevancyEnabled=true registers deleteMissingInstanceIdAnnotation and
deleteMissingWlidAnnotation in the exact expected handler set, while
relevancyEnabled=false leaves those handlers unregistered.

In `@pkg/registry/file/containerprofile_processor.go`:
- Around line 186-201: Update the GetContainerProfileMetadataNoLock error
handling in the completed-immutability check to distinguish storage.IsNotFound
from other errors. Keep the create/no-existing-profile path unchanged for
not-found errors, but log any other storage failure with the relevant key and
error details before proceeding, matching the diagnostic behavior of the nearby
SBOM lookup.

In `@pkg/registry/file/generatednetworkpolicy_multicontainer_test.go`:
- Around line 26-32: Update the comment above the generated network policy tests
to remove the outdated claim that storage performs a literal-key Get, loses
per-workload aggregation, and causes the tests to fail. Reword it to describe
the current pinned aggregation contract while retaining the relevant
per-container naming and workload-level behavior details.

In `@pkg/registry/file/generatednetworkpolicy.go`:
- Around line 176-193: Update the single-workload lookup around
listNamespaceContainerProfiles to avoid truncated in-memory scans: apply the
workload-name selection through the storage.ListOptions predicate when
supported, or paginate using continuation tokens until all namespace profiles
are examined. Preserve the existing availability filtering and return the
matching profile, only returning storage.NewKeyNotFoundError after the complete
filtered search.

---

Outside diff comments:
In `@pkg/apis/softwarecomposition/v1beta1/generated.proto`:
- Around line 226-264: Update the stale warning comment in ContainerProfileSpec
above architectures to describe the execution/profile fields rather than
referencing the removed ApplicationProfileContainer type, matching the wording
used by ContainerProfileSpec in types.go; leave the field definitions and
network warning unchanged.

In `@pkg/apiserver/apiserver.go`:
- Around line 141-144: Update the comments around containerProfileProcessor
initialization and CollapseSettings wiring to refer to the single
container-profile processor, not plural processors or application/container
storage backends. Describe only the remaining processor and its
CollapseConfiguration provider dependency, keeping the implementation unchanged.

---

Nitpick comments:
In `@cmd/migration/main_test.go`:
- Around line 284-286: Remove the package-level blank variable referencing
softwarecomposition.HTTPEndpoint and delete the now-unused softwarecomposition
import from the test file, leaving the surrounding migration fixture unchanged.

In `@pkg/apis/softwarecomposition/networkpolicy/v2/networkpolicy_file_test.go`:
- Around line 44-61: Update the known-servers fixture setup in the test to
unmarshal into a slice of softwarecompositionv1beta1.KnownServer, then convert
each entry through the v1beta1 conversion path into the internal
[]softwarecomposition.KnownServer used by the generator. Replace the direct
json.Unmarshal into knownServers while preserving the existing fixture error
handling and resulting internal collection.

In `@pkg/apis/softwarecomposition/networkpolicy/v2/networkpolicy_test.go`:
- Around line 443-489: Remove the duplicate policy_with_known_servers table
entry, keeping only one identical test case and its expectations in the
surrounding table-driven test.
- Around line 299-337: Update
pkg/apis/softwarecomposition/networkpolicy/v2/networkpolicy_test.go:299-337 to
explicitly assert PoliciesRef and Spec.Spec.PodSelector for the known-servers
case, and normalize the expected TypeMeta.APIVersion to the v1beta1 value. In
pkg/apis/softwarecomposition/networkpolicy/v2/testdata/cp-operator.json:13-22,
add kubescape.io/workload-container-name to both golden metadata.labels entries
or remove it from the fixture. In
pkg/apis/softwarecomposition/networkpolicy/v2/testdata/np.new.json:50-52, change
the embedded NetworkPolicy name to deployment-operator.

In `@pkg/apis/softwarecomposition/networkpolicy/v2/networkpolicy.go`:
- Around line 24-50: Update GenerateNetworkPolicy to create a defensive copy of
cp.Labels before removing TemplateHashKey, so the caller’s ContainerProfile is
not mutated. Use the cleaned labels for networkPolicy.ObjectMeta.Labels and
provide a separate copy for generatedNetworkPolicy.ObjectMeta.Labels, preventing
the two output objects from sharing the same map.

In `@pkg/apis/softwarecomposition/networkpolicy/v2/testdata/cp-operator.json`:
- Around line 13-22: Align the fixture and golden metadata labels by either
adding kubescape.io/workload-container-name to both golden files or removing it
from cp-operator.json; keep compareNP unchanged so metadata differences remain
detectable by networkpolicy_file_test.go.

In `@pkg/registry/file/containerprofile_processor_test.go`:
- Around line 184-242: Restore an output-correctness assertion in
TestConsolidateTimeSeries_Concurrent_NoDeadlock after the final consolidation
and before the pool-leak check. Reuse pool, s, and ctx to acquire a connection,
fetch the expected consolidated ContainerProfile with GetWithConn for the known
coredns key, assert its first identified call stack has CallID "test-call-id",
and return the connection to the pool while preserving the existing deadlock and
leak checks.

In `@pkg/registry/file/dynamicpathdetector/tests/execargs_wildcard_ap_test.go`:
- Line 39: Rename the affected test functions from the AP prefix to CP to match
the ContainerProfile behavior exercised by execCP and matchCP. Update
TestAP_LiteralStarArg_DoesNotBroaden, TestAP_DynamicArg_IsSingleSegmentWildcard,
TestAP_MultiArgWildcard_AbsorbsTail, and
TestAP_LiteralStarVsDynamic_DivergeOnSameInput without changing their test
logic.

In `@pkg/registry/file/networkneighborhood_ipcollapse.go`:
- Around line 25-47: Update deflateNetworkNeighbors so the first occurrence’s
DNSNames and Ports slices are defensively copied before duplicate items are
appended, preventing merged output from sharing backing arrays with input data.
Preserve the existing duplicate aggregation and deflation behavior.

In `@pkg/registry/softwarecomposition/containerprofile/strategy_test.go`:
- Around line 120-124: Rename the copy-pasted strategy symbols in strategy.go
from SbomSyftStrategy to ContainerProfileStrategy and
MatchWorkloadConfigurationScan to MatchContainerProfile, then update all
references in the containerprofile package, including the compile-time interface
guards and tests. Preserve the existing behavior and interfaces.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 1a9c937a-7fda-489d-8d43-55cc8b4ff472

📥 Commits

Reviewing files that changed from the base of the PR and between 72c61d4 and 804bd18.

⛔ Files ignored due to path filters (25)
  • pkg/apis/softwarecomposition/v1beta1/generated.pb.go is excluded by !**/*.pb.go
  • pkg/apis/softwarecomposition/v1beta1/generated.protomessage.pb.go is excluded by !**/*.pb.go
  • pkg/generated/applyconfiguration/softwarecomposition/v1beta1/applicationprofile.go is excluded by !**/generated/**
  • pkg/generated/applyconfiguration/softwarecomposition/v1beta1/applicationprofilecontainer.go is excluded by !**/generated/**
  • pkg/generated/applyconfiguration/softwarecomposition/v1beta1/applicationprofilespec.go is excluded by !**/generated/**
  • pkg/generated/applyconfiguration/softwarecomposition/v1beta1/containerprofilespec.go is excluded by !**/generated/**
  • pkg/generated/applyconfiguration/softwarecomposition/v1beta1/networkneighborhood.go is excluded by !**/generated/**
  • pkg/generated/applyconfiguration/softwarecomposition/v1beta1/networkneighborhoodcontainer.go is excluded by !**/generated/**
  • pkg/generated/applyconfiguration/softwarecomposition/v1beta1/networkneighborhoodspec.go is excluded by !**/generated/**
  • pkg/generated/applyconfiguration/utils.go is excluded by !**/generated/**
  • pkg/generated/clientset/versioned/typed/softwarecomposition/v1beta1/applicationprofile.go is excluded by !**/generated/**
  • pkg/generated/clientset/versioned/typed/softwarecomposition/v1beta1/fake/fake_applicationprofile.go is excluded by !**/generated/**
  • pkg/generated/clientset/versioned/typed/softwarecomposition/v1beta1/fake/fake_networkneighborhood.go is excluded by !**/generated/**
  • pkg/generated/clientset/versioned/typed/softwarecomposition/v1beta1/fake/fake_softwarecomposition_client.go is excluded by !**/generated/**
  • pkg/generated/clientset/versioned/typed/softwarecomposition/v1beta1/generated_expansion.go is excluded by !**/generated/**
  • pkg/generated/clientset/versioned/typed/softwarecomposition/v1beta1/networkneighborhood.go is excluded by !**/generated/**
  • pkg/generated/clientset/versioned/typed/softwarecomposition/v1beta1/softwarecomposition_client.go is excluded by !**/generated/**
  • pkg/generated/informers/externalversions/generic.go is excluded by !**/generated/**
  • pkg/generated/informers/externalversions/softwarecomposition/v1beta1/applicationprofile.go is excluded by !**/generated/**
  • pkg/generated/informers/externalversions/softwarecomposition/v1beta1/interface.go is excluded by !**/generated/**
  • pkg/generated/informers/externalversions/softwarecomposition/v1beta1/networkneighborhood.go is excluded by !**/generated/**
  • pkg/generated/listers/softwarecomposition/v1beta1/applicationprofile.go is excluded by !**/generated/**
  • pkg/generated/listers/softwarecomposition/v1beta1/expansion_generated.go is excluded by !**/generated/**
  • pkg/generated/listers/softwarecomposition/v1beta1/networkneighborhood.go is excluded by !**/generated/**
  • pkg/generated/openapi/zz_generated.openapi.go is excluded by !**/generated/**
📒 Files selected for processing (74)
  • cmd/migration/main.go
  • cmd/migration/main_test.go
  • pkg/apis/softwarecomposition/network_types.go
  • pkg/apis/softwarecomposition/networkpolicy/v2/networkpolicy.go
  • pkg/apis/softwarecomposition/networkpolicy/v2/networkpolicy_file_test.go
  • pkg/apis/softwarecomposition/networkpolicy/v2/networkpolicy_test.go
  • pkg/apis/softwarecomposition/networkpolicy/v2/testdata/cp-operator.json
  • pkg/apis/softwarecomposition/networkpolicy/v2/testdata/known-servers.json
  • pkg/apis/softwarecomposition/networkpolicy/v2/testdata/np-operator.json
  • pkg/apis/softwarecomposition/networkpolicy/v2/testdata/np.new.json
  • pkg/apis/softwarecomposition/register.go
  • pkg/apis/softwarecomposition/types.go
  • pkg/apis/softwarecomposition/types_test.go
  • pkg/apis/softwarecomposition/v1beta1/generated.proto
  • pkg/apis/softwarecomposition/v1beta1/network_types.go
  • pkg/apis/softwarecomposition/v1beta1/network_types_protobuf_test.go
  • pkg/apis/softwarecomposition/v1beta1/networkpolicy/v2/networkpolicy.go
  • pkg/apis/softwarecomposition/v1beta1/networkpolicy/v2/networkpolicy_test.go
  • pkg/apis/softwarecomposition/v1beta1/networkpolicy/v2/testdata/nn-operator.json
  • pkg/apis/softwarecomposition/v1beta1/register.go
  • pkg/apis/softwarecomposition/v1beta1/types.go
  • pkg/apis/softwarecomposition/v1beta1/zz_generated.conversion.go
  • pkg/apis/softwarecomposition/v1beta1/zz_generated.deepcopy.go
  • pkg/apis/softwarecomposition/v1beta1/zz_generated.model_name.go
  • pkg/apis/softwarecomposition/zz_generated.deepcopy.go
  • pkg/apiserver/apiserver.go
  • pkg/config/config.go
  • pkg/config/config_test.go
  • pkg/registry/file/applicationprofile_processor.go
  • pkg/registry/file/applicationprofile_processor_collapse_provider_test.go
  • pkg/registry/file/applicationprofile_processor_test.go
  • pkg/registry/file/applicationprofile_storage.go
  • pkg/registry/file/cleanup.go
  • pkg/registry/file/containerprofile_aggregator_test.go
  • pkg/registry/file/containerprofile_completed_guard_realmech_test.go
  • pkg/registry/file/containerprofile_completed_guard_test.go
  • pkg/registry/file/containerprofile_consolidate_golden_test.go
  • pkg/registry/file/containerprofile_kind_test.go
  • pkg/registry/file/containerprofile_processor.go
  • pkg/registry/file/containerprofile_processor_collapse_provider_test.go
  • pkg/registry/file/containerprofile_processor_test.go
  • pkg/registry/file/containerprofile_rest_storage.go
  • pkg/registry/file/containerprofile_storage.go
  • pkg/registry/file/containerprofile_storage_interface.go
  • pkg/registry/file/containerprofile_user_managed.go
  • pkg/registry/file/containerprofile_user_managed_test.go
  • pkg/registry/file/dynamicpathdetector/tests/compare_exec_args_test.go
  • pkg/registry/file/dynamicpathdetector/tests/coverage_test.go
  • pkg/registry/file/dynamicpathdetector/tests/execargs_wildcard_ap_test.go
  • pkg/registry/file/dynamicpathdetector/types.go
  • pkg/registry/file/generatednetworkpolicy.go
  • pkg/registry/file/generatednetworkpolicy_multicontainer_test.go
  • pkg/registry/file/generatednetworkpolicy_test.go
  • pkg/registry/file/networkneighborhood_ipcollapse.go
  • pkg/registry/file/networkneighborhood_processor.go
  • pkg/registry/file/networkneighborhood_processor_test.go
  • pkg/registry/file/networkneighborhood_storage.go
  • pkg/registry/file/sqlite_keyroundtrip_test.go
  • pkg/registry/file/storage.go
  • pkg/registry/file/storage_test.go
  • pkg/registry/file/testdata/consolidate_golden/consolidated.golden.json
  • pkg/registry/file/testdata/consolidate_golden/window_1.json
  • pkg/registry/file/testdata/consolidate_golden/window_2.json
  • pkg/registry/file/testdata/consolidate_golden/window_3.json
  • pkg/registry/file/testdata/expectedFilesToDelete.json
  • pkg/registry/softwarecomposition/applicationprofile/etcd.go
  • pkg/registry/softwarecomposition/applicationprofile/strategy.go
  • pkg/registry/softwarecomposition/applicationprofile/strategy_test.go
  • pkg/registry/softwarecomposition/collapseconfiguration/etcd.go
  • pkg/registry/softwarecomposition/collapseconfiguration/strategy_test.go
  • pkg/registry/softwarecomposition/containerprofile/strategy_test.go
  • pkg/registry/softwarecomposition/networkneighborhood/etcd.go
  • pkg/registry/softwarecomposition/networkneighborhood/strategy.go
  • pkg/registry/softwarecomposition/networkneighborhood/strategy_test.go
💤 Files with no reviewable changes (28)
  • pkg/apis/softwarecomposition/v1beta1/networkpolicy/v2/testdata/nn-operator.json
  • pkg/apis/softwarecomposition/v1beta1/register.go
  • pkg/apis/softwarecomposition/v1beta1/networkpolicy/v2/networkpolicy.go
  • pkg/registry/softwarecomposition/applicationprofile/etcd.go
  • pkg/registry/file/applicationprofile_processor_test.go
  • pkg/registry/softwarecomposition/applicationprofile/strategy_test.go
  • pkg/registry/file/networkneighborhood_processor_test.go
  • pkg/apis/softwarecomposition/v1beta1/networkpolicy/v2/networkpolicy_test.go
  • pkg/registry/file/applicationprofile_processor_collapse_provider_test.go
  • pkg/apis/softwarecomposition/register.go
  • pkg/registry/file/testdata/expectedFilesToDelete.json
  • pkg/registry/file/networkneighborhood_storage.go
  • pkg/registry/softwarecomposition/networkneighborhood/strategy_test.go
  • pkg/apis/softwarecomposition/network_types.go
  • pkg/registry/file/applicationprofile_processor.go
  • pkg/registry/file/networkneighborhood_processor.go
  • pkg/registry/softwarecomposition/applicationprofile/strategy.go
  • pkg/registry/softwarecomposition/networkneighborhood/etcd.go
  • pkg/apis/softwarecomposition/v1beta1/network_types.go
  • pkg/apis/softwarecomposition/v1beta1/zz_generated.model_name.go
  • pkg/registry/softwarecomposition/networkneighborhood/strategy.go
  • pkg/registry/file/containerprofile_user_managed.go
  • pkg/registry/file/containerprofile_rest_storage.go
  • pkg/apis/softwarecomposition/v1beta1/zz_generated.deepcopy.go
  • pkg/registry/file/applicationprofile_storage.go
  • pkg/apis/softwarecomposition/zz_generated.deepcopy.go
  • pkg/registry/file/containerprofile_user_managed_test.go
  • pkg/apis/softwarecomposition/v1beta1/zz_generated.conversion.go

Comment thread cmd/migration/main_test.go Outdated
Comment on lines +72 to 77
// only if relevancy is enabled, delete container profiles with missing
// instanceId or wlid annotations.
if relevancyEnabled {
logger.L().Debug("relevancy is enabled, adding additional cleanup handlers")
resourceKindToHandler["applicationprofiles"] = append(resourceKindToHandler["applicationprofiles"], deleteMissingInstanceIdAnnotation, deleteMissingWlidAnnotation)
resourceKindToHandler["containerprofiles"] = append(resourceKindToHandler["containerprofiles"], deleteMissingInstanceIdAnnotation, deleteMissingWlidAnnotation)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Add the requested lifecycle-contract test for containerprofiles cleanup.

A past reviewer asked for an explicit test here since ContainerProfiles have a different lifecycle than ApplicationProfiles did, but no test covering deleteMissingInstanceIdAnnotation/deleteMissingWlidAnnotation being wired onto "containerprofiles" is included in this change set. Please add a unit test (e.g. in cleanup_test.go) asserting the exact handler set registered for "containerprofiles" when relevancyEnabled is true/false.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/registry/file/cleanup.go` around lines 72 - 77, The cleanup registration
for "containerprofiles" lacks coverage for both relevancy states. Add a unit
test near the cleanup setup that verifies relevancyEnabled=true registers
deleteMissingInstanceIdAnnotation and deleteMissingWlidAnnotation in the exact
expected handler set, while relevancyEnabled=false leaves those handlers
unregistered.

Comment thread pkg/registry/file/containerprofile_processor.go
Comment thread pkg/registry/file/generatednetworkpolicy_multicontainer_test.go Outdated
Comment thread pkg/registry/file/generatednetworkpolicy.go

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Inline review comments failed to post. This is likely due to GitHub's internal server error or limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.

Actionable comments posted: 6

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
pkg/apis/softwarecomposition/v1beta1/generated.proto (1)

226-264: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Stale WARNING comment left over from ApplicationProfile removal.

Line 227 still says // WARNING report fields from ApplicationProfileContainer here, referencing a type that no longer exists. The sibling comment for the network fields (line 258) was correctly updated to "network fields", and pkg/apis/softwarecomposition/v1beta1/types.go line 236 already uses the correct wording ("execution/profile fields") for this same field group — this generated file appears to not have been fully regenerated/synced.

📝 Proposed fix
 message ContainerProfileSpec {
-  // WARNING report fields from ApplicationProfileContainer here
+  // WARNING report the execution/profile fields here
   repeated string architectures = 1;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/apis/softwarecomposition/v1beta1/generated.proto` around lines 226 - 264,
Update the stale warning comment in ContainerProfileSpec above architectures to
describe the execution/profile fields rather than referencing the removed
ApplicationProfileContainer type, matching the wording used by
ContainerProfileSpec in types.go; leave the field definitions and network
warning unchanged.
pkg/apiserver/apiserver.go (1)

141-144: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Stale comment references a removed second processor.

These comments still describe "processors" (plural) and "application/container storage backends," but the application-profile processor was removed — only containerProfileProcessor remains and only its CollapseSettings is wired (line 176). Update the comments to reflect the single-processor reality to avoid confusing future maintainers.

📝 Proposed fix
-	// Construct processors first so we can wire the CollapseConfiguration
-	// CRD provider into them AFTER the application/container storage
-	// backends are built — chicken-and-egg: the provider needs storage to
-	// read the CR, processors are baked into the storage backend.
+	// Construct the processor first so we can wire the CollapseConfiguration
+	// CRD provider into it AFTER the container storage backend is built —
+	// chicken-and-egg: the provider needs storage to read the CR, and the
+	// processor is baked into the storage backend.
-	// Wire the CollapseConfiguration CRD into the live deflate path: both
-	// processors read effective thresholds from CollapseConfiguration/default
+	// Wire the CollapseConfiguration CRD into the live deflate path: the
+	// container profile processor reads effective thresholds from CollapseConfiguration/default
	// (cluster-scoped) on every compaction, falling back to compiled-in
	// defaults when the CR is absent. Without this the CRD endpoint
	// registered below stores the manifest but never consults it — applying
	// the artifacts/collapseconfiguration-default-sample.yaml manifest would
	// be a no-op (matthyx review on apiserver.go:164, 2026-05-27).
-	//
-	// One shared provider closure is wired into both processors so a single
-	// CR update affects both compaction paths consistently.

Also applies to: 165-174

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/apiserver/apiserver.go` around lines 141 - 144, Update the comments
around containerProfileProcessor initialization and CollapseSettings wiring to
refer to the single container-profile processor, not plural processors or
application/container storage backends. Describe only the remaining processor
and its CollapseConfiguration provider dependency, keeping the implementation
unchanged.
🧹 Nitpick comments (10)
pkg/apis/softwarecomposition/networkpolicy/v2/networkpolicy_test.go (2)

443-489: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Duplicate table entry. The policy_with_known_servers case at Lines 443-588 is byte-identical in name, input and expectations to the one at Lines 297-442; t.Run will just suffix the second subtest name. Drop one.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/apis/softwarecomposition/networkpolicy/v2/networkpolicy_test.go` around
lines 443 - 489, Remove the duplicate policy_with_known_servers table entry,
keeping only one identical test case and its expectations in the surrounding
table-driven test.

299-337: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Migrated expectations outside ingress/egress are unverified. compareNP diffs only Spec.Spec.Ingress/Egress, so every metadata, name, apiVersion and PoliciesRef expectation in the tests and goldens is inert — which is why the divergences below all pass unnoticed.

  • pkg/apis/softwarecomposition/networkpolicy/v2/networkpolicy_test.go#L299-L337: assert PoliciesRef (and Spec.Spec.PodSelector) explicitly for the known-servers case, and normalize the stale .../v1 TypeMeta.APIVersion to .../v1beta1.
  • pkg/apis/softwarecomposition/networkpolicy/v2/testdata/cp-operator.json#L13-L22: either add kubescape.io/workload-container-name to both goldens' metadata.labels or drop it from the fixture.
  • pkg/apis/softwarecomposition/networkpolicy/v2/testdata/np.new.json#L50-L52: set the embedded NetworkPolicy name to deployment-operator, matching the generator and np-operator.json.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/apis/softwarecomposition/networkpolicy/v2/networkpolicy_test.go` around
lines 299 - 337, Update
pkg/apis/softwarecomposition/networkpolicy/v2/networkpolicy_test.go:299-337 to
explicitly assert PoliciesRef and Spec.Spec.PodSelector for the known-servers
case, and normalize the expected TypeMeta.APIVersion to the v1beta1 value. In
pkg/apis/softwarecomposition/networkpolicy/v2/testdata/cp-operator.json:13-22,
add kubescape.io/workload-container-name to both golden metadata.labels entries
or remove it from the fixture. In
pkg/apis/softwarecomposition/networkpolicy/v2/testdata/np.new.json:50-52, change
the embedded NetworkPolicy name to deployment-operator.
pkg/apis/softwarecomposition/networkpolicy/v2/networkpolicy.go (1)

24-50: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider not mutating and not aliasing the caller's label map.

Line 39 deletes from cp.Labels in place, and Lines 50/77 alias that same map into both output objects. Callers now pass pointers into a listed []ContainerProfile (generatednetworkpolicy.go Get/GetList), so the input is silently modified and the two generated objects share one map. Behavior is unchanged from the previous nn version, but a shallow copy would make this robust.

♻️ Proposed defensive copy
-	delete(cp.Labels, helpersv1.TemplateHashKey)
+	labels := make(map[string]string, len(cp.Labels))
+	for k, v := range cp.Labels {
+		if k == helpersv1.TemplateHashKey {
+			continue
+		}
+		labels[k] = v
+	}

Then use labels (and a second copy) for networkPolicy.ObjectMeta.Labels and generatedNetworkPolicy.ObjectMeta.Labels.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/apis/softwarecomposition/networkpolicy/v2/networkpolicy.go` around lines
24 - 50, Update GenerateNetworkPolicy to create a defensive copy of cp.Labels
before removing TemplateHashKey, so the caller’s ContainerProfile is not
mutated. Use the cleaned labels for networkPolicy.ObjectMeta.Labels and provide
a separate copy for generatedNetworkPolicy.ObjectMeta.Labels, preventing the two
output objects from sharing the same map.
pkg/apis/softwarecomposition/networkpolicy/v2/testdata/cp-operator.json (1)

13-22: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Fixture labels diverge from the goldens' labels.

kubescape.io/workload-container-name is set here, but neither golden's metadata.labels (np-operator.json Lines 6-13, np.new.json Lines 8-15) contains it, and the generator only strips instance-template-hash. This passes solely because compareNP ignores metadata, which weakens the "diff-oracle" claim in networkpolicy_file_test.go. Either add the label to the goldens or drop it from the fixture.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/apis/softwarecomposition/networkpolicy/v2/testdata/cp-operator.json`
around lines 13 - 22, Align the fixture and golden metadata labels by either
adding kubescape.io/workload-container-name to both golden files or removing it
from cp-operator.json; keep compareNP unchanged so metadata differences remain
detectable by networkpolicy_file_test.go.
pkg/apis/softwarecomposition/networkpolicy/v2/networkpolicy_file_test.go (1)

44-61: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Decode known-servers through the v1beta1 conversion path.

known-servers.json is currently decoded into []softwarecomposition.KnownServer, which works only because Go matches the camelCase JSON keys (ipBlock, server, name) to the internal exported fields; this is fragile and diverges from the profile fixture path. Decode as softwarecompositionv1beta1.KnownServer and convert to the internal type for consistency.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/apis/softwarecomposition/networkpolicy/v2/networkpolicy_file_test.go`
around lines 44 - 61, Update the known-servers fixture setup in the test to
unmarshal into a slice of softwarecompositionv1beta1.KnownServer, then convert
each entry through the v1beta1 conversion path into the internal
[]softwarecomposition.KnownServer used by the generator. Replace the direct
json.Unmarshal into knownServers while preserving the existing fixture error
handling and resulting internal collection.
pkg/registry/file/dynamicpathdetector/tests/execargs_wildcard_ap_test.go (1)

39-39: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Test names still say "AP" but now test ContainerProfile.

execAP/matchAP were fully replaced by execCP/matchCP, but the enclosing test function names (TestAP_LiteralStarArg_DoesNotBroaden, TestAP_DynamicArg_IsSingleSegmentWildcard, TestAP_MultiArgWildcard_AbsorbsTail, TestAP_LiteralStarVsDynamic_DivergeOnSameInput) weren't renamed, which could mislead future readers into thinking these exercise ApplicationProfile.

Also applies to: 62-62, 85-85, 111-111

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/registry/file/dynamicpathdetector/tests/execargs_wildcard_ap_test.go` at
line 39, Rename the affected test functions from the AP prefix to CP to match
the ContainerProfile behavior exercised by execCP and matchCP. Update
TestAP_LiteralStarArg_DoesNotBroaden, TestAP_DynamicArg_IsSingleSegmentWildcard,
TestAP_MultiArgWildcard_AbsorbsTail, and
TestAP_LiteralStarVsDynamic_DivergeOnSameInput without changing their test
logic.
pkg/registry/file/networkneighborhood_ipcollapse.go (1)

25-47: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value

Minor aliasing risk when merging duplicate identifiers.

out[index].DNSNames/.Ports still reference the first occurrence's backing array; the in-place append at Lines 34-35 can mutate that shared array before it's replaged by DeflateSortString/DeflateStringer. Low risk given current callers discard in after the call, but worth a defensive copy to avoid surprises if this helper is reused elsewhere.

♻️ Suggested defensive copy
 		if index, ok := seen[item.Identifier]; ok {
-			out[index].DNSNames = append(out[index].DNSNames, item.DNSNames...)
-			out[index].Ports = append(out[index].Ports, item.Ports...)
+			out[index].DNSNames = append(append([]string(nil), out[index].DNSNames...), item.DNSNames...)
+			out[index].Ports = append(append([]softwarecomposition.NetworkPort(nil), out[index].Ports...), item.Ports...)
 			toDeflate.Add(index)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/registry/file/networkneighborhood_ipcollapse.go` around lines 25 - 47,
Update deflateNetworkNeighbors so the first occurrence’s DNSNames and Ports
slices are defensively copied before duplicate items are appended, preventing
merged output from sharing backing arrays with input data. Preserve the existing
duplicate aggregation and deflation behavior.
pkg/registry/file/containerprofile_processor_test.go (1)

184-242: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Concurrent consolidation test no longer verifies output correctness.

TestConsolidateTimeSeries_Concurrent_NoDeadlock now only checks for deadlocks and pool leaks after removing the AP verification block; it no longer confirms the consolidated ContainerProfile content is correct under concurrent dispatch (same staged inputs as TestConsolidateData). A regression that produces wrong-but-non-deadlocking output would slip through.

♻️ Suggested addition before the pool-leak check
	conn, err := pool.Take(ctx)
	require.NoError(t, err)
	containerProfile := softwarecomposition.ContainerProfile{}
	key := "/spdx.softwarecomposition.kubescape.io/containerprofile/kube-system/replicaset-coredns-5d78c9869d-coredns-185f-129c"
	require.NoError(t, s.GetWithConn(ctx, conn, key, storage.GetOptions{}, &containerProfile))
	assert.Equal(t, softwarecomposition.CallID("test-call-id"), containerProfile.Spec.IdentifiedCallStacks[0].CallID)
	pool.Put(conn)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/registry/file/containerprofile_processor_test.go` around lines 184 - 242,
Restore an output-correctness assertion in
TestConsolidateTimeSeries_Concurrent_NoDeadlock after the final consolidation
and before the pool-leak check. Reuse pool, s, and ctx to acquire a connection,
fetch the expected consolidated ContainerProfile with GetWithConn for the known
coredns key, assert its first identified call stack has CallID "test-call-id",
and return the connection to the pool while preserving the existing deadlock and
leak checks.
cmd/migration/main_test.go (1)

284-286: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Drop the import-keeper instead of a package-level blank var.

softwarecomposition isn't otherwise needed in this test file; removing the import is cleaner than anchoring it with var _ = softwarecomposition.HTTPEndpoint{}.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/migration/main_test.go` around lines 284 - 286, Remove the package-level
blank variable referencing softwarecomposition.HTTPEndpoint and delete the
now-unused softwarecomposition import from the test file, leaving the
surrounding migration fixture unchanged.
pkg/registry/softwarecomposition/containerprofile/strategy_test.go (1)

120-124: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider renaming the copy-pasted symbols this guard pins.

The guard asserts on SbomSyftStrategy inside the containerprofile package (same for MatchWorkloadConfigurationScan at Line 76) — exactly the copy-paste heritage the file header warns about. Renaming these in strategy.go to ContainerProfileStrategy/MatchContainerProfile would make the tests self-documenting; the package is internal so the churn is contained.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/registry/softwarecomposition/containerprofile/strategy_test.go` around
lines 120 - 124, Rename the copy-pasted strategy symbols in strategy.go from
SbomSyftStrategy to ContainerProfileStrategy and MatchWorkloadConfigurationScan
to MatchContainerProfile, then update all references in the containerprofile
package, including the compile-time interface guards and tests. Preserve the
existing behavior and interfaces.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cmd/migration/main_test.go`:
- Line 48: Replace both exec.Command call sites in the migration test with
exec.CommandContext, including the build invocation and the second command
around the affected lines. Add the context import and pass an appropriate
test-scoped context so hung build or run processes are bounded while preserving
the existing arguments and behavior.

In `@pkg/apis/softwarecomposition/networkpolicy/v2/testdata/np.new.json`:
- Around line 50-52: Update the embedded NetworkPolicy metadata name in
np.new.json to match the generator’s deployment-operator naming and the sibling
golden fixture, replacing the stale replicaset-based name while preserving the
namespace and policy rules.

In `@pkg/registry/file/cleanup.go`:
- Around line 72-77: The cleanup registration for "containerprofiles" lacks
coverage for both relevancy states. Add a unit test near the cleanup setup that
verifies relevancyEnabled=true registers deleteMissingInstanceIdAnnotation and
deleteMissingWlidAnnotation in the exact expected handler set, while
relevancyEnabled=false leaves those handlers unregistered.

In `@pkg/registry/file/containerprofile_processor.go`:
- Around line 186-201: Update the GetContainerProfileMetadataNoLock error
handling in the completed-immutability check to distinguish storage.IsNotFound
from other errors. Keep the create/no-existing-profile path unchanged for
not-found errors, but log any other storage failure with the relevant key and
error details before proceeding, matching the diagnostic behavior of the nearby
SBOM lookup.

In `@pkg/registry/file/generatednetworkpolicy_multicontainer_test.go`:
- Around line 26-32: Update the comment above the generated network policy tests
to remove the outdated claim that storage performs a literal-key Get, loses
per-workload aggregation, and causes the tests to fail. Reword it to describe
the current pinned aggregation contract while retaining the relevant
per-container naming and workload-level behavior details.

In `@pkg/registry/file/generatednetworkpolicy.go`:
- Around line 176-193: Update the single-workload lookup around
listNamespaceContainerProfiles to avoid truncated in-memory scans: apply the
workload-name selection through the storage.ListOptions predicate when
supported, or paginate using continuation tokens until all namespace profiles
are examined. Preserve the existing availability filtering and return the
matching profile, only returning storage.NewKeyNotFoundError after the complete
filtered search.

---

Outside diff comments:
In `@pkg/apis/softwarecomposition/v1beta1/generated.proto`:
- Around line 226-264: Update the stale warning comment in ContainerProfileSpec
above architectures to describe the execution/profile fields rather than
referencing the removed ApplicationProfileContainer type, matching the wording
used by ContainerProfileSpec in types.go; leave the field definitions and
network warning unchanged.

In `@pkg/apiserver/apiserver.go`:
- Around line 141-144: Update the comments around containerProfileProcessor
initialization and CollapseSettings wiring to refer to the single
container-profile processor, not plural processors or application/container
storage backends. Describe only the remaining processor and its
CollapseConfiguration provider dependency, keeping the implementation unchanged.

---

Nitpick comments:
In `@cmd/migration/main_test.go`:
- Around line 284-286: Remove the package-level blank variable referencing
softwarecomposition.HTTPEndpoint and delete the now-unused softwarecomposition
import from the test file, leaving the surrounding migration fixture unchanged.

In `@pkg/apis/softwarecomposition/networkpolicy/v2/networkpolicy_file_test.go`:
- Around line 44-61: Update the known-servers fixture setup in the test to
unmarshal into a slice of softwarecompositionv1beta1.KnownServer, then convert
each entry through the v1beta1 conversion path into the internal
[]softwarecomposition.KnownServer used by the generator. Replace the direct
json.Unmarshal into knownServers while preserving the existing fixture error
handling and resulting internal collection.

In `@pkg/apis/softwarecomposition/networkpolicy/v2/networkpolicy_test.go`:
- Around line 443-489: Remove the duplicate policy_with_known_servers table
entry, keeping only one identical test case and its expectations in the
surrounding table-driven test.
- Around line 299-337: Update
pkg/apis/softwarecomposition/networkpolicy/v2/networkpolicy_test.go:299-337 to
explicitly assert PoliciesRef and Spec.Spec.PodSelector for the known-servers
case, and normalize the expected TypeMeta.APIVersion to the v1beta1 value. In
pkg/apis/softwarecomposition/networkpolicy/v2/testdata/cp-operator.json:13-22,
add kubescape.io/workload-container-name to both golden metadata.labels entries
or remove it from the fixture. In
pkg/apis/softwarecomposition/networkpolicy/v2/testdata/np.new.json:50-52, change
the embedded NetworkPolicy name to deployment-operator.

In `@pkg/apis/softwarecomposition/networkpolicy/v2/networkpolicy.go`:
- Around line 24-50: Update GenerateNetworkPolicy to create a defensive copy of
cp.Labels before removing TemplateHashKey, so the caller’s ContainerProfile is
not mutated. Use the cleaned labels for networkPolicy.ObjectMeta.Labels and
provide a separate copy for generatedNetworkPolicy.ObjectMeta.Labels, preventing
the two output objects from sharing the same map.

In `@pkg/apis/softwarecomposition/networkpolicy/v2/testdata/cp-operator.json`:
- Around line 13-22: Align the fixture and golden metadata labels by either
adding kubescape.io/workload-container-name to both golden files or removing it
from cp-operator.json; keep compareNP unchanged so metadata differences remain
detectable by networkpolicy_file_test.go.

In `@pkg/registry/file/containerprofile_processor_test.go`:
- Around line 184-242: Restore an output-correctness assertion in
TestConsolidateTimeSeries_Concurrent_NoDeadlock after the final consolidation
and before the pool-leak check. Reuse pool, s, and ctx to acquire a connection,
fetch the expected consolidated ContainerProfile with GetWithConn for the known
coredns key, assert its first identified call stack has CallID "test-call-id",
and return the connection to the pool while preserving the existing deadlock and
leak checks.

In `@pkg/registry/file/dynamicpathdetector/tests/execargs_wildcard_ap_test.go`:
- Line 39: Rename the affected test functions from the AP prefix to CP to match
the ContainerProfile behavior exercised by execCP and matchCP. Update
TestAP_LiteralStarArg_DoesNotBroaden, TestAP_DynamicArg_IsSingleSegmentWildcard,
TestAP_MultiArgWildcard_AbsorbsTail, and
TestAP_LiteralStarVsDynamic_DivergeOnSameInput without changing their test
logic.

In `@pkg/registry/file/networkneighborhood_ipcollapse.go`:
- Around line 25-47: Update deflateNetworkNeighbors so the first occurrence’s
DNSNames and Ports slices are defensively copied before duplicate items are
appended, preventing merged output from sharing backing arrays with input data.
Preserve the existing duplicate aggregation and deflation behavior.

In `@pkg/registry/softwarecomposition/containerprofile/strategy_test.go`:
- Around line 120-124: Rename the copy-pasted strategy symbols in strategy.go
from SbomSyftStrategy to ContainerProfileStrategy and
MatchWorkloadConfigurationScan to MatchContainerProfile, then update all
references in the containerprofile package, including the compile-time interface
guards and tests. Preserve the existing behavior and interfaces.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 1a9c937a-7fda-489d-8d43-55cc8b4ff472

📥 Commits

Reviewing files that changed from the base of the PR and between 72c61d4 and 804bd18.

⛔ Files ignored due to path filters (25)
  • pkg/apis/softwarecomposition/v1beta1/generated.pb.go is excluded by !**/*.pb.go
  • pkg/apis/softwarecomposition/v1beta1/generated.protomessage.pb.go is excluded by !**/*.pb.go
  • pkg/generated/applyconfiguration/softwarecomposition/v1beta1/applicationprofile.go is excluded by !**/generated/**
  • pkg/generated/applyconfiguration/softwarecomposition/v1beta1/applicationprofilecontainer.go is excluded by !**/generated/**
  • pkg/generated/applyconfiguration/softwarecomposition/v1beta1/applicationprofilespec.go is excluded by !**/generated/**
  • pkg/generated/applyconfiguration/softwarecomposition/v1beta1/containerprofilespec.go is excluded by !**/generated/**
  • pkg/generated/applyconfiguration/softwarecomposition/v1beta1/networkneighborhood.go is excluded by !**/generated/**
  • pkg/generated/applyconfiguration/softwarecomposition/v1beta1/networkneighborhoodcontainer.go is excluded by !**/generated/**
  • pkg/generated/applyconfiguration/softwarecomposition/v1beta1/networkneighborhoodspec.go is excluded by !**/generated/**
  • pkg/generated/applyconfiguration/utils.go is excluded by !**/generated/**
  • pkg/generated/clientset/versioned/typed/softwarecomposition/v1beta1/applicationprofile.go is excluded by !**/generated/**
  • pkg/generated/clientset/versioned/typed/softwarecomposition/v1beta1/fake/fake_applicationprofile.go is excluded by !**/generated/**
  • pkg/generated/clientset/versioned/typed/softwarecomposition/v1beta1/fake/fake_networkneighborhood.go is excluded by !**/generated/**
  • pkg/generated/clientset/versioned/typed/softwarecomposition/v1beta1/fake/fake_softwarecomposition_client.go is excluded by !**/generated/**
  • pkg/generated/clientset/versioned/typed/softwarecomposition/v1beta1/generated_expansion.go is excluded by !**/generated/**
  • pkg/generated/clientset/versioned/typed/softwarecomposition/v1beta1/networkneighborhood.go is excluded by !**/generated/**
  • pkg/generated/clientset/versioned/typed/softwarecomposition/v1beta1/softwarecomposition_client.go is excluded by !**/generated/**
  • pkg/generated/informers/externalversions/generic.go is excluded by !**/generated/**
  • pkg/generated/informers/externalversions/softwarecomposition/v1beta1/applicationprofile.go is excluded by !**/generated/**
  • pkg/generated/informers/externalversions/softwarecomposition/v1beta1/interface.go is excluded by !**/generated/**
  • pkg/generated/informers/externalversions/softwarecomposition/v1beta1/networkneighborhood.go is excluded by !**/generated/**
  • pkg/generated/listers/softwarecomposition/v1beta1/applicationprofile.go is excluded by !**/generated/**
  • pkg/generated/listers/softwarecomposition/v1beta1/expansion_generated.go is excluded by !**/generated/**
  • pkg/generated/listers/softwarecomposition/v1beta1/networkneighborhood.go is excluded by !**/generated/**
  • pkg/generated/openapi/zz_generated.openapi.go is excluded by !**/generated/**
📒 Files selected for processing (74)
  • cmd/migration/main.go
  • cmd/migration/main_test.go
  • pkg/apis/softwarecomposition/network_types.go
  • pkg/apis/softwarecomposition/networkpolicy/v2/networkpolicy.go
  • pkg/apis/softwarecomposition/networkpolicy/v2/networkpolicy_file_test.go
  • pkg/apis/softwarecomposition/networkpolicy/v2/networkpolicy_test.go
  • pkg/apis/softwarecomposition/networkpolicy/v2/testdata/cp-operator.json
  • pkg/apis/softwarecomposition/networkpolicy/v2/testdata/known-servers.json
  • pkg/apis/softwarecomposition/networkpolicy/v2/testdata/np-operator.json
  • pkg/apis/softwarecomposition/networkpolicy/v2/testdata/np.new.json
  • pkg/apis/softwarecomposition/register.go
  • pkg/apis/softwarecomposition/types.go
  • pkg/apis/softwarecomposition/types_test.go
  • pkg/apis/softwarecomposition/v1beta1/generated.proto
  • pkg/apis/softwarecomposition/v1beta1/network_types.go
  • pkg/apis/softwarecomposition/v1beta1/network_types_protobuf_test.go
  • pkg/apis/softwarecomposition/v1beta1/networkpolicy/v2/networkpolicy.go
  • pkg/apis/softwarecomposition/v1beta1/networkpolicy/v2/networkpolicy_test.go
  • pkg/apis/softwarecomposition/v1beta1/networkpolicy/v2/testdata/nn-operator.json
  • pkg/apis/softwarecomposition/v1beta1/register.go
  • pkg/apis/softwarecomposition/v1beta1/types.go
  • pkg/apis/softwarecomposition/v1beta1/zz_generated.conversion.go
  • pkg/apis/softwarecomposition/v1beta1/zz_generated.deepcopy.go
  • pkg/apis/softwarecomposition/v1beta1/zz_generated.model_name.go
  • pkg/apis/softwarecomposition/zz_generated.deepcopy.go
  • pkg/apiserver/apiserver.go
  • pkg/config/config.go
  • pkg/config/config_test.go
  • pkg/registry/file/applicationprofile_processor.go
  • pkg/registry/file/applicationprofile_processor_collapse_provider_test.go
  • pkg/registry/file/applicationprofile_processor_test.go
  • pkg/registry/file/applicationprofile_storage.go
  • pkg/registry/file/cleanup.go
  • pkg/registry/file/containerprofile_aggregator_test.go
  • pkg/registry/file/containerprofile_completed_guard_realmech_test.go
  • pkg/registry/file/containerprofile_completed_guard_test.go
  • pkg/registry/file/containerprofile_consolidate_golden_test.go
  • pkg/registry/file/containerprofile_kind_test.go
  • pkg/registry/file/containerprofile_processor.go
  • pkg/registry/file/containerprofile_processor_collapse_provider_test.go
  • pkg/registry/file/containerprofile_processor_test.go
  • pkg/registry/file/containerprofile_rest_storage.go
  • pkg/registry/file/containerprofile_storage.go
  • pkg/registry/file/containerprofile_storage_interface.go
  • pkg/registry/file/containerprofile_user_managed.go
  • pkg/registry/file/containerprofile_user_managed_test.go
  • pkg/registry/file/dynamicpathdetector/tests/compare_exec_args_test.go
  • pkg/registry/file/dynamicpathdetector/tests/coverage_test.go
  • pkg/registry/file/dynamicpathdetector/tests/execargs_wildcard_ap_test.go
  • pkg/registry/file/dynamicpathdetector/types.go
  • pkg/registry/file/generatednetworkpolicy.go
  • pkg/registry/file/generatednetworkpolicy_multicontainer_test.go
  • pkg/registry/file/generatednetworkpolicy_test.go
  • pkg/registry/file/networkneighborhood_ipcollapse.go
  • pkg/registry/file/networkneighborhood_processor.go
  • pkg/registry/file/networkneighborhood_processor_test.go
  • pkg/registry/file/networkneighborhood_storage.go
  • pkg/registry/file/sqlite_keyroundtrip_test.go
  • pkg/registry/file/storage.go
  • pkg/registry/file/storage_test.go
  • pkg/registry/file/testdata/consolidate_golden/consolidated.golden.json
  • pkg/registry/file/testdata/consolidate_golden/window_1.json
  • pkg/registry/file/testdata/consolidate_golden/window_2.json
  • pkg/registry/file/testdata/consolidate_golden/window_3.json
  • pkg/registry/file/testdata/expectedFilesToDelete.json
  • pkg/registry/softwarecomposition/applicationprofile/etcd.go
  • pkg/registry/softwarecomposition/applicationprofile/strategy.go
  • pkg/registry/softwarecomposition/applicationprofile/strategy_test.go
  • pkg/registry/softwarecomposition/collapseconfiguration/etcd.go
  • pkg/registry/softwarecomposition/collapseconfiguration/strategy_test.go
  • pkg/registry/softwarecomposition/containerprofile/strategy_test.go
  • pkg/registry/softwarecomposition/networkneighborhood/etcd.go
  • pkg/registry/softwarecomposition/networkneighborhood/strategy.go
  • pkg/registry/softwarecomposition/networkneighborhood/strategy_test.go
💤 Files with no reviewable changes (28)
  • pkg/apis/softwarecomposition/v1beta1/networkpolicy/v2/testdata/nn-operator.json
  • pkg/apis/softwarecomposition/v1beta1/register.go
  • pkg/apis/softwarecomposition/v1beta1/networkpolicy/v2/networkpolicy.go
  • pkg/registry/softwarecomposition/applicationprofile/etcd.go
  • pkg/registry/file/applicationprofile_processor_test.go
  • pkg/registry/softwarecomposition/applicationprofile/strategy_test.go
  • pkg/registry/file/networkneighborhood_processor_test.go
  • pkg/apis/softwarecomposition/v1beta1/networkpolicy/v2/networkpolicy_test.go
  • pkg/registry/file/applicationprofile_processor_collapse_provider_test.go
  • pkg/apis/softwarecomposition/register.go
  • pkg/registry/file/testdata/expectedFilesToDelete.json
  • pkg/registry/file/networkneighborhood_storage.go
  • pkg/registry/softwarecomposition/networkneighborhood/strategy_test.go
  • pkg/apis/softwarecomposition/network_types.go
  • pkg/registry/file/applicationprofile_processor.go
  • pkg/registry/file/networkneighborhood_processor.go
  • pkg/registry/softwarecomposition/applicationprofile/strategy.go
  • pkg/registry/softwarecomposition/networkneighborhood/etcd.go
  • pkg/apis/softwarecomposition/v1beta1/network_types.go
  • pkg/apis/softwarecomposition/v1beta1/zz_generated.model_name.go
  • pkg/registry/softwarecomposition/networkneighborhood/strategy.go
  • pkg/registry/file/containerprofile_user_managed.go
  • pkg/registry/file/containerprofile_rest_storage.go
  • pkg/apis/softwarecomposition/v1beta1/zz_generated.deepcopy.go
  • pkg/registry/file/applicationprofile_storage.go
  • pkg/apis/softwarecomposition/zz_generated.deepcopy.go
  • pkg/registry/file/containerprofile_user_managed_test.go
  • pkg/apis/softwarecomposition/v1beta1/zz_generated.conversion.go
🛑 Comments failed to post (1)
pkg/apis/softwarecomposition/networkpolicy/v2/testdata/np.new.json (1)

50-52: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Inner NetworkPolicy name contradicts the generator (and the sibling golden).

The generator names the embedded policy <lower(kind)>-<workload-name>deployment-operator, which np-operator.json Line 63 has; here it is replicaset-operator-55df98fc6d. Unnoticed only because compareNP compares ingress/egress alone.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/apis/softwarecomposition/networkpolicy/v2/testdata/np.new.json` around
lines 50 - 52, Update the embedded NetworkPolicy metadata name in np.new.json to
match the generator’s deployment-operator naming and the sibling golden fixture,
replacing the stale replicaset-based name while preserving the namespace and
policy rules.

Signed-off-by: ConstanzeTU <74674840+ConstanzeTU@users.noreply.github.com>
Signed-off-by: entlein <einentlein@gmail.com>
Signed-off-by: entlein <einentlein@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: WIP

Development

Successfully merging this pull request may close these issues.

2 participants