Skip to content

Commit

Permalink
Use protobuf encoding for core K8s APIs in ingress-nginx
Browse files Browse the repository at this point in the history
  • Loading branch information
tosi3k committed Dec 19, 2024
1 parent 57b4a14 commit c3a74a4
Show file tree
Hide file tree
Showing 6 changed files with 317 additions and 2 deletions.
3 changes: 3 additions & 0 deletions cmd/nginx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/prometheus/client_golang/prometheus/collectors"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kuberuntime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/wait"
discovery "k8s.io/apimachinery/pkg/version"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -202,6 +203,8 @@ func createApiserverClient(apiserverHost, rootCAFile, kubeConfig string) (*kuber
cfg.TLSClientConfig = tlsClientConfig
}

cfg.ContentType = kuberuntime.ContentTypeProtobuf

klog.InfoS("Creating API client", "host", cfg.Host)

client, err := kubernetes.NewForConfig(cfg)
Expand Down
7 changes: 7 additions & 0 deletions cmd/plugin/request/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
discoveryv1 "k8s.io/api/discovery/v1"
networking "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/cli-runtime/pkg/genericclioptions"
appsv1client "k8s.io/client-go/kubernetes/typed/apps/v1"
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
Expand Down Expand Up @@ -97,6 +98,7 @@ func GetDeployments(flags *genericclioptions.ConfigFlags, namespace string) ([]a
if err != nil {
return make([]appsv1.Deployment, 0), err
}
rawConfig.ContentType = runtime.ContentTypeProtobuf

api, err := appsv1client.NewForConfig(rawConfig)
if err != nil {
Expand All @@ -117,6 +119,7 @@ func GetIngressDefinitions(flags *genericclioptions.ConfigFlags, namespace strin
if err != nil {
return make([]networking.Ingress, 0), err
}
rawConfig.ContentType = runtime.ContentTypeProtobuf

api, err := typednetworking.NewForConfig(rawConfig)
if err != nil {
Expand Down Expand Up @@ -193,6 +196,7 @@ func getEndpointSlices(flags *genericclioptions.ConfigFlags, namespace string) (
if err != nil {
return nil, err
}
rawConfig.ContentType = runtime.ContentTypeProtobuf

api, err := discoveryv1client.NewForConfig(rawConfig)
if err != nil {
Expand Down Expand Up @@ -259,6 +263,7 @@ func getPods(flags *genericclioptions.ConfigFlags) ([]apiv1.Pod, error) {
if err != nil {
return make([]apiv1.Pod, 0), err
}
rawConfig.ContentType = runtime.ContentTypeProtobuf

api, err := corev1.NewForConfig(rawConfig)
if err != nil {
Expand All @@ -280,6 +285,7 @@ func getLabeledPods(flags *genericclioptions.ConfigFlags, label string) ([]apiv1
if err != nil {
return make([]apiv1.Pod, 0), err
}
rawConfig.ContentType = runtime.ContentTypeProtobuf

api, err := corev1.NewForConfig(rawConfig)
if err != nil {
Expand Down Expand Up @@ -319,6 +325,7 @@ func getServices(flags *genericclioptions.ConfigFlags) ([]apiv1.Service, error)
if err != nil {
return make([]apiv1.Service, 0), err
}
rawConfig.ContentType = runtime.ContentTypeProtobuf

api, err := corev1.NewForConfig(rawConfig)
if err != nil {
Expand Down
Loading

0 comments on commit c3a74a4

Please sign in to comment.