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

service controller: add node event handlers for faster LB backend sync #81185

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 19 additions & 2 deletions pkg/controller/service/controller.go
Expand Up @@ -19,11 +19,10 @@ package service
import (
"context"
"fmt"
"reflect"
"sync"
"time"

"reflect"

v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/labels"
Expand Down Expand Up @@ -101,6 +100,7 @@ type serviceCache struct {
type Controller struct {
cloud cloudprovider.Interface
knownHosts []*v1.Node
knownHostsLock sync.Mutex
servicesToUpdate []*v1.Service
kubeClient clientset.Interface
clusterName string
Expand Down Expand Up @@ -175,6 +175,21 @@ func New(
s.serviceLister = serviceInformer.Lister()
s.serviceListerSynced = serviceInformer.Informer().HasSynced

nodeInformer.Informer().AddEventHandlerWithResyncPeriod(
cache.ResourceEventHandlerFuncs{
AddFunc: func(cur interface{}) {
s.nodeSyncLoop()
},
UpdateFunc: func(old, cur interface{}) {
s.nodeSyncLoop()
},
DeleteFunc: func(old interface{}) {
s.nodeSyncLoop()
},
},
time.Duration(0),
)

if err := s.init(); err != nil {
return nil, err
}
Expand Down Expand Up @@ -646,6 +661,8 @@ func getNodeConditionPredicate() NodeConditionPredicate {
// nodeSyncLoop handles updating the hosts pointed to by all load
// balancers whenever the set of nodes in the cluster changes.
func (s *Controller) nodeSyncLoop() {
s.knownHostsLock.Lock()
defer s.knownHostsLock.Unlock()
newHosts, err := listWithPredicate(s.nodeLister, getNodeConditionPredicate())
if err != nil {
runtime.HandleError(fmt.Errorf("Failed to retrieve current set of nodes from node lister: %v", err))
Expand Down