Closed maleck13 closed 7 years ago
Internal types should never be used for serialization
Are you importing the openshift client in combination with kubernetes code? Do you have the generated JSON codecs from kubernetes present? Those can cause problems because of the anonymous inclusion of ObjectMeta
@liggitt Thanks for the quick reply. I am importing kubernetes code. Is there a way to use the client without importing code from kubernetes, they seem quite tightly coupled? I am experimenting at the moment, so not sure I am doing things correctly. Here are what my imports look like for setting up the client:
import (
oclient "github.com/openshift/origin/pkg/client"
kubectlutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
)
I am not sure how to check if I have the JSON codecs present.
if you have the types.generated.go files with CodecEncodeSelf/CodecDecodeSelf implementations for kubernetes types, that can cause problems with serializing/deserializing openshift objects that embed those types
@liggitt I don't have those present. But I believe I figured out what I was doing wrong: I needed to register the Scheme(s) and then use the scheme convertor as shown below when retrieving buildConfigs. Is this how you would expect it to work? Or is there a better way? I have cut down the example for brevity.
//in the imports
imports(
bc "github.com/openshift/origin/pkg/build/api"
bcv1 "github.com/openshift/origin/pkg/build/api/v1"
)
bc.AddToScheme(api.Scheme)
bcv1.AddToScheme(api.Scheme)
out, err := api.Scheme.ConvertToVersion(bl, oc.APIVersion())
if err != nil {
log.Panic(err)
}
if v1bl, ok := out.(*bcv1.BuildConfigList); ok {
fmt.Println("bc", v1bl.Items[0].Name)
}
@liggitt I am happy for this to be closed now as I can progress, but interested in any opinions. Also is there any initiative to reduce the number of dependencies and simplify the usage of the client as a lib for external projects
When using the github.com/openshift/origin/pkg/client programatically, I noticed that json responses were not be decoded into the struct as expected. Digging into this further, I believe it is because the client uses the type definition in https://github.com/openshift/origin/blob/master/pkg/project/api/types.go#L35 Which seems to be missing the struct tags. Locally I modified this struct definition and added:
json:"metadata"
and then it started to work as expected, as in the values were present in the struct fields.Version
v1.3.0
Steps To Reproduce
This is how I am using the client
Current Result
The name returned is empty as are most other fields
Expected Result
The name of the project