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 |
📝 WalkthroughWalkthroughThe percentage validator now accepts only values strictly greater than 🚥 Pre-merge checks | ✅ 13 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (13 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
| 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.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '%s\n' '--- pkg/ocm/validators.go ---'
cat -n pkg/ocm/validators.go | sed -n '1,180p'
printf '\n%s\n' '--- tests mentioning ParseFloat or NaN in pkg/ocm ---'
rg -n "ParseFloat|NaN|floating-point number greater than 0 and less than 1|validator" pkg/ocm -g '*_test.go' -A3 -B3Repository: openshift/rosa
Length of output: 3968
🏁 Script executed:
#!/bin/bash
set -euo pipefail
cat -n pkg/ocm/validators_test.go | sed -n '1,220p'Repository: openshift/rosa
Length of output: 3886
Reject NaN explicitly. strconv.ParseFloat accepts NaN, and this bounds check still returns nil because both comparisons are false. Add math.IsNaN(number) to the guard and cover "NaN" in pkg/ocm/validators_test.go.
🤖 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/ocm/validators.go` around lines 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.
There was a problem hiding this comment.
I agree the CLI still accepts NaN, so the validator does not yet fully enforce its own 0 < x < 1 contract. The same comparison pattern exists in the operator and Terraform provider, so if we address it here we should also track sibling follow-ups instead of treating it as a CLI-only nit.
There was a problem hiding this comment.
@olucasfreitas Agreed. The CLI change should explicitly reject NaN in this PR, while the operator and Terraform provider should receive separate follow-ups so their open-interval validation is consistent as well.
Would you like me to open GitHub issues for those two sibling follow-ups, assigned to you, with links back to this PR and discussion?
✏️ Learnings added
Learnt from: olucasfreitas
Repo: openshift/rosa PR: 3398
File: pkg/ocm/validators.go:71-72
Timestamp: 2026-07-20T18:45:56.541Z
Learning: `pkg/ocm/validators.go` in the ROSA CLI must reject `NaN` as well as values outside the open interval `(0, 1)` in `PercentageValidator`; `strconv.ParseFloat` accepts `NaN`, and ordinary ordered comparisons do not reject it. Equivalent percentage-validation comparison patterns also exist in the cluster-autoscaler operator and Terraform provider, so cross-component fixes should be tracked separately rather than treated as a CLI-only concern.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
|
@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. |
| }) | ||
|
|
||
| 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.
| 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.
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