Skip to content

Commit 0a255ab

Browse files
cvo: Use protobuf for sending events and other basic API commands
For the kube apis, protobuf is more efficient on both client and server side which reduces the base load of the cluster. We can't set protobuf for custom resource clients or unstructured at the current time.
1 parent 2376468 commit 0a255ab

File tree

9 files changed

+30
-24
lines changed

9 files changed

+30
-24
lines changed

lib/resourcebuilder/apiext.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type crdBuilder struct {
2424

2525
func newCRDBuilder(config *rest.Config, m lib.Manifest) Interface {
2626
return &crdBuilder{
27-
client: apiextclientv1beta1.NewForConfigOrDie(config),
27+
client: apiextclientv1beta1.NewForConfigOrDie(withProtobuf(config)),
2828
raw: m.Raw,
2929
}
3030
}

lib/resourcebuilder/apps.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type deploymentBuilder struct {
2525

2626
func newDeploymentBuilder(config *rest.Config, m lib.Manifest) Interface {
2727
return &deploymentBuilder{
28-
client: appsclientv1.NewForConfigOrDie(config),
28+
client: appsclientv1.NewForConfigOrDie(withProtobuf(config)),
2929
raw: m.Raw,
3030
}
3131
}
@@ -89,7 +89,7 @@ type daemonsetBuilder struct {
8989

9090
func newDaemonsetBuilder(config *rest.Config, m lib.Manifest) Interface {
9191
return &daemonsetBuilder{
92-
client: appsclientv1.NewForConfigOrDie(config),
92+
client: appsclientv1.NewForConfigOrDie(withProtobuf(config)),
9393
raw: m.Raw,
9494
}
9595
}

lib/resourcebuilder/batch.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type jobBuilder struct {
2424

2525
func newJobBuilder(config *rest.Config, m lib.Manifest) Interface {
2626
return &jobBuilder{
27-
client: batchclientv1.NewForConfigOrDie(config),
27+
client: batchclientv1.NewForConfigOrDie(withProtobuf(config)),
2828
raw: m.Raw,
2929
}
3030
}

lib/resourcebuilder/core.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type serviceAccountBuilder struct {
1616

1717
func newServiceAccountBuilder(config *rest.Config, m lib.Manifest) Interface {
1818
return &serviceAccountBuilder{
19-
client: coreclientv1.NewForConfigOrDie(config),
19+
client: coreclientv1.NewForConfigOrDie(withProtobuf(config)),
2020
raw: m.Raw,
2121
}
2222
}
@@ -43,7 +43,7 @@ type configMapBuilder struct {
4343

4444
func newConfigMapBuilder(config *rest.Config, m lib.Manifest) Interface {
4545
return &configMapBuilder{
46-
client: coreclientv1.NewForConfigOrDie(config),
46+
client: coreclientv1.NewForConfigOrDie(withProtobuf(config)),
4747
raw: m.Raw,
4848
}
4949
}
@@ -70,7 +70,7 @@ type namespaceBuilder struct {
7070

7171
func newNamespaceBuilder(config *rest.Config, m lib.Manifest) Interface {
7272
return &namespaceBuilder{
73-
client: coreclientv1.NewForConfigOrDie(config),
73+
client: coreclientv1.NewForConfigOrDie(withProtobuf(config)),
7474
raw: m.Raw,
7575
}
7676
}
@@ -97,7 +97,7 @@ type serviceBuilder struct {
9797

9898
func newServiceBuilder(config *rest.Config, m lib.Manifest) Interface {
9999
return &serviceBuilder{
100-
client: coreclientv1.NewForConfigOrDie(config),
100+
client: coreclientv1.NewForConfigOrDie(withProtobuf(config)),
101101
raw: m.Raw,
102102
}
103103
}

lib/resourcebuilder/helper.go

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package resourcebuilder
2+
3+
import "k8s.io/client-go/rest"
4+
5+
// withProtobuf makes a client use protobuf.
6+
func withProtobuf(config *rest.Config) *rest.Config {
7+
config = rest.CopyConfig(config)
8+
config.AcceptContentTypes = "application/vnd.kubernetes.protobuf,application/json"
9+
config.ContentType = "application/vnd.kubernetes.protobuf"
10+
return config
11+
}

lib/resourcebuilder/rbac.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type clusterRoleBuilder struct {
1616

1717
func newClusterRoleBuilder(config *rest.Config, m lib.Manifest) Interface {
1818
return &clusterRoleBuilder{
19-
client: rbacclientv1.NewForConfigOrDie(config),
19+
client: rbacclientv1.NewForConfigOrDie(withProtobuf(config)),
2020
raw: m.Raw,
2121
}
2222
}
@@ -43,7 +43,7 @@ type clusterRoleBindingBuilder struct {
4343

4444
func newClusterRoleBindingBuilder(config *rest.Config, m lib.Manifest) Interface {
4545
return &clusterRoleBindingBuilder{
46-
client: rbacclientv1.NewForConfigOrDie(config),
46+
client: rbacclientv1.NewForConfigOrDie(withProtobuf(config)),
4747
raw: m.Raw,
4848
}
4949
}
@@ -70,7 +70,7 @@ type roleBuilder struct {
7070

7171
func newRoleBuilder(config *rest.Config, m lib.Manifest) Interface {
7272
return &roleBuilder{
73-
client: rbacclientv1.NewForConfigOrDie(config),
73+
client: rbacclientv1.NewForConfigOrDie(withProtobuf(config)),
7474
raw: m.Raw,
7575
}
7676
}
@@ -97,7 +97,7 @@ type roleBindingBuilder struct {
9797

9898
func newRoleBindingBuilder(config *rest.Config, m lib.Manifest) Interface {
9999
return &roleBindingBuilder{
100-
client: rbacclientv1.NewForConfigOrDie(config),
100+
client: rbacclientv1.NewForConfigOrDie(withProtobuf(config)),
101101
raw: m.Raw,
102102
}
103103
}

lib/resourcebuilder/security.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type securityBuilder struct {
1616

1717
func newSecurityBuilder(config *rest.Config, m lib.Manifest) Interface {
1818
return &securityBuilder{
19-
client: securityclientv1.NewForConfigOrDie(config),
19+
client: securityclientv1.NewForConfigOrDie(withProtobuf(config)),
2020
raw: m.Raw,
2121
}
2222
}

pkg/cvo/cvo.go

-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"github.com/golang/glog"
1313
"github.com/google/uuid"
1414
corev1 "k8s.io/api/core/v1"
15-
apiextclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
1615
apierrors "k8s.io/apimachinery/pkg/api/errors"
1716
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1817
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
@@ -83,7 +82,6 @@ type Operator struct {
8382

8483
client clientset.Interface
8584
kubeClient kubernetes.Interface
86-
apiExtClient apiextclientset.Interface
8785
eventRecorder record.EventRecorder
8886

8987
// minimumUpdateCheckInterval is the minimum duration to check for updates from
@@ -132,7 +130,6 @@ func New(
132130
restConfig *rest.Config,
133131
client clientset.Interface,
134132
kubeClient kubernetes.Interface,
135-
apiExtClient apiextclientset.Interface,
136133
enableMetrics bool,
137134
) *Operator {
138135
eventBroadcaster := record.NewBroadcaster()
@@ -153,7 +150,6 @@ func New(
153150
restConfig: restConfig,
154151
client: client,
155152
kubeClient: kubeClient,
156-
apiExtClient: apiExtClient,
157153
eventRecorder: eventBroadcaster.NewRecorder(scheme.Scheme, corev1.EventSource{Component: namespace}),
158154

159155
queue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "clusterversion"),

pkg/start/start.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"github.com/openshift/cluster-version-operator/pkg/cvo"
2020
"github.com/prometheus/client_golang/prometheus/promhttp"
2121
v1 "k8s.io/api/core/v1"
22-
apiext "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
2322
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2423
"k8s.io/client-go/kubernetes"
2524
"k8s.io/client-go/kubernetes/scheme"
@@ -247,10 +246,6 @@ func (cb *ClientBuilder) KubeClientOrDie(name string, fns ...func(*rest.Config))
247246
return kubernetes.NewForConfigOrDie(rest.AddUserAgent(cb.RestConfig(fns...), name))
248247
}
249248

250-
func (cb *ClientBuilder) APIExtClientOrDie(name string, fns ...func(*rest.Config)) apiext.Interface {
251-
return apiext.NewForConfigOrDie(rest.AddUserAgent(cb.RestConfig(fns...), name))
252-
}
253-
254249
func newClientBuilder(kubeconfig string) (*ClientBuilder, error) {
255250
clientCfg := clientcmd.NewDefaultClientConfigLoadingRules()
256251
clientCfg.ExplicitPath = kubeconfig
@@ -271,6 +266,11 @@ func increaseQPS(config *rest.Config) {
271266
config.Burst = 40
272267
}
273268

269+
func useProtobuf(config *rest.Config) {
270+
config.AcceptContentTypes = "application/vnd.kubernetes.protobuf,application/json"
271+
config.ContentType = "application/vnd.kubernetes.protobuf"
272+
}
273+
274274
type Context struct {
275275
CVO *cvo.Operator
276276
AutoUpdate *autoupdate.Controller
@@ -301,8 +301,7 @@ func (o *Options) NewControllerContext(cb *ClientBuilder) *Context {
301301
sharedInformers.Config().V1().ClusterOperators(),
302302
cb.RestConfig(increaseQPS),
303303
cb.ClientOrDie(o.Namespace),
304-
cb.KubeClientOrDie(o.Namespace),
305-
cb.APIExtClientOrDie(o.Namespace),
304+
cb.KubeClientOrDie(o.Namespace, useProtobuf),
306305
o.EnableMetrics,
307306
),
308307
}

0 commit comments

Comments
 (0)