Skip to content

Commit

Permalink
WIP: Use proto if we have proto types
Browse files Browse the repository at this point in the history
  • Loading branch information
justinsb committed Aug 20, 2021
1 parent 4e7f0c9 commit 513e6cc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pkg/cache/internal/informers_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func createStructuredListWatch(gvk schema.GroupVersionKind, ip *specificInformer
return nil, err
}

client, err := apiutil.RESTClientForGVK(gvk, false, ip.config, ip.codecs)
client, err := apiutil.RESTClientForGVK(ip.Scheme, gvk, false, ip.config, ip.codecs)
if err != nil {
return nil, err
}
Expand Down
24 changes: 16 additions & 8 deletions pkg/client/apiutil/apimachinery.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package apiutil

import (
"fmt"
"reflect"
"sync"

"k8s.io/apimachinery/pkg/api/meta"
Expand Down Expand Up @@ -117,7 +118,7 @@ func GVKForObject(obj runtime.Object, scheme *runtime.Scheme) (schema.GroupVersi
// RESTClientForGVK constructs a new rest.Interface capable of accessing the resource associated
// with the given GroupVersionKind. The REST client will be configured to use the negotiated serializer from
// baseConfig, if set, otherwise a default serializer will be set.
func RESTClientForGVK(gvk schema.GroupVersionKind, isUnstructured bool, baseConfig *rest.Config, codecs serializer.CodecFactory) (rest.Interface, error) {
func RESTClientForGVK(scheme *runtime.Scheme, gvk schema.GroupVersionKind, isUnstructured bool, baseConfig *rest.Config, codecs serializer.CodecFactory) (rest.Interface, error) {
return rest.RESTClientFor(createRestConfig(gvk, isUnstructured, baseConfig, codecs))
}

Expand All @@ -134,6 +135,12 @@ func (f serializerWithDecodedGVK) DecoderToVersion(serializer runtime.Decoder, _
return serializer
}

type protoMessage interface {
ProtoMessage()
}

var protoMessageType = reflect.TypeOf(new(protoMessage)).Elem()

// createRestConfig copies the base config and updates needed fields for a new rest config.
func createRestConfig(gvk schema.GroupVersionKind, isUnstructured bool, baseConfig *rest.Config, codecs serializer.CodecFactory) *rest.Config {
gv := gvk.GroupVersion()
Expand All @@ -149,13 +156,14 @@ func createRestConfig(gvk schema.GroupVersionKind, isUnstructured bool, baseConf
cfg.UserAgent = rest.DefaultKubernetesUserAgent()
}
// TODO(FillZpp): In the long run, we want to check discovery or something to make sure that this is actually true.
if cfg.ContentType == "" && !isUnstructured {
protobufSchemeLock.RLock()
if protobufScheme.Recognizes(gvk) {
cfg.ContentType = runtime.ContentTypeProtobuf
}
protobufSchemeLock.RUnlock()
}
// if cfg.ContentType == "" && !isUnstructured {
// protobufSchemeLock.RLock()
// gvkType, found := protobufScheme.AllKnownTypes()[gvk]
// if found && gvkType.Implements(protoMessageType) {
// cfg.ContentType = runtime.ContentTypeProtobuf
// }
// protobufSchemeLock.RUnlock()
// }

if cfg.NegotiatedSerializer == nil {
if isUnstructured {
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/client_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (c *clientCache) newResource(gvk schema.GroupVersionKind, isList, isUnstruc
gvk.Kind = gvk.Kind[:len(gvk.Kind)-4]
}

client, err := apiutil.RESTClientForGVK(gvk, isUnstructured, c.config, c.codecs)
client, err := apiutil.RESTClientForGVK(c.scheme, gvk, isUnstructured, c.config, c.codecs)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 513e6cc

Please sign in to comment.