Skip to content

Commit

Permalink
Panic if validations use unsupported float values
Browse files Browse the repository at this point in the history
  • Loading branch information
theunrepentantgeek committed May 25, 2023
1 parent d99cc56 commit 33681c0
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions v2/tools/generator/internal/astmodel/kubebuilder_validations.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,27 @@ func MakeMaximumValidation(value *big.Rat) KubeBuilderValidation {
if value.IsInt() {
return KubeBuilderValidation{MaximumValidationName, value.RatString()}
} else {
floatValue, _ := value.Float64()
return KubeBuilderValidation{MaximumValidationName, floatValue}
//TODO (@bearps) Restore this check when we modify AsDeclarations() to allow error returns
if floatValue, ok := value.Float64(); ok {
return KubeBuilderValidation{MaximumValidationName, floatValue}
}

msg := fmt.Sprintf("invalid value for maximum: %s", value.RatString())
panic(msg)
}
}

func MaxMinimumValidation(value *big.Rat) KubeBuilderValidation {
if value.IsInt() {
return KubeBuilderValidation{MinimumValidationName, value.RatString()}
} else {
floatValue, _ := value.Float64()
return KubeBuilderValidation{MinimumValidationName, floatValue}
//TODO (@bearps) Restore this check when we modify AsDeclarations() to allow error returns
if floatValue, ok := value.Float64(); ok {
return KubeBuilderValidation{MinimumValidationName, floatValue}
}

msg := fmt.Sprintf("invalid value for minimum: %s", value.RatString())
panic(msg)
}
}

Expand All @@ -183,7 +193,12 @@ func MakeMultipleOfValidation(value *big.Rat) KubeBuilderValidation {
if value.IsInt() {
return KubeBuilderValidation{MultipleOfValidationName, value.RatString()}
} else {
floatValue, _ := value.Float64()
return KubeBuilderValidation{MultipleOfValidationName, floatValue}
//TODO (@bearps) Restore this check when we modify AsDeclarations() to allow error returns
if floatValue, ok := value.Float64(); ok {
return KubeBuilderValidation{MultipleOfValidationName, floatValue}
}

msg := fmt.Sprintf("invalid value for multipleOf: %s", value.RatString())
panic(msg)
}
}

0 comments on commit 33681c0

Please sign in to comment.