stackrox icon indicating copy to clipboard operation
stackrox copied to clipboard

CR Status Defaults [with version check]

Open mclasmeier opened this issue 7 months ago • 4 comments

Description

change me!

User-facing documentation

  • [ ] CHANGELOG is updated OR update is not needed
  • [ ] documentation PR is created and is linked above OR is not needed

Testing and quality

  • [ ] the change is production ready: the change is GA or otherwise the functionality is gated by a feature flag
  • [ ] CI results are inspected

Automated testing

  • [ ] added unit tests
  • [ ] added e2e tests
  • [ ] added regression tests
  • [ ] added compatibility tests
  • [ ] modified existing tests

How I validated my change

change me!

Summary by Sourcery

Implement version-aware defaulting mechanism for Scanner V4 component policy in the ACS (Advanced Cluster Security) operator

New Features:

  • Introduced a new defaulting mechanism for Scanner V4 component policy that considers installation type (new vs upgrade) and version

Enhancements:

  • Added XYVersion parsing and comparison utilities
  • Created a flexible defaulting strategy for Scanner V4 component enablement
  • Implemented status tracking for component policy defaults

Chores:

  • Refactored version parsing and comparison logic
  • Updated operator and API type definitions

mclasmeier avatar Apr 09 '25 11:04 mclasmeier

Skipping CI for Draft Pull Request. If you want CI signal for your change, please convert it to an actual PR. You can still manually trigger a test run with /test all

openshift-ci[bot] avatar Apr 09 '25 11:04 openshift-ci[bot]

Reviewer's Guide by Sourcery

This pull request introduces changes to manage the Scanner V4 component's enablement status, including version comparison utilities, status persistence, and defaulting logic. It also includes updates to the operator version and startup logging.

Sequence diagram for Scanner V4 component policy defaulting

sequenceDiagram
  participant CentralReconciler
  participant ScannerV4StatusDefaultsExtension
  participant defaulting.ScannerV4DefaultsApply
  participant CentralStatus

  CentralReconciler->>ScannerV4StatusDefaultsExtension: Reconcile
  ScannerV4StatusDefaultsExtension->>defaulting.ScannerV4DefaultsApply: ScannerV4DefaultsApply(statusDefaults, spec)
  defaulting.ScannerV4DefaultsApply->>CentralStatus: Read status.Defaults
  defaulting.ScannerV4DefaultsApply->>CentralStatus: Write status.Defaults
  ScannerV4StatusDefaultsExtension->>CentralReconciler: Update status

Updated class diagram for versioning

classDiagram
  class ParsedMainVersion {
    MarketingMajor int
    MarketingMinor *int
    EngRelease int
    PatchLevel string
    PatchSuffix string
  }
  class XYVersion {
    X int
    Y int
    Serialize() string
    LessOrEqual(XYVersion) bool
    Less(XYVersion) bool
  }

  ParsedMainVersion <.. XYVersion : Uses

Class diagram for StatusDefaults and StatusDefault

classDiagram
  class StatusDefaults {
    ScannerV4ComponentPolicy StatusDefault
  }

  class StatusDefault {
    OwnerVersion string
    Value string
  }

  StatusDefaults -- StatusDefault : contains

File-Level Changes

Change Details Files
Introduces XYVersion struct and related functions for comparing versions, and updates version parsing logic to support X.Y version format.
  • Added XYVersion struct with X and Y integer fields.
  • Added ParseXYVersion function to parse a version string into an XYVersion.
  • Added MustParseXYVersion function that panics on parsing failure.
  • Added GetMainXYVersion function to get the main XY version.
  • Added LessOrEqual and Less methods to the XYVersion struct for version comparison.
  • Added Serialize method to the XYVersion struct to convert it to a string.
  • Modified parseVersion to correctly parse X.Y version strings.
  • Updated parseMainVersion to return a ParsedMainVersion struct.
  • Renamed parsedMainVersion to ParsedMainVersion.
pkg/version/version.go
Adds StatusDefault and StatusDefaults structs to operator API for managing default component statuses, specifically for Scanner V4.
  • Added StatusDefault struct with OwnerVersion and Value fields.
  • Added StatusDefaults struct with ScannerV4ComponentPolicy field of type StatusDefault.
  • Added DeepCopy methods for the new structs.
  • Modified CentralStatus to include Defaults field of type StatusDefaults.
operator/api/v1alpha1/zz_generated.deepcopy.go
operator/api/v1alpha1/common_types.go
operator/api/v1alpha1/central_types.go
Modifies the Scanner V4 component defaulting logic to retain the current enablement state during upgrades to 4.8 and enable it for new installations.
  • Modified the description of the scannerComponent field in ScannerV4Spec to explain the defaulting behavior.
  • Removed the default value from the scannerComponent field in the CRD.
  • Adjusted the defaulting logic in getCentralScannerV4ComponentValues to apply defaults based on existing status and operator version.
  • Introduced defaulting.ScannerV4DefaultsApply to encapsulate the defaulting logic.
  • Introduced defaulting.ScannerV4ComponentPolicy to encapsulate the logic for determining the scanner v4 component policy.
  • Introduced defaulting.ScannerV4ComponentPolicyEnabled to check if the scanner v4 component policy is enabled.
operator/api/v1alpha1/central_types.go
operator/config/crd/bases/platform.stackrox.io_centrals.yaml
operator/internal/central/values/translation/translation.go
operator/internal/common/defaulting/scanner_v4_enabling.go
Adds an extension to persist the Scanner V4 enablement status in the Central status for later use.
  • Created a new extension ReconcileScannerV4StatusDefaultsExtension to persist the Scanner V4 enablement status.
  • Implemented the reconcileScannerV4StatusDefaults function to update the Central status with the Scanner V4 component policy.
  • Registered the new extension in the Central reconciler.
  • Modified centralWithScannerV4Bearer to use the new defaulting logic.
operator/internal/central/extensions/reconcile_scanner_v4_status_defaults.go
operator/internal/central/reconciler/reconciler.go
operator/internal/central/extensions/reconcile_scanner_v4_db_password.go
Updates the operator version and adds logging for operator startup.
  • Added operator/internal/version/version.go to define the operator version.
  • Added logging of the operator version on startup.
operator/cmd/main.go
operator/internal/version/version.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an issue from a review comment by replying to it. You can also reply to a review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull request title to generate a title at any time. You can also comment @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in the pull request body to generate a PR summary at any time exactly where you want it. You can also comment @sourcery-ai summary on the pull request to (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the pull request to resolve all Sourcery comments. Useful if you've already addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull request to dismiss all existing Sourcery reviews. Especially useful if you want to start fresh with a new review - don't forget to comment @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

  • Contact our support team for questions or feedback.
  • Visit our documentation for detailed guides and information.
  • Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.

sourcery-ai[bot] avatar Apr 09 '25 11:04 sourcery-ai[bot]

Images are ready for the commit at 6bfba62.

To use with deploy scripts, first export MAIN_IMAGE_TAG=4.8.x-429-g2af4bc01b4.

rhacs-bot avatar Apr 09 '25 11:04 rhacs-bot

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 49.17%. Comparing base (aeb7429) to head (6bfba62). Report is 39 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##           master   #14937       +/-   ##
===========================================
+ Coverage   48.96%   49.17%    +0.21%     
===========================================
  Files        2550      734     -1816     
  Lines      187233    73971   -113262     
===========================================
- Hits        91673    36374    -55299     
+ Misses      88308    34314    -53994     
+ Partials     7252     3283     -3969     
Flag Coverage Δ
go-unit-tests 49.17% <ø> (+0.21%) :arrow_up:

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

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Apr 09 '25 12:04 codecov[bot]