ROSAENG-62105: PercentageValidator must require value greater than 0 and less than 1 - #3398
Conversation
|
@nephomaniac: This pull request references ROSAENG-62105 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the bug to target the "5.0.0" version, but no target version was set. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: nephomaniac The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
📝 WalkthroughWalkthroughPercentage validation now rejects Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 14 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (14 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@pkg/ocm/validators.go`:
- Around line 71-72: Update the numeric validation guard in the visible
validator to explicitly reject NaN by incorporating math.IsNaN(number) alongside
the existing bounds checks, while preserving rejection of values outside the
open (0,1) interval. Add a validator test covering the "NaN" input in the
existing test suite.
🪄 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: Repository YAML (base), Central YAML (inherited)
Review profile: CHILL
Plan: Enterprise
Run ID: 35276561-b701-431e-8a50-90f9ef8c276f
📒 Files selected for processing (2)
pkg/ocm/validators.gopkg/ocm/validators_test.go
| }) | ||
|
|
||
| It("raises an error if got exactly 1", func() { | ||
| Expect(PercentageValidator("1")).ToNot(BeNil()) |
There was a problem hiding this comment.
The unit test update is good, but the higher-level autoscaler tests still encode the old contract: they expect the old error string and still use 1 as a successful threshold. Since this PR changes user-visible validation behavior, please update the e2e cases so the broader suite reflects the new open interval.
There was a problem hiding this comment.
Addressed — updated all e2e tests in tests/e2e/rosa_autoscaler_test.go and tests/e2e/test_rosacli_cluster.go: changed threshold values from "1" to "0.5" in success paths, updated assertion from "1.000000" to "0.500000", and updated all error string expectations to match the new lowercase format.
| if number > 1 || number < 0 { | ||
| return fmt.Errorf("Expecting a floating-point number between 0 and 1.") | ||
| if number >= 1 || number <= 0 { | ||
| return fmt.Errorf("Expecting a floating-point number greater than 0 and less than 1.") |
There was a problem hiding this comment.
Now that 0 and 1 are rejected, the flag help should say 'greater than 0 and less than 1' instead of 'between 0 and 1'. That keeps CLI help aligned with the validator and the OCP docs.
There was a problem hiding this comment.
Addressed — updated flag help text in pkg/clusterautoscaler/flags.go line 247 from "between 0 and 1" to "greater than 0 and less than 1".
… and 1 Align PercentageValidator bounds with the cluster-autoscaler-operator webhook and OCP documentation. Reject 0, 1, and NaN as invalid values. Fix error strings to comply with Go staticcheck ST1005 conventions. Update flag help text and all affected test expectations.
2c6664b to
f0e98e7
Compare
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (3)
tests/e2e/test_rosacli_cluster.go (3)
197-197: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick winComplete the Hosted Control Plane assertion.
This branch silently passes without validating the HCP node representation. Add the expected assertion or track and skip the unsupported behavior explicitly. As per coding guidelines, Ginkgo tests must prove one specific behavior and TODOs require follow-up.
🤖 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 `@tests/e2e/test_rosacli_cluster.go` at line 197, Replace the TODO in the Hosted Control Plane test branch with an assertion that validates the expected HCP node representation, keeping the test focused on that behavior; if the behavior is intentionally unsupported, explicitly mark or track the branch as skipped instead of allowing it to pass silently.Sources: Coding guidelines, Path instructions
4115-4133: 🔒 Security & Privacy | 🟡 Minor | ⚡ Quick winRestore the overwritten IAM trust policies after the test.
This test mutates
installerRoleNameandsupportRoleName, but the surrounding cleanup path only callsCleanResources, which does not handle this in-memoryaccountRoleNamesslice. Save the originalpolicyDocument["Statement"]per role and restore it viaUpdateAssumeRolePolicyon failure/skip, or delete/replace the roles after the test.🤖 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 `@tests/e2e/test_rosacli_cluster.go` around lines 4115 - 4133, Preserve and restore each role’s original IAM trust policy in the test that updates installerRoleName and supportRoleName. Save policyDocument["Statement"] separately per role before replacing it, then register failure/skip cleanup that calls UpdateAssumeRolePolicy for both roles to restore the saved statements; do not rely solely on CleanResources or the in-memory accountRoleNames slice.Source: Coding guidelines
4141-4153: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick winPropagate the polling context to IAM.
Inside
PollUntilContextTimeout(..., 300*time.Second, ...),context.TODO()bypasses the poll deadline, so a stuckGetRolecall can keep the test running beyond the intended timeout.Proposed fix
- func(context.Context) (bool, error) { - result, err := awsClient.IamClient.GetRole(context.TODO(), &iam.GetRoleInput{ + func(ctx context.Context) (bool, error) { + result, err := awsClient.IamClient.GetRole(ctx, &iam.GetRoleInput{🤖 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 `@tests/e2e/test_rosacli_cluster.go` around lines 4141 - 4153, Update the polling callback around awsClient.IamClient.GetRole to use its context.Context parameter instead of context.TODO(). Preserve the existing timeout and result-handling behavior while ensuring GetRole observes the PollUntilContextTimeout deadline.Sources: Coding guidelines, Path instructions
🤖 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.
Outside diff comments:
In `@tests/e2e/test_rosacli_cluster.go`:
- Line 197: Replace the TODO in the Hosted Control Plane test branch with an
assertion that validates the expected HCP node representation, keeping the test
focused on that behavior; if the behavior is intentionally unsupported,
explicitly mark or track the branch as skipped instead of allowing it to pass
silently.
- Around line 4115-4133: Preserve and restore each role’s original IAM trust
policy in the test that updates installerRoleName and supportRoleName. Save
policyDocument["Statement"] separately per role before replacing it, then
register failure/skip cleanup that calls UpdateAssumeRolePolicy for both roles
to restore the saved statements; do not rely solely on CleanResources or the
in-memory accountRoleNames slice.
- Around line 4141-4153: Update the polling callback around
awsClient.IamClient.GetRole to use its context.Context parameter instead of
context.TODO(). Preserve the existing timeout and result-handling behavior while
ensuring GetRole observes the PollUntilContextTimeout deadline.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Central YAML (inherited)
Review profile: CHILL
Plan: Pro Plus
Run ID: 514ff940-e700-43ae-823a-9e86ab3a684f
📒 Files selected for processing (7)
cmd/create/autoscaler/cmd_test.gocmd/edit/autoscaler/cmd_test.gopkg/clusterautoscaler/flags.gopkg/ocm/validators.gopkg/ocm/validators_test.gotests/e2e/rosa_autoscaler_test.gotests/e2e/test_rosacli_cluster.go
🚧 Files skipped from review as they are similar to previous changes (1)
- pkg/ocm/validators_test.go
|
@nephomaniac: The following tests failed, say
Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
|
Noting that the govulncheck, and security checks are, I believe, not related to and outside the scope of the PR. These appear to be failing in other recent MRs as well. |
Summary
PercentageValidatorbounds to match the cluster-autoscaler-operator webhook and OCP documentationnumber < 0tonumber <= 0andnumber > 1tonumber >= 1— value must be strictly between 0 and 1Context
The ROSA CLI accepted
--scale-down-utilization-threshold 0, storing"0.000000"in OCM. The cluster-autoscaler-operator's validating admission webhook rejects this value, causing Hive to enter a permanent patch rejection loop and blocking cluster upgrades.The OCP 4.18 documentation states the value "must be a value greater than 0 but less than 1." Additionally, setting the threshold to 0 silently disables scale-down in the upstream Kubernetes autoscaler (kubernetes/autoscaler#2221).
Jira: https://redhat.atlassian.net/browse/ROSAENG-62105
Summary by CodeRabbit
NaNare rejected with improved validation messages.