Trouble with Virtual Service Deserialization

Hello, I’m trying to make a client to work with istio virtualservices

This is my object definition

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// VirtualService is a Istio VirtualService resource
type VirtualService struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`

	Spec MyVirtualService `json:"spec"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// VirtualServiceList is a list of VirtualService resources
type VirtualServiceList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata"`

	Items []VirtualService `json:"items"`
}


type MyVirtualService istiov1alpha3.VirtualService


func (in *MyVirtualService) DeepCopyInto(out *MyVirtualService) {
	*out = *in
	return
}

I use k8s code generation to create my client, my get method looks like this:

func (c *virtualServices) Get(name string, options v1.GetOptions) (result *v1alpha3.VirtualService, err error) {
result = &v1alpha3.VirtualService{}
err = c.client.Get().
Namespace(c.ns).
Resource("virtualservices").
Name(name).
VersionedParams(&options, schema.ParameterCodec).
Do().
Into(result)
return
}

It seems to work fine however some fields are always null. For example, route match header selectors and faults are always null. This is my return object for a virtualservice with a valid fault:

spec: hosts: - details http: - route: - destination: host: details subset: v1 weight: 63 - destination: host: details subset: v2 weight: 37 fault: delay: percent: 100 HttpDelayType: null

The HttpDelayType is null.

Am I doing something wrong or is this maybe just a version issue?
Does anyone have a go-client or way of working with the istio CRDs with go?

Hi,

The problem is that istio uses JSON mapping for protobuf APIs (https://developers.google.com/protocol-buffers/docs/proto3#json), which is distinct from k8s API machinery. In particular, the field tags are different, there is no strategic patch, and embedding into k8s envelope is tricky.

In istio code base, the process is two step: 1) retrieve opaque JSON spec from k8s API, 2) convert JSON to proto using jsonpb package.