Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
  • Loading branch information
smarterclayton committed Jan 18, 2019
commit 0a255aba5c30218de28b4596d8260a474dd83576
2 changes: 1 addition & 1 deletion lib/resourcebuilder/apiext.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type crdBuilder struct {

func newCRDBuilder(config *rest.Config, m lib.Manifest) Interface {
return &crdBuilder{
client: apiextclientv1beta1.NewForConfigOrDie(config),
client: apiextclientv1beta1.NewForConfigOrDie(withProtobuf(config)),
raw: m.Raw,
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/resourcebuilder/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type deploymentBuilder struct {

func newDeploymentBuilder(config *rest.Config, m lib.Manifest) Interface {
return &deploymentBuilder{
client: appsclientv1.NewForConfigOrDie(config),
client: appsclientv1.NewForConfigOrDie(withProtobuf(config)),
raw: m.Raw,
}
}
Expand Down Expand Up @@ -89,7 +89,7 @@ type daemonsetBuilder struct {

func newDaemonsetBuilder(config *rest.Config, m lib.Manifest) Interface {
return &daemonsetBuilder{
client: appsclientv1.NewForConfigOrDie(config),
client: appsclientv1.NewForConfigOrDie(withProtobuf(config)),
raw: m.Raw,
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/resourcebuilder/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type jobBuilder struct {

func newJobBuilder(config *rest.Config, m lib.Manifest) Interface {
return &jobBuilder{
client: batchclientv1.NewForConfigOrDie(config),
client: batchclientv1.NewForConfigOrDie(withProtobuf(config)),
raw: m.Raw,
}
}
Expand Down
8 changes: 4 additions & 4 deletions lib/resourcebuilder/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type serviceAccountBuilder struct {

func newServiceAccountBuilder(config *rest.Config, m lib.Manifest) Interface {
return &serviceAccountBuilder{
client: coreclientv1.NewForConfigOrDie(config),
client: coreclientv1.NewForConfigOrDie(withProtobuf(config)),
raw: m.Raw,
}
}
Expand All @@ -43,7 +43,7 @@ type configMapBuilder struct {

func newConfigMapBuilder(config *rest.Config, m lib.Manifest) Interface {
return &configMapBuilder{
client: coreclientv1.NewForConfigOrDie(config),
client: coreclientv1.NewForConfigOrDie(withProtobuf(config)),
raw: m.Raw,
}
}
Expand All @@ -70,7 +70,7 @@ type namespaceBuilder struct {

func newNamespaceBuilder(config *rest.Config, m lib.Manifest) Interface {
return &namespaceBuilder{
client: coreclientv1.NewForConfigOrDie(config),
client: coreclientv1.NewForConfigOrDie(withProtobuf(config)),
raw: m.Raw,
}
}
Expand All @@ -97,7 +97,7 @@ type serviceBuilder struct {

func newServiceBuilder(config *rest.Config, m lib.Manifest) Interface {
return &serviceBuilder{
client: coreclientv1.NewForConfigOrDie(config),
client: coreclientv1.NewForConfigOrDie(withProtobuf(config)),
raw: m.Raw,
}
}
Expand Down
11 changes: 11 additions & 0 deletions lib/resourcebuilder/helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package resourcebuilder

import "k8s.io/client-go/rest"

// withProtobuf makes a client use protobuf.
func withProtobuf(config *rest.Config) *rest.Config {
config = rest.CopyConfig(config)
config.AcceptContentTypes = "application/vnd.kubernetes.protobuf,application/json"
config.ContentType = "application/vnd.kubernetes.protobuf"
return config
}
8 changes: 4 additions & 4 deletions lib/resourcebuilder/rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type clusterRoleBuilder struct {

func newClusterRoleBuilder(config *rest.Config, m lib.Manifest) Interface {
return &clusterRoleBuilder{
client: rbacclientv1.NewForConfigOrDie(config),
client: rbacclientv1.NewForConfigOrDie(withProtobuf(config)),
raw: m.Raw,
}
}
Expand All @@ -43,7 +43,7 @@ type clusterRoleBindingBuilder struct {

func newClusterRoleBindingBuilder(config *rest.Config, m lib.Manifest) Interface {
return &clusterRoleBindingBuilder{
client: rbacclientv1.NewForConfigOrDie(config),
client: rbacclientv1.NewForConfigOrDie(withProtobuf(config)),
raw: m.Raw,
}
}
Expand All @@ -70,7 +70,7 @@ type roleBuilder struct {

func newRoleBuilder(config *rest.Config, m lib.Manifest) Interface {
return &roleBuilder{
client: rbacclientv1.NewForConfigOrDie(config),
client: rbacclientv1.NewForConfigOrDie(withProtobuf(config)),
raw: m.Raw,
}
}
Expand All @@ -97,7 +97,7 @@ type roleBindingBuilder struct {

func newRoleBindingBuilder(config *rest.Config, m lib.Manifest) Interface {
return &roleBindingBuilder{
client: rbacclientv1.NewForConfigOrDie(config),
client: rbacclientv1.NewForConfigOrDie(withProtobuf(config)),
raw: m.Raw,
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/resourcebuilder/security.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type securityBuilder struct {

func newSecurityBuilder(config *rest.Config, m lib.Manifest) Interface {
return &securityBuilder{
client: securityclientv1.NewForConfigOrDie(config),
client: securityclientv1.NewForConfigOrDie(withProtobuf(config)),
raw: m.Raw,
}
}
Expand Down
4 changes: 0 additions & 4 deletions pkg/cvo/cvo.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/golang/glog"
"github.com/google/uuid"
corev1 "k8s.io/api/core/v1"
apiextclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
Expand Down Expand Up @@ -83,7 +82,6 @@ type Operator struct {

client clientset.Interface
kubeClient kubernetes.Interface
apiExtClient apiextclientset.Interface
eventRecorder record.EventRecorder

// minimumUpdateCheckInterval is the minimum duration to check for updates from
Expand Down Expand Up @@ -132,7 +130,6 @@ func New(
restConfig *rest.Config,
client clientset.Interface,
kubeClient kubernetes.Interface,
apiExtClient apiextclientset.Interface,
enableMetrics bool,
) *Operator {
eventBroadcaster := record.NewBroadcaster()
Expand All @@ -153,7 +150,6 @@ func New(
restConfig: restConfig,
client: client,
kubeClient: kubeClient,
apiExtClient: apiExtClient,
eventRecorder: eventBroadcaster.NewRecorder(scheme.Scheme, corev1.EventSource{Component: namespace}),

queue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "clusterversion"),
Expand Down
13 changes: 6 additions & 7 deletions pkg/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/openshift/cluster-version-operator/pkg/cvo"
"github.com/prometheus/client_golang/prometheus/promhttp"
v1 "k8s.io/api/core/v1"
apiext "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
Expand Down Expand Up @@ -247,10 +246,6 @@ func (cb *ClientBuilder) KubeClientOrDie(name string, fns ...func(*rest.Config))
return kubernetes.NewForConfigOrDie(rest.AddUserAgent(cb.RestConfig(fns...), name))
}

func (cb *ClientBuilder) APIExtClientOrDie(name string, fns ...func(*rest.Config)) apiext.Interface {
return apiext.NewForConfigOrDie(rest.AddUserAgent(cb.RestConfig(fns...), name))
}

func newClientBuilder(kubeconfig string) (*ClientBuilder, error) {
clientCfg := clientcmd.NewDefaultClientConfigLoadingRules()
clientCfg.ExplicitPath = kubeconfig
Expand All @@ -271,6 +266,11 @@ func increaseQPS(config *rest.Config) {
config.Burst = 40
}

func useProtobuf(config *rest.Config) {
config.AcceptContentTypes = "application/vnd.kubernetes.protobuf,application/json"
config.ContentType = "application/vnd.kubernetes.protobuf"
}

type Context struct {
CVO *cvo.Operator
AutoUpdate *autoupdate.Controller
Expand Down Expand Up @@ -301,8 +301,7 @@ func (o *Options) NewControllerContext(cb *ClientBuilder) *Context {
sharedInformers.Config().V1().ClusterOperators(),
cb.RestConfig(increaseQPS),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will only affect the generic resource builders. what about the ClientOrDie, KubeClientOrDie atleast KubeClientOrDie ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left those at the defaults, those have low qps and low actions (rest config is what is used for sync loop). I'd like to do a shared qps pool eventually though for everything that isn't status updates to CV (which is effectively what this PR is).

cb.ClientOrDie(o.Namespace),
cb.KubeClientOrDie(o.Namespace),
cb.APIExtClientOrDie(o.Namespace),
cb.KubeClientOrDie(o.Namespace, useProtobuf),
o.EnableMetrics,
),
}
Expand Down