Skip to content

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

Open
@rm3l

Description

@rm3l

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 redhat-developer/odo#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:

  • child devfile:
schemaVersion: 2.2.0
metadata:
  name: base
  version: 1.0.0
parent:
  uri: ./base.devfile.yaml
  components:
    - name: runtime
      container:
        image: python:3.11  # arbitrary
      attributes:
        pod-overrides:
          spec:
            imagePullSecrets:
              - name: abcd
  • parent devfile:
schemaVersion: 2.2.0
metadata:
  name: base
  version: 1.0.0
components:
  - name: runtime
    container:
      image: python:3.11  # arbitrary
    attributes:
      pod-overrides:
        spec:
          imagePullSecrets:
            - name: regcred

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/apiEnhancement or issue related to the api/devfile specificationarea/libraryCommon devfile library for interacting with devfileshelp wantedExtra attention is neededkind/bugSomething isn't workinglifecycle/frozenFrozen items. These items will never go stale or rotten after being tagged as frozen.

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions