@@ -156,6 +156,11 @@ func (g Generator) Generate(ctx *genall.GenerationContext) error {
156
156
}
157
157
158
158
for i , crd := range versionedCRDs {
159
+ // defaults are not allowed to be specified in v1beta1 CRDs, so strip them
160
+ // before writing to a file
161
+ if crdVersions [i ] == "v1beta1" {
162
+ removeDefaultsFromSchemas (crd .(* apiextlegacy.CustomResourceDefinition ))
163
+ }
159
164
var fileName string
160
165
if i == 0 {
161
166
fileName = fmt .Sprintf ("%s_%s.yaml" , crdRaw .Spec .Group , crdRaw .Spec .Names .Plural )
@@ -171,6 +176,43 @@ func (g Generator) Generate(ctx *genall.GenerationContext) error {
171
176
return nil
172
177
}
173
178
179
+ // removeDefaultsFromSchemas will remove all instances of default values being
180
+ // specified across all defined API versions
181
+ func removeDefaultsFromSchemas (crd * apiextlegacy.CustomResourceDefinition ) {
182
+ if crd .Spec .Validation != nil {
183
+ removeDefaultsFromSchemaProps (crd .Spec .Validation .OpenAPIV3Schema )
184
+ }
185
+
186
+ for _ , versionSpec := range crd .Spec .Versions {
187
+ if versionSpec .Schema != nil {
188
+ removeDefaultsFromSchemaProps (versionSpec .Schema .OpenAPIV3Schema )
189
+ }
190
+ }
191
+ }
192
+
193
+ // removeDefaultsFromSchemaProps will recurse into JSONSchemaProps to remove
194
+ // all instances of default values being specified
195
+ func removeDefaultsFromSchemaProps (v * apiextlegacy.JSONSchemaProps ) {
196
+ if v == nil {
197
+ return
198
+ }
199
+
200
+ // nil-out the default field
201
+ v .Default = nil
202
+ for name , prop := range v .Properties {
203
+ removeDefaultsFromSchemaProps (& prop )
204
+ v .Properties [name ] = prop
205
+ }
206
+ if v .Items != nil {
207
+ removeDefaultsFromSchemaProps (v .Items .Schema )
208
+ for i := range v .Items .JSONSchemas {
209
+ props := v .Items .JSONSchemas [i ]
210
+ removeDefaultsFromSchemaProps (& props )
211
+ v .Items .JSONSchemas [i ] = props
212
+ }
213
+ }
214
+ }
215
+
174
216
// toTrivialVersions strips out all schemata except for the storage schema,
175
217
// and moves that up into the root object. This makes the CRD compatible
176
218
// with pre 1.13 clusters.
0 commit comments