Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherrypick #1051[Fix kube-config for CRD informers] into release-1.9 #1054

Merged
merged 1 commit into from
Mar 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 6 additions & 4 deletions cmd/glbc/app/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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()
Expand Down
16 changes: 12 additions & 4 deletions cmd/glbc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,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 {
Expand Down
3 changes: 3 additions & 0 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,18 +204,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.(*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) {
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{}) {
klog.V(3).Infof("obj(type %T) deleted", obj)
var beConfig *backendconfigv1.BackendConfig
var ok, beOk bool
beConfig, ok = obj.(*backendconfigv1.BackendConfig)
Expand Down