You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2020/10/29 14:33:54 UTC
[GitHub] [camel-k] kaczyns opened a new issue #1794: Panic when attempting to convert from unstructured to Integration with traits
kaczyns opened a new issue #1794:
URL: https://github.com/apache/camel-k/issues/1794
Hello - I've got a `kind: Integration` that was generated from `kamel` and contains traits. I'm using [manifestival](https://github.com/manifestival/manifestival) to load the yaml, and so it comes in as unstructured. When I attempt to convert it to an Integration using the camel-k scheme, I get a kernel panic. I've reduced the yaml to the minimum that produces the error, and the test case is below:
```golang
package main
import (
"bytes"
"fmt"
"os"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/yaml"
camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
)
func main() {
newScheme := runtime.NewScheme()
camelv1.AddToScheme(newScheme)
decoder := yaml.NewYAMLToJSONDecoder(bytes.NewReader([]byte(testYaml)))
u := &unstructured.Unstructured{}
err := decoder.Decode(u)
if err != nil {
fmt.Printf("Error decoding: %v\n", err.Error())
os.Exit(1)
}
integration := &camelv1.Integration{}
err = newScheme.Convert(u, integration, nil)
if err != nil {
fmt.Printf("Error converting: %v\n", err.Error())
os.Exit(1)
}
fmt.Printf("Test passed!")
}
var testYaml = `apiVersion: camel.apache.org/v1
kind: Integration
metadata:
name: scm-connection
namespace: juno
spec:
traits:
owner:
configuration:
targetLabels:
- sdlc.visibility`
```
The panic seems to occur because of the trait configuration. Here is the panic:
```
[kaczyns@new-host-2 bruno-operator]$ go run scheme-test.go
panic: reflect: NumField of non-struct type
goroutine 1 [running]:
reflect.(*rtype).NumField(0xb800e0, 0x2c)
/home/kaczyns/goroot/1.13/go/src/reflect/type.go:981 +0x5e
sigs.k8s.io/structured-merge-diff/v3/value.buildStructCacheEntry(0xd6dfc0, 0xb800e0, 0xc00018aa50, 0xc000188bc0, 0x1, 0x1)
/home/kaczyns/gopath/pkg/mod/sigs.k8s.io/structured-merge-diff/v3@v3.0.0/value/reflectcache.go:146 +0x67
sigs.k8s.io/structured-merge-diff/v3/value.buildStructCacheEntry(0xd6dfc0, 0xba90e0, 0xc00018aa50, 0x0, 0x0, 0x0)
/home/kaczyns/gopath/pkg/mod/sigs.k8s.io/structured-merge-diff/v3@v3.0.0/value/reflectcache.go:153 +0x1b7
sigs.k8s.io/structured-merge-diff/v3/value.typeReflectEntryOf(0xc00015bec0, 0xd6dfc0, 0xba90e0, 0xc0000e3280, 0x0)
/home/kaczyns/gopath/pkg/mod/sigs.k8s.io/structured-merge-diff/v3@v3.0.0/value/reflectcache.go:119 +0x44e
sigs.k8s.io/structured-merge-diff/v3/value.typeReflectEntryOf(0xc00015bec0, 0xd6dfc0, 0xb9bb60, 0xc0000e3280, 0x20300000000000)
/home/kaczyns/gopath/pkg/mod/sigs.k8s.io/structured-merge-diff/v3@v3.0.0/value/reflectcache.go:139 +0x3b4
sigs.k8s.io/structured-merge-diff/v3/value.TypeReflectEntryOf(0xd6dfc0, 0xb9bb60, 0x199)
/home/kaczyns/gopath/pkg/mod/sigs.k8s.io/structured-merge-diff/v3@v3.0.0/value/reflectcache.go:94 +0x13d
k8s.io/apimachinery/pkg/runtime.fromUnstructured(0xb76520, 0xc00015b5c0, 0x15, 0xb9bb60, 0xc000188b60, 0x199, 0xb738e0, 0xc000184690)
/home/kaczyns/gopath/pkg/mod/k8s.io/apimachinery@v0.18.6/pkg/runtime/converter.go:206 +0x15c
k8s.io/apimachinery/pkg/runtime.mapFromUnstructured(0xb76520, 0xc00015b590, 0x15, 0xb76100, 0xc00016e8a0, 0x195, 0x40406a, 0xb1a711)
/home/kaczyns/gopath/pkg/mod/k8s.io/apimachinery@v0.18.6/pkg/runtime/converter.go:293 +0x5e0
k8s.io/apimachinery/pkg/runtime.fromUnstructured(0xb76520, 0xc00015b590, 0x15, 0xb76100, 0xc00016e8a0, 0x195, 0xb738e0, 0xc000184670)
/home/kaczyns/gopath/pkg/mod/k8s.io/apimachinery@v0.18.6/pkg/runtime/converter.go:213 +0x2d4
k8s.io/apimachinery/pkg/runtime.structFromUnstructured(0xb76520, 0xc00015b560, 0x15, 0xc122a0, 0xc00016e818, 0x199, 0x40406a, 0xb1664f)
/home/kaczyns/gopath/pkg/mod/k8s.io/apimachinery@v0.18.6/pkg/runtime/converter.go:382 +0x344
k8s.io/apimachinery/pkg/runtime.fromUnstructured(0xb76520, 0xc00015b560, 0x15, 0xc122a0, 0xc00016e818, 0x199, 0xb738e0, 0xc0001845c0)
/home/kaczyns/gopath/pkg/mod/k8s.io/apimachinery@v0.18.6/pkg/runtime/converter.go:219 +0x3db
k8s.io/apimachinery/pkg/runtime.structFromUnstructured(0xb76520, 0xc00015b4d0, 0x15, 0xbd70c0, 0xc00016e700, 0x199, 0xc00015b4d0, 0xc0000e3b90)
/home/kaczyns/gopath/pkg/mod/k8s.io/apimachinery@v0.18.6/pkg/runtime/converter.go:382 +0x344
k8s.io/apimachinery/pkg/runtime.fromUnstructured(0xb76520, 0xc00015b4d0, 0x15, 0xbd70c0, 0xc00016e700, 0x199, 0xc324e0, 0xc00016e700)
/home/kaczyns/gopath/pkg/mod/k8s.io/apimachinery@v0.18.6/pkg/runtime/converter.go:219 +0x3db
k8s.io/apimachinery/pkg/runtime.(*unstructuredConverter).FromUnstructured(0x124fa40, 0xc00015b4d0, 0xc324e0, 0xc00016e700, 0x2, 0xc000037440)
/home/kaczyns/gopath/pkg/mod/k8s.io/apimachinery@v0.18.6/pkg/runtime/converter.go:126 +0x2b8
k8s.io/apimachinery/pkg/runtime.(*Scheme).unstructuredToTyped(0xc00012ed90, 0xd5f4e0, 0xc0000102e8, 0x0, 0x0, 0x0, 0xd0)
/home/kaczyns/gopath/pkg/mod/k8s.io/apimachinery@v0.18.6/pkg/runtime/scheme.go:548 +0x176
k8s.io/apimachinery/pkg/runtime.(*Scheme).Convert(0xc00012ed90, 0xc3ce80, 0xc0000102e8, 0xc324e0, 0xc00016e380, 0x0, 0x0, 0x1, 0xc0000e3f20)
/home/kaczyns/gopath/pkg/mod/k8s.io/apimachinery@v0.18.6/pkg/runtime/scheme.go:416 +0x30c
main.main()
/home/kaczyns/gopath/src/github.mycompany.com/bruno/bruno-operator/scheme-test.go:28 +0x195
exit status 2
```
I'd like to be able to convert to the Integration struct as that's easier to work with, but I can manipulate this object using unstructured for now. Thanks for your help!
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-k] astefanutti commented on issue #1794: Panic when attempting to convert from unstructured to Integration with traits
Posted by GitBox <gi...@apache.org>.
astefanutti commented on issue #1794:
URL: https://github.com/apache/camel-k/issues/1794#issuecomment-718858259
I would need to dig to understand what causes that `reflect: NumField of non-struct type` error. It seems there is a non struct field, like an interface, somewhere that's being traversed.
Before that, would converting the YAML to JSON, and then unmarshall into the Integration struct be an option, instead of converting the unstructured object?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-k] kaczyns commented on issue #1794: Panic when attempting to convert from unstructured to Integration with traits
Posted by GitBox <gi...@apache.org>.
kaczyns commented on issue #1794:
URL: https://github.com/apache/camel-k/issues/1794#issuecomment-718938143
Yes I can convert the unstructured to JSON, and then use `json.Unmarshal()` to inflate the Integration object. That is working OK. I can also edit the unstructured object directly, to do what I need to do, which is actually going to end up being easier (less converting).
With these work-arounds I don't care so much about what happens with this issue - it's documented now in case someone else hits this. Please feel free to close it or leave it open as you see fit. Thanks!
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [camel-k] astefanutti commented on issue #1794: Panic when attempting to convert from unstructured to Integration with traits
Posted by GitBox <gi...@apache.org>.
astefanutti commented on issue #1794:
URL: https://github.com/apache/camel-k/issues/1794#issuecomment-718945503
Right, another option is to convert the YAML to JSON using an intermediate `map[string]interface{}{}`. I can research a bit into apimachinery bug tracker, but I'd be inclined to close the issue as schema conversion, where the error occurs, is not actually needed for your use case.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org