devfile / api

Kube-native API for cloud development workspaces specification
Apache License 2.0
259 stars 62 forks source link

Library panics when child devfile overrides parent with list attribute #1268

Open rm3l opened 1 year ago

rm3l commented 1 year ago

Which area this feature is related to?

/kind bug

Which area this bug is related to?

/area api /area library

What versions of software are you using?

Bug Summary

Issue originally reported in https://github.com/redhat-developer/odo/issues/7099

To Reproduce:

See repro repo here: https://github.com/AgentK9/devfile-override-bug They tried to run odo dev on their Devfile, but had this panic. I also reproduced the same issue with the latest version of the library. I thought it was related to pod-overrides attributes, but in fact, the same error happens with any other attribute name, as long as it is a list.

In a nutshell:

Trying to parse the child devfile results in a panic:

$ ./main /home/asoro/work/tmp/7099-odo-panics-when-overriding-parent-components-attributes-pod-override-spec-imagepullsecrets-name/devfile-override-bug/.devfile.yaml                          
parsing devfile from /home/asoro/work/tmp/7099-odo-panics-when-overriding-parent-components-attributes-pod-override-spec-imagepullsecrets-name/devfile-override-bug/.devfile.yaml              
panic: reflect.StructOf: field 0 has invalid name                                                                                                                                              

goroutine 1 [running]:                                                                                                                                                                         
reflect.StructOf({0xc00093d050, 0x1, 0x1?})                                                                                                                                                    
        /home/asoro/.asdf/installs/golang/1.19.6/go/src/reflect/type.go:2459 +0x29d4                                                                                                           
github.com/devfile/api/v2/pkg/utils/overriding.(*mapEnabledPatchMetaFromStruct).replaceMapWithSingleKeyStruct(0xc00093d190, {0xc0002ec280, 0xc}, 0x0)                                          
        /home/asoro/go/pkg/mod/github.com/devfile/api/v2@v2.2.1-alpha.0.20230413012049-a6c32fca0dbd/pkg/utils/overriding/overriding.go:161 +0x286                                              
github.com/devfile/api/v2/pkg/utils/overriding.mapEnabledPatchMetaFromStruct.LookupPatchMetadataForStruct({{{0x1ab20d0, 0x17735a0}}}, {0xc0002ec280, 0xc})                                     
        /home/asoro/go/pkg/mod/github.com/devfile/api/v2@v2.2.1-alpha.0.20230413012049-a6c32fca0dbd/pkg/utils/overriding/overriding.go:166 +0x6d                                               
k8s.io/apimachinery/pkg/util/strategicpatch.mergeMap(0xc0003890e0, 0xc0003890e0?, {0x1aa1308, 0xc0002c9c40}, {0x60?, 0x6c?})
        /home/asoro/go/pkg/mod/k8s.io/apimachinery@v0.26.1/pkg/util/strategicpatch/patch.go:1355 +0x76f
k8s.io/apimachinery/pkg/util/strategicpatch.mergeMapHandler({0x15ea860?, 0xc0003890e0?}, {0x15ea860?, 0xc000389470?}, {0x1aa1308, 0xc0002c9c40}, {0x0, 0x0}, {0x1, 0x1})
        /home/asoro/go/pkg/mod/k8s.io/apimachinery@v0.26.1/pkg/util/strategicpatch/patch.go:1413 +0x8a
k8s.io/apimachinery/pkg/util/strategicpatch.mergeMap(0xc0003890b0, 0x1?, {0x1aa1308, 0xc0002c9990}, {0x4?, 0x0?})
        /home/asoro/go/pkg/mod/k8s.io/apimachinery@v0.26.1/pkg/util/strategicpatch/patch.go:1363 +0x8a5
k8s.io/apimachinery/pkg/util/strategicpatch.mergeSliceWithoutSpecialElements({0xc0002c91a0?, 0x1?, 0x40f1ff?}, {0xc0002c99c0?, 0x1, 0x5?}, {0x15cf388, 0x4}, {0x1aa1308, 0xc0002c9990}, ...)
        /home/asoro/go/pkg/mod/k8s.io/apimachinery@v0.26.1/pkg/util/strategicpatch/patch.go:1568 +0x1e6
k8s.io/apimachinery/pkg/util/strategicpatch.mergeSlice({0xc0002c91a0, 0x1, 0x1}, {0xc0002c9700?, 0x1, 0x1}, {0x1aa1308, 0xc0002c9990}, {0x15cf388, 0x4}, ...)
        /home/asoro/go/pkg/mod/k8s.io/apimachinery@v0.26.1/pkg/util/strategicpatch/patch.go:1471 +0x3e5
k8s.io/apimachinery/pkg/util/strategicpatch.mergeSliceHandler({0x154f760?, 0xc000870f18?}, {0x154f760?, 0xc000870ff0?}, {0x1aa1308, 0xc0002c9990}, {0x15cf372, 0x5}, {0x15cf388, 0x4}, ...)
        /home/asoro/go/pkg/mod/k8s.io/apimachinery@v0.26.1/pkg/util/strategicpatch/patch.go:1429 +0xdb
k8s.io/apimachinery/pkg/util/strategicpatch.mergeMap(0xc000389080, 0xc0002c97e0?, {0x1aa1308, 0xc0002c97e0}, {0x48?, 0xdf?})
        /home/asoro/go/pkg/mod/k8s.io/apimachinery@v0.26.1/pkg/util/strategicpatch/patch.go:1373 +0x696
k8s.io/apimachinery/pkg/util/strategicpatch.StrategicMergeMapPatchUsingLookupPatchMeta(0x167b200?, 0xc0001a0880?, {0x1aa1308?, 0xc0002c97e0?})
        /home/asoro/go/pkg/mod/k8s.io/apimachinery@v0.26.1/pkg/util/strategicpatch/patch.go:880 +0x2b
github.com/devfile/api/v2/pkg/utils/overriding.OverrideDevWorkspaceTemplateSpec(0xc0001a0880, {0x1a93ed0, 0xc000209b90})
        /home/asoro/go/pkg/mod/github.com/devfile/api/v2@v2.2.1-alpha.0.20230413012049-a6c32fca0dbd/pkg/utils/overriding/overriding.go:95 +0x1ff
github.com/devfile/library/v2/pkg/devfile/parser.parseParentAndPlugin({{{0xc00048ca50, 0x5}, {0x7ffeeaa365b1, 0x9c}, {0x7ffeeaa365b1, 0x9c}, {0xc0002127e0, 0x101, 0x120}, {0x18d3260, ...}, ..
.}, ...}, ...)
        /home/asoro/work/projects/devfile/library/pkg/devfile/parser/parse.go:360 +0x79c
github.com/devfile/library/v2/pkg/devfile/parser.parseDevfile({{{0xc00048ca50, 0x5}, {0x7ffeeaa365b1, 0x9c}, {0x7ffeeaa365b1, 0x9c}, {0xc0002127e0, 0x101, 0x120}, {0x18d3260, ...}, ...}, ...}
, ...)
        /home/asoro/work/projects/devfile/library/pkg/devfile/parser/parse.go:70 +0x1c5
github.com/devfile/library/v2/pkg/devfile/parser.populateAndParseDevfile({{{0xc00048ca50, 0x5}, {0x7ffeeaa365b1, 0x9c}, {0x7ffeeaa365b1, 0x9c}, {0xc0002127e0, 0x101, 0x120}, {0x18d3260, ...},
 ...}, ...}, ...)
        /home/asoro/work/projects/devfile/library/pkg/devfile/parser/parse.go:261 +0x188
github.com/devfile/library/v2/pkg/devfile/parser.ParseDevfile({{0x7ffeeaa365b1, 0x9c}, {0x0, 0x0}, {0x0, 0x0, 0x0}, 0x0, 0x0, {0x0, ...}, ...})
        /home/asoro/work/projects/devfile/library/pkg/devfile/parser/parse.go:192 +0x425
github.com/devfile/library/v2/pkg/devfile.ParseDevfileAndValidate({{0x7ffeeaa365b1, 0x9c}, {0x0, 0x0}, {0x0, 0x0, 0x0}, 0x0, 0x0, {0x0, ...}, ...})
        /home/asoro/work/projects/devfile/library/pkg/devfile/parse.go:92 +0xa5
main.parserTest()
        /home/asoro/work/projects/devfile/library/main.go:58 +0x238
main.main()
        /home/asoro/work/projects/devfile/library/main.go:34 +0x52

Expected behavior

Successful parsing with correct attribute overridden.

Any workaround?

github-actions[bot] commented 10 months ago

This issue is stale because it has been open for 90 days with no activity. Remove stale label or comment or this will be closed in 60 days.

kevariste225 commented 8 months ago

+1

github-actions[bot] commented 1 month ago

This issue is stale because it has been open for 90 days with no activity. Remove stale label or comment or this will be closed in 60 days.

AgentK9 commented 1 month ago

ping