Skip to content

Commit 513e6cc

Browse files
committed
WIP: Use proto if we have proto types
1 parent 4e7f0c9 commit 513e6cc

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

pkg/cache/internal/informers_map.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ func createStructuredListWatch(gvk schema.GroupVersionKind, ip *specificInformer
266266
return nil, err
267267
}
268268

269-
client, err := apiutil.RESTClientForGVK(gvk, false, ip.config, ip.codecs)
269+
client, err := apiutil.RESTClientForGVK(ip.Scheme, gvk, false, ip.config, ip.codecs)
270270
if err != nil {
271271
return nil, err
272272
}

pkg/client/apiutil/apimachinery.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ package apiutil
2121

2222
import (
2323
"fmt"
24+
"reflect"
2425
"sync"
2526

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

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

138+
type protoMessage interface {
139+
ProtoMessage()
140+
}
141+
142+
var protoMessageType = reflect.TypeOf(new(protoMessage)).Elem()
143+
137144
// createRestConfig copies the base config and updates needed fields for a new rest config.
138145
func createRestConfig(gvk schema.GroupVersionKind, isUnstructured bool, baseConfig *rest.Config, codecs serializer.CodecFactory) *rest.Config {
139146
gv := gvk.GroupVersion()
@@ -149,13 +156,14 @@ func createRestConfig(gvk schema.GroupVersionKind, isUnstructured bool, baseConf
149156
cfg.UserAgent = rest.DefaultKubernetesUserAgent()
150157
}
151158
// TODO(FillZpp): In the long run, we want to check discovery or something to make sure that this is actually true.
152-
if cfg.ContentType == "" && !isUnstructured {
153-
protobufSchemeLock.RLock()
154-
if protobufScheme.Recognizes(gvk) {
155-
cfg.ContentType = runtime.ContentTypeProtobuf
156-
}
157-
protobufSchemeLock.RUnlock()
158-
}
159+
// if cfg.ContentType == "" && !isUnstructured {
160+
// protobufSchemeLock.RLock()
161+
// gvkType, found := protobufScheme.AllKnownTypes()[gvk]
162+
// if found && gvkType.Implements(protoMessageType) {
163+
// cfg.ContentType = runtime.ContentTypeProtobuf
164+
// }
165+
// protobufSchemeLock.RUnlock()
166+
// }
159167

160168
if cfg.NegotiatedSerializer == nil {
161169
if isUnstructured {

pkg/client/client_cache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (c *clientCache) newResource(gvk schema.GroupVersionKind, isList, isUnstruc
5959
gvk.Kind = gvk.Kind[:len(gvk.Kind)-4]
6060
}
6161

62-
client, err := apiutil.RESTClientForGVK(gvk, isUnstructured, c.config, c.codecs)
62+
client, err := apiutil.RESTClientForGVK(c.scheme, gvk, isUnstructured, c.config, c.codecs)
6363
if err != nil {
6464
return nil, err
6565
}

0 commit comments

Comments
 (0)