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 1cc25e407c..32d1cc8386 100644 --- a/cmd/glbc/main.go +++ b/cmd/glbc/main.go @@ -70,28 +70,36 @@ 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) } var dynamicClient dynamic.Interface if flags.F.EnableCSM { - dynamicClient, err = dynamic.NewForConfig(kubeConfig) + dynamicClient, err = dynamic.NewForConfig(kubeConfigForProtobuf) if err != nil { klog.Fatalf("Failed to create kubernetes dynamic 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 bd93c9d30c..27871ddd37 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -197,18 +197,21 @@ func NewLoadBalancerController( // BackendConfig event handlers. ctx.BackendConfigInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { + klog.V(3).Infof("obj(type %T) added", obj) beConfig := obj.(*backendconfigv1beta1.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) { + klog.V(3).Infof("obj(type %T) updated", cur) beConfig := cur.(*backendconfigv1beta1.BackendConfig) ings := operator.Ingresses(ctx.Ingresses().List()).ReferencesBackendConfig(beConfig, operator.Services(ctx.Services().List())).AsList() lbc.ingQueue.Enqueue(convert(ings)...) } }, DeleteFunc: func(obj interface{}) { + klog.V(3).Infof("obj(type %T) deleted", obj) var beConfig *backendconfigv1beta1.BackendConfig var ok, beOk bool beConfig, ok = obj.(*backendconfigv1beta1.BackendConfig)