Skip to content

Commit

Permalink
Fix kube config for backend and frontend config CRDs
Browse files Browse the repository at this point in the history
  • Loading branch information
skmatti committed Mar 11, 2020
1 parent a0a01a6 commit 4151d4d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
17 changes: 8 additions & 9 deletions cmd/glbc/app/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,17 @@ const (
cloudClientRetryInterval = 10 * time.Second
)

// NewKubeConfig returns a Kubernetes client config given the command line settings.
func NewKubeConfig() (*rest.Config, error) {
config, err := newKubeConfig()
if err != nil {
return nil, err
}
// KubeConfigForProtobuf returns a shallow copy of client config after updating
// content type to protobuf.
func KubeConfigForProtobuf(kubeConfig *rest.Config) *rest.Config {
configShallowCopy := *kubeConfig
// Use protobufs for communication with apiserver
config.ContentType = "application/vnd.kubernetes.protobuf"
return config, nil
configShallowCopy.ContentType = "application/vnd.kubernetes.protobuf"
return &configShallowCopy
}

func newKubeConfig() (*rest.Config, error) {
// NewKubeConfig returns a Kubernetes client config given the command line settings.
func NewKubeConfig() (*rest.Config, error) {
if flags.F.InCluster {
klog.V(0).Infof("Using in cluster configuration")
return rest.InClusterConfig()
Expand Down
5 changes: 3 additions & 2 deletions cmd/glbc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,15 @@ func main() {
if err != nil {
klog.Fatalf("Failed to create kubernetes client config: %v", err)
}
kubeConfigForProtobuf := app.KubeConfigForProtobuf(kubeConfig)

kubeClient, err := kubernetes.NewForConfig(kubeConfig)
kubeClient, err := kubernetes.NewForConfig(kubeConfigForProtobuf)
if err != nil {
klog.Fatalf("Failed to create kubernetes client: %v", err)
}

// Due to scaling issues, leader election must be configured with a separate k8s client.
leaderElectKubeClient, err := kubernetes.NewForConfig(restclient.AddUserAgent(kubeConfig, "leader-election"))
leaderElectKubeClient, err := kubernetes.NewForConfig(restclient.AddUserAgent(kubeConfigForProtobuf, "leader-election"))
if err != nil {
klog.Fatalf("Failed to create kubernetes client for leader election: %v", err)
}
Expand Down

0 comments on commit 4151d4d

Please sign in to comment.