Skip to content

Commit

Permalink
Use application/vnd.kubernetes.protobuf as content-type if possible
Browse files Browse the repository at this point in the history
Signed-off-by: Siyu Wang <FillZpp.pub@gmail.com>
  • Loading branch information
FillZpp committed Sep 15, 2020
1 parent d6829e9 commit 9077fb6
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/client/apiutil/apimachinery.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,19 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/client-go/discovery"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"k8s.io/client-go/restmapper"
)

var (
localScheme = runtime.NewScheme()
)

func init() {
_ = clientgoscheme.AddToScheme(localScheme)
}

// NewDiscoveryRESTMapper constructs a new RESTMapper based on discovery
// information fetched by a new client with the given config.
func NewDiscoveryRESTMapper(c *rest.Config) (meta.RESTMapper, error) {
Expand Down Expand Up @@ -93,5 +102,8 @@ func createRestConfig(gvk schema.GroupVersionKind, baseConfig *rest.Config) *res
if cfg.UserAgent == "" {
cfg.UserAgent = rest.DefaultKubernetesUserAgent()
}
if cfg.ContentType == "" && localScheme.Recognizes(gvk) {
cfg.ContentType = runtime.ContentTypeProtobuf
}
return cfg
}

0 comments on commit 9077fb6

Please sign in to comment.