Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic in value.buildStructCacheEntry if an inlined struct field is not of a struct kind #230

Closed
ulucinar opened this issue Dec 21, 2022 · 0 comments · Fixed by #231
Closed

Comments

@ulucinar
Copy link
Contributor

ulucinar commented Dec 21, 2022

Crossplane's v1.MapTransform type has an inlined map and using the runtime.DefaultUnstructuredConverter.FromUnstructured to convert a map[string]interface{} into a v1.Composition (which embodies a v1.MapTransform results in a panic:

panic: reflect: NumField of non-struct type map[string]v1.JSON

goroutine 1 [running]:
reflect.(*rtype).NumField(0x0?)
        /Users/alper/.goenv/versions/1.19.1/src/reflect/type.go:1033 +0x6c
sigs.k8s.io/structured-merge-diff/v4/value.buildStructCacheEntry({0x1066b18b8, 0x1063a48e0}, 0x0?, {0x14000121b30, 0x1, 0x1})
        /Users/alper/data/workspaces/go/pkg/mod/sigs.k8s.io/structured-merge-diff/v4@v4.2.3/value/reflectcache.go:146 +0x60
sigs.k8s.io/structured-merge-diff/v4/value.buildStructCacheEntry({0x1066b18b8, 0x106439c80}, 0x10640aae0?, {0x0, 0x0, 0x0})
        /Users/alper/data/workspaces/go/pkg/mod/sigs.k8s.io/structured-merge-diff/v4@v4.2.3/value/reflectcache.go:157 +0x3dc
sigs.k8s.io/structured-merge-diff/v4/value.typeReflectEntryOf(0x106402540?, {0x1066b18b8, 0x106439c80?}, 0x0?)
        /Users/alper/data/workspaces/go/pkg/mod/sigs.k8s.io/structured-merge-diff/v4@v4.2.3/value/reflectcache.go:119 +0x1e4
sigs.k8s.io/structured-merge-diff/v4/value.TypeReflectEntryOf({0x1066b18b8, 0x106439c80})
        /Users/alper/data/workspaces/go/pkg/mod/sigs.k8s.io/structured-merge-diff/v4@v4.2.3/value/reflectcache.go:94 +0xf4
k8s.io/apimachinery/pkg/runtime.fromUnstructured({0x1063a4580?, 0x140009e9dd0?, 0x1400091d728?}, {0x106439c80?, 0x14000011590?, 0x14000a3a750?}, 0x106342080?)
        /Users/alper/data/workspaces/go/pkg/mod/k8s.io/apimachinery@v0.25.4/pkg/runtime/converter.go:346 +0x194
k8s.io/apimachinery/pkg/runtime.pointerFromUnstructured({0x1063a4580?, 0x140009e9dd0?, 0x1066b18b8?}, {0x10647c500?, 0x14000a3aa68?, 0x104ab1b2c?}, 0x1063a4580?)
        /Users/alper/data/workspaces/go/pkg/mod/k8s.io/apimachinery@v0.25.4/pkg/runtime/converter.go:508 +0x27c
k8s.io/apimachinery/pkg/runtime.fromUnstructured({0x1063a4580?, 0x140009e9dd0?, 0x2?}, {0x10647c500?, 0x14000a3aa68?, 0x98?}, 0x12f2a2300?)
        /Users/alper/data/workspaces/go/pkg/mod/k8s.io/apimachinery@v0.25.4/pkg/runtime/converter.go:357 +0x320
k8s.io/apimachinery/pkg/runtime.structFromUnstructured({0x1063a4580?, 0x140009e9da0?, 0x1400091da28?}, {0x1065176a0?, 0x14000a3aa50?, 0x104b26b3c?}, 0x1400091f110)
        /Users/alper/data/workspaces/go/pkg/mod/k8s.io/apimachinery@v0.25.4/pkg/runtime/converter.go:550 +0x6cc
k8s.io/apimachinery/pkg/runtime.fromUnstructured({0x106386600?, 0x1400047ed40?, 0x1?}, {0x1065176a0?, 0x14000a3aa50?, 0x104e4aa04?}, 0x106402540?)
        /Users/alper/data/workspaces/go/pkg/mod/k8s.io/apimachinery@v0.25.4/pkg/runtime/converter.go:359 +0x2c8
k8s.io/apimachinery/pkg/runtime.sliceFromUnstructured({0x1062abb00?, 0x14000515e90?, 0x1066b18b8?}, {0x1062a6800?, 0x140006a9ac0?, 0x104ab1b2c?}, 0x1400091f110)
        /Users/alper/data/workspaces/go/pkg/mod/k8s.io/apimachinery@v0.25.4/pkg/runtime/converter.go:488 +0x73c
k8s.io/apimachinery/pkg/runtime.fromUnstructured({0x1062abb00?, 0x14000515e90?, 0x5?}, {0x1062a6800?, 0x140006a9ac0?, 0x98?}, 0x1400091dec8?)
        /Users/alper/data/workspaces/go/pkg/mod/k8s.io/apimachinery@v0.25.4/pkg/runtime/converter.go:355 +0x2f4
k8s.io/apimachinery/pkg/runtime.structFromUnstructured({0x1063a4580?, 0x140009e9d70?, 0x1400091e008?}, {0x106544460?, 0x140006a9a90?, 0x1077f6da8?}, 0x1400091f110)
        /Users/alper/data/workspaces/go/pkg/mod/k8s.io/apimachinery@v0.25.4/pkg/runtime/converter.go:550 +0x6cc
k8s.io/apimachinery/pkg/runtime.fromUnstructured({0x106386600?, 0x140009d9b10?, 0x3?}, {0x106544460?, 0x140006a9a90?, 0x104e4aa04?}, 0x106402540?)
        /Users/alper/data/workspaces/go/pkg/mod/k8s.io/apimachinery@v0.25.4/pkg/runtime/converter.go:359 +0x2c8
k8s.io/apimachinery/pkg/runtime.sliceFromUnstructured({0x1062abb00?, 0x14000515ea8?, 0x1066b18b8?}, {0x1062a6700?, 0x14000301bf0?, 0x104ab1b2c?}, 0x1400091f110)
        /Users/alper/data/workspaces/go/pkg/mod/k8s.io/apimachinery@v0.25.4/pkg/runtime/converter.go:488 +0x73c
k8s.io/apimachinery/pkg/runtime.fromUnstructured({0x1062abb00?, 0x14000515ea8?, 0x2?}, {0x1062a6700?, 0x14000301bf0?, 0x98?}, 0x14000a17200?)
        /Users/alper/data/workspaces/go/pkg/mod/k8s.io/apimachinery@v0.25.4/pkg/runtime/converter.go:355 +0x2f4
k8s.io/apimachinery/pkg/runtime.structFromUnstructured({0x1063a4580?, 0x140009e9b60?, 0x1400091e5e8?}, {0x106517400?, 0x14000301bc0?, 0x1400039df18?}, 0x1400091f110)
        /Users/alper/data/workspaces/go/pkg/mod/k8s.io/apimachinery@v0.25.4/pkg/runtime/converter.go:550 +0x6cc
k8s.io/apimachinery/pkg/runtime.fromUnstructured({0x106386600?, 0x140002eb580?, 0xb?}, {0x106517400?, 0x14000301bc0?, 0x104e4aa04?}, 0x106402540?)
        /Users/alper/data/workspaces/go/pkg/mod/k8s.io/apimachinery@v0.25.4/pkg/runtime/converter.go:359 +0x2c8
k8s.io/apimachinery/pkg/runtime.sliceFromUnstructured({0x1062abb00?, 0x14000515f50?, 0x1066b18b8?}, {0x1062a65c0?, 0x1400039df40?, 0x104ab1b2c?}, 0x1400091f110)
        /Users/alper/data/workspaces/go/pkg/mod/k8s.io/apimachinery@v0.25.4/pkg/runtime/converter.go:488 +0x73c
k8s.io/apimachinery/pkg/runtime.fromUnstructured({0x1062abb00?, 0x14000515f50?, 0x2?}, {0x1062a65c0?, 0x1400039df40?, 0x98?}, 0x0?)
        /Users/alper/data/workspaces/go/pkg/mod/k8s.io/apimachinery@v0.25.4/pkg/runtime/converter.go:355 +0x2f4
k8s.io/apimachinery/pkg/runtime.structFromUnstructured({0x1063a4580?, 0x140009e9020?, 0x1066b18b8?}, {0x106526060?, 0x1400039df08?, 0x104ab1b2c?}, 0x1400091f110)
        /Users/alper/data/workspaces/go/pkg/mod/k8s.io/apimachinery@v0.25.4/pkg/runtime/converter.go:550 +0x6cc
k8s.io/apimachinery/pkg/runtime.fromUnstructured({0x1063a4580?, 0x140009e9020?, 0x2?}, {0x106526060?, 0x1400039df08?, 0x98?}, 0x14000a161b0?)
        /Users/alper/data/workspaces/go/pkg/mod/k8s.io/apimachinery@v0.25.4/pkg/runtime/converter.go:359 +0x2c8
k8s.io/apimachinery/pkg/runtime.structFromUnstructured({0x1063a4580?, 0x140009e8f60?, 0x0?}, {0x1064a9de0?, 0x1400039de00?, 0x104c70218?}, 0x1400091f110)
        /Users/alper/data/workspaces/go/pkg/mod/k8s.io/apimachinery@v0.25.4/pkg/runtime/converter.go:550 +0x6cc
k8s.io/apimachinery/pkg/runtime.fromUnstructured({0x1063a4580?, 0x140009e8f60?, 0x19b0?}, {0x1064a9de0?, 0x1400039de00?, 0x195?}, 0x1400091f0c8?)
        /Users/alper/data/workspaces/go/pkg/mod/k8s.io/apimachinery@v0.25.4/pkg/runtime/converter.go:359 +0x2c8
k8s.io/apimachinery/pkg/runtime.(*unstructuredConverter).FromUnstructuredWithValidation(0x1077ba580, 0x140009e8f60, {0x1065fffc0?, 0x1400039de00}, 0x0)
        /Users/alper/data/workspaces/go/pkg/mod/k8s.io/apimachinery@v0.25.4/pkg/runtime/converter.go:247 +0x32c
k8s.io/apimachinery/pkg/runtime.(*unstructuredConverter).FromUnstructured(...)
        /Users/alper/data/workspaces/go/pkg/mod/k8s.io/apimachinery@v0.25.4/pkg/runtime/converter.go:274
github.com/upbound/upjet/pkg/migration.(*PlanGenerator).convertComposition(0x1400091ff18, {{0x140009e8f60}, {{0x14000055020, 0x55}, {0x0, 0x0}, {0x0, 0x0}}})
        /Users/alper/data/workspaces/github.com/ulucinar/upbound/upbound-upjet/pkg/migration/plan_generator.go:236 +0x7c
github.com/upbound/upjet/pkg/migration.(*PlanGenerator).convert(0x1400091ff18)
        /Users/alper/data/workspaces/github.com/ulucinar/upbound/upbound-upjet/pkg/migration/plan_generator.go:128 +0x338
github.com/upbound/upjet/pkg/migration.(*PlanGenerator).GeneratePlan(0x0?)
        /Users/alper/data/workspaces/github.com/ulucinar/upbound/upbound-upjet/pkg/migration/plan_generator.go:107 +0x28
main.main()
        /Users/alper/data/workspaces/github.com/ulucinar/migration/cmd/migrator/main.go:48 +0x5f8

Process finished with the exit code 2

Looks like we are not checking the inlined field's kind before making a recursive call here.

ulucinar added a commit to ulucinar/upbound-upjet that referenced this issue Dec 23, 2022
…1.Compositions

- FromUnstructured may fail on v1.Compositions due to:
  kubernetes-sigs/structured-merge-diff#230

Signed-off-by: Alper Rifat Ulucinar <ulucinar@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant