Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/ocm/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ func PercentageValidator(val interface{}) error {
return fmt.Errorf("Failed parsing '%v' into a floating-point number.", val)
}

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.")
Comment on lines +71 to +72

@coderabbitai coderabbitai Bot Jul 18, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 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 -B3

Repository: 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.

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.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@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.

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.

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.

}

return nil
Expand Down
8 changes: 8 additions & 0 deletions pkg/ocm/validators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ var _ = Describe("Input Validators", Ordered, func() {
Expect(PercentageValidator("-0.1")).ToNot(BeNil())
})

It("raises an error if got exactly 0", func() {
Expect(PercentageValidator("0")).ToNot(BeNil())
})

It("raises an error if got exactly 1", func() {
Expect(PercentageValidator("1")).ToNot(BeNil())

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.

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.

})

It("successfully parses a valid percentage value", func() {
Expect(PercentageValidator("0.4")).To(BeNil())
})
Expand Down