Skip to content

Commit dd110ca

Browse files
authored
Merge pull request kubernetes-sigs#655 from tosi3k/anp-pb
Use protobuf encoding for core K8s APIs in apiserver-network-proxy
2 parents 88a6f04 + e68f77b commit dd110ca

File tree

6 files changed

+16
-0
lines changed

6 files changed

+16
-0
lines changed

cmd/agent/app/options/options.go

+6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/google/uuid"
2828
"github.com/spf13/pflag"
2929
"google.golang.org/grpc"
30+
"k8s.io/apimachinery/pkg/runtime"
3031
"k8s.io/klog/v2"
3132

3233
"sigs.k8s.io/apiserver-network-proxy/pkg/agent"
@@ -86,6 +87,8 @@ type GrpcProxyAgentOptions struct {
8687
CountServerLeases bool
8788
// Path to kubeconfig (used by kubernetes client for lease listing)
8889
KubeconfigPath string
90+
// Content type of requests sent to apiserver.
91+
APIContentType string
8992
}
9093

9194
func (o *GrpcProxyAgentOptions) ClientSetConfig(dialOptions ...grpc.DialOption) *agent.ClientSetConfig {
@@ -130,6 +133,7 @@ func (o *GrpcProxyAgentOptions) Flags() *pflag.FlagSet {
130133
flags.IntVar(&o.XfrChannelSize, "xfr-channel-size", 150, "Set the size of the channel for transferring data between the agent and the proxy server.")
131134
flags.BoolVar(&o.CountServerLeases, "count-server-leases", o.CountServerLeases, "Enables lease counting system to determine the number of proxy servers to connect to.")
132135
flags.StringVar(&o.KubeconfigPath, "kubeconfig", o.KubeconfigPath, "Path to the kubeconfig file")
136+
flags.StringVar(&o.APIContentType, "kube-api-content-type", o.APIContentType, "Content type of requests sent to apiserver.")
133137
return flags
134138
}
135139

@@ -156,6 +160,7 @@ func (o *GrpcProxyAgentOptions) Print() {
156160
klog.V(1).Infof("WarnOnChannelLimit set to %t.\n", o.WarnOnChannelLimit)
157161
klog.V(1).Infof("SyncForever set to %v.\n", o.SyncForever)
158162
klog.V(1).Infof("ChannelSize set to %d.\n", o.XfrChannelSize)
163+
klog.V(1).Infof("APIContentType set to %v.\n", o.APIContentType)
159164
}
160165

161166
func (o *GrpcProxyAgentOptions) Validate() error {
@@ -259,6 +264,7 @@ func NewGrpcProxyAgentOptions() *GrpcProxyAgentOptions {
259264
XfrChannelSize: 150,
260265
CountServerLeases: false,
261266
KubeconfigPath: "",
267+
APIContentType: runtime.ContentTypeProtobuf,
262268
}
263269
return &o
264270
}

cmd/agent/app/options/options_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func TestDefaultServerOptions(t *testing.T) {
5151
assertDefaultValue(t, "WarnOnChannelLimit", defaultAgentOptions.WarnOnChannelLimit, false)
5252
assertDefaultValue(t, "SyncForever", defaultAgentOptions.SyncForever, false)
5353
assertDefaultValue(t, "XfrChannelSize", defaultAgentOptions.XfrChannelSize, 150)
54+
assertDefaultValue(t, "APIContentType", defaultAgentOptions.APIContentType, "application/vnd.kubernetes.protobuf")
5455
}
5556

5657
func assertDefaultValue(t *testing.T, fieldName string, actual, expected interface{}) {

cmd/agent/app/server.go

+1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ func (a *Agent) runProxyConnection(o *options.GrpcProxyAgentOptions, drainCh, st
157157
return nil, fmt.Errorf("failed to load in cluster kubernetes client config: %w", err)
158158
}
159159
}
160+
config.ContentType = o.APIContentType
160161

161162
k8sClient, err := kubernetes.NewForConfig(config)
162163
if err != nil {

cmd/server/app/options/options.go

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
"github.com/google/uuid"
2525
"github.com/spf13/pflag"
26+
"k8s.io/apimachinery/pkg/runtime"
2627
"k8s.io/klog/v2"
2728

2829
"sigs.k8s.io/apiserver-network-proxy/pkg/server"
@@ -86,6 +87,8 @@ type ProxyRunOptions struct {
8687
KubeconfigQPS float32
8788
// Client maximum burst for throttle.
8889
KubeconfigBurst int
90+
// Content type of requests sent to apiserver.
91+
APIContentType string
8992

9093
// Proxy strategies used by the server.
9194
// NOTE the order of the strategies matters. e.g., for list
@@ -137,6 +140,7 @@ func (o *ProxyRunOptions) Flags() *pflag.FlagSet {
137140
flags.StringVar(&o.KubeconfigPath, "kubeconfig", o.KubeconfigPath, "absolute path to the kubeconfig file (used with agent-namespace, agent-service-account, authentication-audience).")
138141
flags.Float32Var(&o.KubeconfigQPS, "kubeconfig-qps", o.KubeconfigQPS, "Maximum client QPS (proxy server uses this client to authenticate agent tokens).")
139142
flags.IntVar(&o.KubeconfigBurst, "kubeconfig-burst", o.KubeconfigBurst, "Maximum client burst (proxy server uses this client to authenticate agent tokens).")
143+
flags.StringVar(&o.APIContentType, "kube-api-content-type", o.APIContentType, "Content type of requests sent to apiserver.")
140144
flags.StringVar(&o.AuthenticationAudience, "authentication-audience", o.AuthenticationAudience, "Expected agent's token authentication audience (used with agent-namespace, agent-service-account, kubeconfig).")
141145
flags.StringVar(&o.ProxyStrategies, "proxy-strategies", o.ProxyStrategies, "The list of proxy strategies used by the server to pick an agent/tunnel, available strategies are: default, destHost, defaultRoute.")
142146
flags.StringSliceVar(&o.CipherSuites, "cipher-suites", o.CipherSuites, "The comma separated list of allowed cipher suites. Has no effect on TLS1.3. Empty means allow default list.")
@@ -178,6 +182,7 @@ func (o *ProxyRunOptions) Print() {
178182
klog.V(1).Infof("KubeconfigPath set to %q.\n", o.KubeconfigPath)
179183
klog.V(1).Infof("KubeconfigQPS set to %f.\n", o.KubeconfigQPS)
180184
klog.V(1).Infof("KubeconfigBurst set to %d.\n", o.KubeconfigBurst)
185+
klog.V(1).Infof("APIContentType set to %v.\n", o.APIContentType)
181186
klog.V(1).Infof("ProxyStrategies set to %q.\n", o.ProxyStrategies)
182187
klog.V(1).Infof("CipherSuites set to %q.\n", o.CipherSuites)
183188
klog.V(1).Infof("XfrChannelSize set to %d.\n", o.XfrChannelSize)
@@ -350,6 +355,7 @@ func NewProxyRunOptions() *ProxyRunOptions {
350355
KubeconfigPath: "",
351356
KubeconfigQPS: 0,
352357
KubeconfigBurst: 0,
358+
APIContentType: runtime.ContentTypeProtobuf,
353359
AuthenticationAudience: "",
354360
ProxyStrategies: "default",
355361
CipherSuites: make([]string, 0),

cmd/server/app/options/options_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ func TestDefaultServerOptions(t *testing.T) {
6262
assertDefaultValue(t, "ProxyStrategies", defaultServerOptions.ProxyStrategies, "default")
6363
assertDefaultValue(t, "CipherSuites", defaultServerOptions.CipherSuites, make([]string, 0))
6464
assertDefaultValue(t, "XfrChannelSize", defaultServerOptions.XfrChannelSize, 10)
65+
assertDefaultValue(t, "APIContentType", defaultServerOptions.APIContentType, "application/vnd.kubernetes.protobuf")
6566

6667
}
6768

cmd/server/app/server.go

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ func (p *Proxy) Run(o *options.ProxyRunOptions, stopCh <-chan struct{}) error {
120120
klog.V(1).Infof("Setting k8s client Burst: %v", o.KubeconfigBurst)
121121
config.Burst = o.KubeconfigBurst
122122
}
123+
config.ContentType = o.APIContentType
123124
k8sClient, err = kubernetes.NewForConfig(config)
124125
if err != nil {
125126
return fmt.Errorf("failed to create kubernetes clientset: %v", err)

0 commit comments

Comments
 (0)