Skip to content

Commit 5e6dc15

Browse files
authored
Merge pull request #618 from alvaroaleman/improve-warning
🐛 Be more helpful with floats when allowDangerousTypes=false
2 parents 9724ec3 + 7e7f2e9 commit 5e6dc15

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

pkg/crd/schema.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package crd
1818

1919
import (
20+
"errors"
2021
"fmt"
2122
"go/ast"
2223
"go/token"
@@ -427,10 +428,13 @@ func builtinToType(basic *types.Basic, allowDangerousTypes bool) (typ string, fo
427428
typ = "string"
428429
case basicInfo&types.IsInteger != 0:
429430
typ = "integer"
430-
case basicInfo&types.IsFloat != 0 && allowDangerousTypes:
431-
typ = "number"
431+
case basicInfo&types.IsFloat != 0:
432+
if allowDangerousTypes {
433+
typ = "number"
434+
} else {
435+
return "", "", errors.New("found float, the usage of which is highly discouraged, as support for them varies across languages. Please consider serializing your float as string instead. If you are really sure you want to use them, re-run with crd:allowDangerousTypes=true")
436+
}
432437
default:
433-
// NB(directxman12): floats are *NOT* allowed in kubernetes APIs
434438
return "", "", fmt.Errorf("unsupported type %q", basic.String())
435439
}
436440

0 commit comments

Comments
 (0)