Skip to content

Commit 9f92547

Browse files
Generate embedded ObjectMeta with schemapatch as well
1 parent f284e2e commit 9f92547

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

pkg/schemapatcher/gen.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ type Generator struct {
8484
// n indicates limit the description to at most n characters and truncate the description to
8585
// closest sentence boundary if it exceeds n characters.
8686
MaxDescLen *int `marker:",optional"`
87+
88+
// GenerateEmbeddedObjectMeta specifies if any embedded ObjectMeta in the CRD should be generated
89+
GenerateEmbeddedObjectMeta *bool `marker:",optional"`
8790
}
8891

8992
var _ genall.Generator = &Generator{}
@@ -100,6 +103,8 @@ func (g Generator) Generate(ctx *genall.GenerationContext) (result error) {
100103
parser := &crdgen.Parser{
101104
Collector: ctx.Collector,
102105
Checker: ctx.Checker,
106+
// Indicates the parser on whether to register the ObjectMeta type or not
107+
GenerateEmbeddedObjectMeta: g.GenerateEmbeddedObjectMeta != nil && *g.GenerateEmbeddedObjectMeta == true,
103108
}
104109

105110
crdgen.AddKnownTypes(parser)
@@ -142,6 +147,12 @@ func (g Generator) Generate(ctx *genall.GenerationContext) (result error) {
142147
fullSchema = *fullSchema.DeepCopy()
143148
crdgen.TruncateDescription(&fullSchema, *g.MaxDescLen)
144149
}
150+
151+
// Fix top level ObjectMeta regardless of the settings.
152+
if _, ok := fullSchema.Properties["metadata"]; ok {
153+
fullSchema.Properties["metadata"] = apiext.JSONSchemaProps{Type: "object"}
154+
}
155+
145156
existingSet.NewSchemata[gv.Version] = fullSchema
146157
}
147158
}

0 commit comments

Comments
 (0)