istio/api

Why istio api types have proto unexported fields

masquee opened this issue · 5 comments

For example, ServiceEntry has unexported fileds

	state         protoimpl.MessageState
	sizeCache     protoimpl.SizeCache
	unknownFields protoimpl.UnknownFields

image

And Kubernetes native types have no these unexported fields, for example PodSpec

image

Why I care about this

Recently I use kubernetes equality.Semantic.DeepEqual compare two ServiceEntry but got a panic

panic: an unexported field was encountered, nested like this:  [recovered]
	panic: an unexported field was encountered, nested like this: int32 [recovered]
	panic: an unexported field was encountered, nested like this: v1beta1.ServiceEntry -> int32 [recovered]
	panic: an unexported field was encountered, nested like this: *v1beta1.ServiceEntry -> v1beta1.ServiceEntry -> int32 [recovered]
	panic: an unexported field was encountered, nested like this: *v1beta1.ServiceEntry -> v1beta1.ServiceEntry -> int32

[ ] Configuration Infrastructure
[ ] Docs
[ ] Installation
[X] Networking
[ ] Performance and Scalability
[ ] Policies and Telemetry
[ ] Security
[ ] Test and Release
[ ] User Experience

Additional context

This is how protobuf works: https://github.com/golang/protobuf

Use cmp.Equal(a,b,protocmp.Transform), not DeepEqual.

I just started seeing this error upon updating a controller which I'm using to manage VirtualService and ServiceEntry.

The controller is built using controller-runtime (from kubebuilder) and its CreateOrUpdate utility function uses equality.Semantic.DeepEqual.

The error started when updating controller-runtime from v0.13.1 to v0.14.0, which bumped a few other versions:

 require (
        github.com/coderanger/controller-utils v0.0.0-20201221100905-e26c5734ecc9
-       github.com/google/go-cmp v0.5.8
+       github.com/google/go-cmp v0.5.9
        istio.io/api v0.0.0-20230125212921-f04847bedb29
        istio.io/client-go v1.16.2
-       k8s.io/api v0.25.0
-       k8s.io/apimachinery v0.25.0
-       k8s.io/client-go v0.25.0
-       sigs.k8s.io/controller-runtime v0.13.1
+       k8s.io/api v0.26.1
+       k8s.io/apimachinery v0.26.1
+       k8s.io/client-go v0.26.1
+       sigs.k8s.io/controller-runtime v0.14.0
 )

but the CreateOrUpdate function didn't change, and I'm still trying to work out what changed that could have affected the behaviour in this way. So not sure whether to raise this in controller-runtime or some other project!

Mentioning it here in case the OP has solved it or anyone else has found the same, or has any pointers on where to look. Meanwhile I'll try & reduce the problem to a minimal reproduction that I can share.

FYI @gidesh

Istio changed to use protobuf v2 is what make it have unexported fields.

cmp.Equal seems to have serious performance issues and is not suitable for production use.

image


Finally I use proto.Equal from package google.golang.org/protobuf/proto.