Skip to content

Commit

Permalink
schemapatch add marker allowDangerousTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
phosae committed May 15, 2023
1 parent 20b9845 commit c203835
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/crd/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ func builtinToType(basic *types.Basic, allowDangerousTypes bool) (typ string, fo
if allowDangerousTypes {
typ = "number"
} else {
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")
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 or schemapatch:allowDangerousTypes=true")
}
default:
return "", "", fmt.Errorf("unsupported type %q", basic.String())
Expand Down
17 changes: 14 additions & 3 deletions pkg/schemapatcher/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ type Generator struct {
// closest sentence boundary if it exceeds n characters.
MaxDescLen *int `marker:",optional"`

// AllowDangerousTypes allows types which are usually omitted from CRD generation
// because they are not recommended.
//
// Currently the following additional types are allowed when this is true:
// float32
// float64
//
// Left unspecified, the default is false
AllowDangerousTypes *bool `marker:",optional"`

// GenerateEmbeddedObjectMeta specifies if any embedded ObjectMeta in the CRD should be generated
GenerateEmbeddedObjectMeta *bool `marker:",optional"`
}
Expand All @@ -89,10 +99,11 @@ func (Generator) RegisterMarkers(into *markers.Registry) error {

func (g Generator) Generate(ctx *genall.GenerationContext) (result error) {
parser := &crdgen.Parser{
Collector: ctx.Collector,
Checker: ctx.Checker,
Collector: ctx.Collector,
Checker: ctx.Checker,
AllowDangerousTypes: g.AllowDangerousTypes != nil && *g.AllowDangerousTypes,
// Indicates the parser on whether to register the ObjectMeta type or not
GenerateEmbeddedObjectMeta: g.GenerateEmbeddedObjectMeta != nil && *g.GenerateEmbeddedObjectMeta == true,
GenerateEmbeddedObjectMeta: g.GenerateEmbeddedObjectMeta != nil && *g.GenerateEmbeddedObjectMeta,
}

crdgen.AddKnownTypes(parser)
Expand Down
4 changes: 4 additions & 0 deletions pkg/schemapatcher/zz_generated.markerhelp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c203835

Please sign in to comment.