feat: implement SBOM status subresource - #359
Open
doraem-on wants to merge 1 commit into
Open
Conversation
Signed-off-by: Lalit Kishore <lr_be24@thapar.edu>
📝 WalkthroughWalkthroughThe change adds status fields and version conversions for SBOM Syft resources. It adds status REST storage and update strategies for filtered and unfiltered resources. The API server registers both status subresources. ChangesSBOM Syft status subresources
Estimated code review effort: 3 (Moderate) | ~15 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant API server
participant Status REST
participant Status strategy
participant Storage
Client->>API server: Submit SBOM Syft status update
API server->>Status REST: Route request to /status
Status REST->>Status strategy: Prepare update
Status strategy->>Status strategy: Preserve existing Spec
Status REST->>Storage: Persist status fields
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR implements the
/statusREST subresource for theSBOMSyftandSBOMSyftFilteredcustom resources.Historically, the
SBOMSyftStatusstruct was defined as an empty struct ({}). This meant that critical operational state—such as whether an SBOM scan waslearning,incomplete,tooLarge, etc.—could not be stored using standard Kubernetes API conventions.Workarounds typically involved saving status indicators as annotations, which is an anti-pattern for aggregated API servers and makes programmatic state tracking difficult for controllers.
This PR addresses the missing implementation by giving
SBOMSyftandSBOMSyftFilteredproper status capabilities, allowing downstream consumers (such askubevuln) to reliably read and write SBOM processing states.Detailed Changes
API Definitions Updated (
pkg/apis/softwarecomposition)SBOMSyftStatusin both the internal (types.go) and external (v1beta1/types.go) API groups.Status (string): The current operational state of the SBOM generation.StatusReason (string): A detailed explanation corresponding to the status.Limit (string): The specific limit that triggered a failure/fallback (e.g.,maxImageSize,maxSBOMSize,memoryLimit).Code Generation
hack/update-codegen.shto regenerate thedeepcopy,conversion,openapi, andclientsetfiles to reflect the newSBOMSyftStatusfields.Status Strategy Enforcement (
pkg/registry/softwarecomposition)SbomSyftStatusStrategyandSbomSyftFilteredStatusStrategy.PrepareForUpdatein the strategy to ensure that modifying the/statusendpoint strictly drops any mutations to theSpecfields, keeping theoldObj.Specfully intact.REST Subresource Registry (
etcd.go)NewStatusRESTfactory functions for bothsbomsyftsandsbomsyftfiltereds.UpdateStrategy: statusStrategyso that validation and isolation are properly enforced at the etcd layer.API Server Wiring (
pkg/apiserver/apiserver.go)v1beta1API group endpoint map:sbomsyfts/status:ep(sbomsyfts.NewStatusREST)sbomsyftfiltereds/status:ep(sbomsyftfiltereds.NewStatusREST)How to Test
Compile the API server using:
make buildStart the storage API server locally or deploy it to a test cluster.
Attempt to
PATCHorPUTagainst the/apis/spdx.softwarecomposition.kubescape.io/v1beta1/namespaces/<namespace>/sbomsyfts/<name>/statusendpoint.Verify that:
status,statusReason, andlimitfields update correctly.specvia this endpoint is ignored.Specremains unchanged after a status update.Run the complete test suite:
go test ./...All existing tests should pass.
Related issues/PRs
This is a prerequisite upstream blocker to fix the status annotation handling in the vulnerability scanner:
Summary by CodeRabbit