Closed ulucinar closed 1 year ago
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:
map[string]interface{}
v1.MapTransform
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.
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 av1.MapTransform
results in a panic:Looks like we are not checking the inlined field's kind before making a recursive call here.