From 4f65a718b4fc0bc5d098b3d23c2097fb0b43e18a Mon Sep 17 00:00:00 2001 From: Satish Matti Date: Wed, 11 Mar 2020 15:58:02 -0700 Subject: [PATCH] Cherrypick #1051[Fix kube-config for CRD informers] into release-1.8 --- cmd/glbc/app/clients.go | 10 ++++++---- cmd/glbc/main.go | 16 ++++++++++++---- pkg/controller/controller.go | 9 ++++++--- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/cmd/glbc/app/clients.go b/cmd/glbc/app/clients.go index 4940d9108d..9f6ca7bdf7 100644 --- a/cmd/glbc/app/clients.go +++ b/cmd/glbc/app/clients.go @@ -44,9 +44,10 @@ const ( cloudClientRetryInterval = 10 * time.Second ) -// NewKubeConfig returns a Kubernetes client config given the command line settings. -func NewKubeConfig() (*rest.Config, error) { - config, err := newKubeConfig() +// NewKubeConfigForProtobuf returns a Kubernetes client config that uses protobufs +// for given the command line settings. +func NewKubeConfigForProtobuf() (*rest.Config, error) { + config, err := NewKubeConfig() if err != nil { return nil, err } @@ -55,7 +56,8 @@ func NewKubeConfig() (*rest.Config, error) { return config, nil } -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() diff --git a/cmd/glbc/main.go b/cmd/glbc/main.go index afe328de38..d5388cb949 100644 --- a/cmd/glbc/main.go +++ b/cmd/glbc/main.go @@ -70,22 +70,30 @@ func main() { klog.V(2).Infof("Flags = %+v", flags.F) defer klog.Flush() - kubeConfig, err := app.NewKubeConfig() + // Create kube-config that uses protobufs to communicate with API server. + kubeConfigForProtobuf, err := app.NewKubeConfigForProtobuf() if err != nil { - klog.Fatalf("Failed to create kubernetes client config: %v", err) + klog.Fatalf("Failed to create kubernetes client config for protobuf: %v", err) } - 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) } + // Create kube-config for CRDs. + // TODO(smatti): Migrate to use protobuf once CRD supports. + kubeConfig, err := app.NewKubeConfig() + if err != nil { + klog.Fatalf("Failed to create kubernetes client config: %v", err) + } + var backendConfigClient backendconfigclient.Interface crdClient, err := crdclient.NewForConfig(kubeConfig) if err != nil { diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index d0fc01640f..ab88ec6a8f 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -204,19 +204,22 @@ func NewLoadBalancerController( // BackendConfig event handlers. ctx.BackendConfigInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { - beConfig := obj.(*backendconfigv1beta1.BackendConfig) + klog.V(3).Infof("obj(type %T) added", obj) + beConfig := obj.(*backendconfigv1.BackendConfig) ings := operator.Ingresses(ctx.Ingresses().List()).ReferencesBackendConfig(beConfig, operator.Services(ctx.Services().List())).AsList() lbc.ingQueue.Enqueue(convert(ings)...) }, UpdateFunc: func(old, cur interface{}) { if !reflect.DeepEqual(old, cur) { - beConfig := cur.(*backendconfigv1beta1.BackendConfig) + klog.V(3).Infof("obj(type %T) updated", cur) + beConfig := cur.(*backendconfigv1.BackendConfig) ings := operator.Ingresses(ctx.Ingresses().List()).ReferencesBackendConfig(beConfig, operator.Services(ctx.Services().List())).AsList() lbc.ingQueue.Enqueue(convert(ings)...) } }, DeleteFunc: func(obj interface{}) { - var beConfig *backendconfigv1beta1.BackendConfig + klog.V(3).Infof("obj(type %T) deleted", obj) + var beConfig *backendconfigv1.BackendConfig var ok, beOk bool beConfig, ok = obj.(*backendconfigv1beta1.BackendConfig) if !ok {