@@ -252,7 +252,8 @@ func convertCRD(crd cue.Value) (*IntermediateCRD, error) {
252
252
// all the way to the file root
253
253
err = walkfn (defpath .Selectors (), rootosch )
254
254
255
- // First pass of astutil.Apply to remove ellipses for fields not marked with x-kubernetes-embedded-resource: true
255
+ // First pass of astutil.Apply to remove ellipses for fields not marked with
256
+ // 'x-kubernetes-preserve-unknown-fields: true'.
256
257
// Note that this implementation is only correct for CUE inputs that do not contain references.
257
258
// It is safe to use in this context because CRDs already have that invariant.
258
259
var stack []ast.Node
@@ -278,7 +279,20 @@ func convertCRD(crd cue.Value) (*IntermediateCRD, error) {
278
279
}
279
280
stack = append (stack [:i ], pc .Node ())
280
281
pathstack = append (pathstack [:i ], psel )
281
- if ! preserve [cue .MakePath (pathstack ... ).String ()] {
282
+
283
+ // Risk not closing up fields that are not marked with 'x-kubernetes-preserve-unknown-fields: true'
284
+ // if the current field name matches a path that is marked with preserve unknown.
285
+ // TODO: find a way to fix parentPath when arrays are involved.
286
+ currentPath := cue .MakePath (pathstack ... ).String ()
287
+ found := false
288
+ for k , ok := range preserve {
289
+ if strings .HasSuffix (k , currentPath ) && ok {
290
+ found = true
291
+ break
292
+ }
293
+ }
294
+
295
+ if ! found {
282
296
newlist := make ([]ast.Decl , 0 , len (x .Elts ))
283
297
for _ , elt := range x .Elts {
284
298
if _ , is := elt .(* ast.Ellipsis ); ! is {
@@ -366,7 +380,7 @@ func convertCRD(crd cue.Value) (*IntermediateCRD, error) {
366
380
// - *ast.ListLit (index is the path)
367
381
// - *ast.Field (label is the path)
368
382
//
369
- // If the there exceptions for the above two items, or the list should properly
383
+ // If there are exceptions for the above two items, or the list should properly
370
384
// have more items, this func will be buggy
371
385
func parentPath (c astutil.Cursor ) (cue.Selector , astutil.Cursor ) {
372
386
p , prior := c .Parent (), c
0 commit comments