Skip to content

feat(controller): add enabled/disabled to NodeScanConfiguration#1238

Open
fabriziosestito wants to merge 3 commits into
kubewarden:mainfrom
fabriziosestito:feat/add-enabled-disabled-to-nodescanconfiguration
Open

feat(controller): add enabled/disabled to NodeScanConfiguration#1238
fabriziosestito wants to merge 3 commits into
kubewarden:mainfrom
fabriziosestito:feat/add-enabled-disabled-to-nodescanconfiguration

Conversation

@fabriziosestito

Copy link
Copy Markdown
Collaborator

Description

  • Adds enabled/disabled to NodeScanConfiguration
  • Fixes DeleteAllOf not working with cache indexes in NodeScan controller

Fixes #1179

…leteAllOf

Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
Copilot AI review requested due to automatic review settings June 16, 2026 15:41
@fabriziosestito fabriziosestito requested a review from a team as a code owner June 16, 2026 15:41
@github-project-automation github-project-automation Bot moved this to Pending Review in SBOMscanner Jun 16, 2026
@fabriziosestito fabriziosestito self-assigned this Jun 16, 2026
@fabriziosestito fabriziosestito changed the title Feat/add enabled disabled to nodescanconfiguration feat(controller): add enabled/disabled to NodeScanConfiguration Jun 16, 2026
@fabriziosestito fabriziosestito added this to the v0.12.0 milestone Jun 16, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces an enable/disable switch for node scanning via NodeScanConfiguration.spec.enabled, and adds controller logic to clean up node-scan resources when scanning is disabled or the configuration is removed. It also changes node-deletion cleanup to use cached index-based lookups instead of DeleteAllOf.

Changes:

  • Add spec.enabled to NodeScanConfiguration and skip scan cycles when disabled.
  • Add a NodeScanConfiguration controller that deletes all NodeScanJob and NodeSBOM resources when disabled/missing.
  • Fix node-deletion cleanup by switching from DeleteAllOf to List+Delete using field indexes.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
test/e2e/nodescan_test.go Adds an E2E step to disable the configuration and assert cleanup.
internal/controller/nodescanconfiguration_controller.go New reconciler that performs cluster-wide cleanup when node scanning is disabled or config is missing.
internal/controller/nodescanconfiguration_controller_test.go Unit tests for the new configuration reconciler behavior (enabled/disabled/missing).
internal/controller/nodescan_runner.go Skips node scan cycles when the configuration is disabled.
internal/controller/nodescan_runner_test.go Updates runner tests to explicitly set Enabled: true in created configs.
internal/controller/nodescan_controller.go Reworks per-node cleanup to List+Delete via cached field indexes.
cmd/controller/main.go Registers the new NodeScanConfigurationReconciler with the manager.
charts/sbomscanner/templates/crd/sbomscanner.kubewarden.io_nodescanconfigurations.yaml Adds enabled to the CRD schema (with default) and marks it required.
charts/sbomscanner/templates/controller/role.yaml Expands RBAC to include deletecollection for node scan resources and broader verbs for nodescanjobs.
api/v1alpha1/nodescanconfiguration_types.go Adds the Enabled field to the API type.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 16 to +20
// NodeScanConfigurationSpec defines the desired configuration for node scanning.
type NodeScanConfigurationSpec struct {
// Enabled controls whether node scanning is active.
// +kubebuilder:default=true
Enabled bool `json:"enabled"`
Comment on lines +137 to 139
required:
- enabled
type: object
Comment on lines +72 to +75
if !config.Spec.Enabled {
log.V(1).Info("NodeScanConfiguration disabled, skipping node scan cycle")
return nil
}
Comment on lines +42 to +48
if !config.Spec.Enabled {
logger.Info("NodeScanConfiguration disabled, cleaning up all node scan resources")
if err := r.cleanupAllNodeResources(ctx); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to cleanup all node scan resources: %w", err)
}
return ctrl.Result{}, nil
}
@codecov

codecov Bot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 38.88889% with 33 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.74%. Comparing base (5adb1bd) to head (dd1c3e1).
⚠️ Report is 36 commits behind head on main.

Files with missing lines Patch % Lines
...nal/controller/nodescanconfiguration_controller.go 43.33% 13 Missing and 4 partials ⚠️
internal/controller/nodescan_controller.go 50.00% 4 Missing and 4 partials ⚠️
cmd/controller/main.go 0.00% 5 Missing ⚠️
internal/controller/nodescan_runner.go 0.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1238      +/-   ##
==========================================
- Coverage   53.44%   49.74%   -3.70%     
==========================================
  Files          61       78      +17     
  Lines        5340     6527    +1187     
==========================================
+ Hits         2854     3247     +393     
- Misses       2088     2816     +728     
- Partials      398      464      +66     
Flag Coverage Δ
unit-tests 49.74% <38.88%> (-3.70%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Pending Review

Development

Successfully merging this pull request may close these issues.

Add Enable/Disable to NodeScanConfiguration

2 participants