Skip to content

Commit c1d602d

Browse files
committed
Workaround for preserve-unknown-fields arrays issue
For CRDs with arrays the `parentPath` function doesn't walk back to the spec. To not miss `x-kubernetes-preserve-unknown-fields` we do partial matching which could open more fields than desired if the field names overlap. Signed-off-by: Stefan Prodan <[email protected]>
1 parent e02da77 commit c1d602d

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

Diff for: internal/engine/importer.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,19 @@ func convertCRD(crd cue.Value) (*IntermediateCRD, error) {
280280
stack = append(stack[:i], pc.Node())
281281
pathstack = append(pathstack[:i], psel)
282282

283-
if !preserve[cue.MakePath(pathstack...).String()] {
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 {
284296
newlist := make([]ast.Decl, 0, len(x.Elts))
285297
for _, elt := range x.Elts {
286298
if _, is := elt.(*ast.Ellipsis); !is {

Diff for: internal/engine/importer_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,9 @@ func TestConvertCRD(t *testing.T) {
334334
spec?: {
335335
template?: {
336336
// Preserve unknown fields.
337-
values?: {}
337+
values?: {
338+
...
339+
}
338340
}
339341
}
340342
}`,

0 commit comments

Comments
 (0)