@@ -252,7 +252,8 @@ func convertCRD(crd cue.Value) (*IntermediateCRD, error) {
252252 // all the way to the file root
253253 err = walkfn (defpath .Selectors (), rootosch )
254254
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'.
256257 // Note that this implementation is only correct for CUE inputs that do not contain references.
257258 // It is safe to use in this context because CRDs already have that invariant.
258259 var stack []ast.Node
@@ -278,7 +279,20 @@ func convertCRD(crd cue.Value) (*IntermediateCRD, error) {
278279 }
279280 stack = append (stack [:i ], pc .Node ())
280281 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 {
282296 newlist := make ([]ast.Decl , 0 , len (x .Elts ))
283297 for _ , elt := range x .Elts {
284298 if _ , is := elt .(* ast.Ellipsis ); ! is {
@@ -366,7 +380,7 @@ func convertCRD(crd cue.Value) (*IntermediateCRD, error) {
366380// - *ast.ListLit (index is the path)
367381// - *ast.Field (label is the path)
368382//
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
370384// have more items, this func will be buggy
371385func parentPath (c astutil.Cursor ) (cue.Selector , astutil.Cursor ) {
372386 p , prior := c .Parent (), c
0 commit comments