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

PR : faster detection of loxilb instance liveness #85

Merged
merged 1 commit into from
Dec 8, 2023
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
25 changes: 13 additions & 12 deletions cmd/loxilb-agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func run(o *Options) error {
loxiLBLiveCh := make(chan *api.LoxiClient, 50)
loxiLBPurgeCh := make(chan *api.LoxiClient, 5)
loxiLBSelMasterEvent := make(chan bool)
loxiLBDeadCh := make(chan bool, 64)
loxiLBDeadCh := make(chan struct{}, 64)

if len(networkConfig.LoxilbURLs) > 0 {
for _, lbURL := range networkConfig.LoxilbURLs {
Expand All @@ -179,22 +179,23 @@ func run(o *Options) error {
informerFactory,
)

go wait.Until(func() {
select {
case <-loxiLBDeadCh:
roleEvents := func() {
for range loxiLBDeadCh {
if networkConfig.SetRoles != "" {
klog.Infof("Running select-roles")
lbManager.SelectLoxiLBRoles(true, loxiLBSelMasterEvent)
}
default:
if len(networkConfig.LoxilbURLs) <= 0 {
lbManager.DiscoverLoxiLBServices(loxiLBLiveCh, loxiLBDeadCh, loxiLBPurgeCh)
}
lbManager.DiscoverLoxiLBPeerServices(loxiLBLiveCh, loxiLBDeadCh, loxiLBPurgeCh)
}
}
go roleEvents()
go wait.Until(func() {
if len(networkConfig.LoxilbURLs) <= 0 {
lbManager.DiscoverLoxiLBServices(loxiLBLiveCh, loxiLBDeadCh, loxiLBPurgeCh)
}
lbManager.DiscoverLoxiLBPeerServices(loxiLBLiveCh, loxiLBDeadCh, loxiLBPurgeCh)

if networkConfig.SetRoles != "" {
lbManager.SelectLoxiLBRoles(true, loxiLBSelMasterEvent)
}
if networkConfig.SetRoles != "" {
lbManager.SelectLoxiLBRoles(true, loxiLBSelMasterEvent)
}
}, time.Second*20, stopCh)

Expand Down
4 changes: 2 additions & 2 deletions pkg/agent/manager/loadbalancer/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,7 @@ func (m *Manager) addIngress(service *corev1.Service, newIP net.IP) {
append(service.Status.LoadBalancer.Ingress, corev1.LoadBalancerIngress{IP: newIP.String()})
}

func (m *Manager) DiscoverLoxiLBServices(loxiLBAliveCh chan *api.LoxiClient, loxiLBDeadCh chan bool, loxiLBPurgeCh chan *api.LoxiClient) {
func (m *Manager) DiscoverLoxiLBServices(loxiLBAliveCh chan *api.LoxiClient, loxiLBDeadCh chan struct{}, loxiLBPurgeCh chan *api.LoxiClient) {
var tmploxilbClients []*api.LoxiClient
// DNS lookup (not used now)
// ips, err := net.LookupIP("loxilb-lb-service")
Expand Down Expand Up @@ -1293,7 +1293,7 @@ func (m *Manager) DiscoverLoxiLBServices(loxiLBAliveCh chan *api.LoxiClient, lox
m.LoxiClients = tmp
}

func (m *Manager) DiscoverLoxiLBPeerServices(loxiLBAliveCh chan *api.LoxiClient, loxiLBDeadCh chan bool, loxiLBPurgeCh chan *api.LoxiClient) {
func (m *Manager) DiscoverLoxiLBPeerServices(loxiLBAliveCh chan *api.LoxiClient, loxiLBDeadCh chan struct{}, loxiLBPurgeCh chan *api.LoxiClient) {
var tmploxilbPeerClients []*api.LoxiClient
ips, err := k8s.GetServiceEndPoints(m.kubeClient, "loxilb-peer-service", "kube-system")
if len(ips) > 0 {
Expand Down
6 changes: 3 additions & 3 deletions pkg/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type LoxiClient struct {
}

// apiServer is string. what format? http://10.0.0.1 or 10.0.0.1
func NewLoxiClient(apiServer string, aliveCh chan *LoxiClient, deadCh chan bool, peerOnly bool) (*LoxiClient, error) {
func NewLoxiClient(apiServer string, aliveCh chan *LoxiClient, deadCh chan struct{}, peerOnly bool) (*LoxiClient, error) {

client := &http.Client{}

Expand Down Expand Up @@ -68,7 +68,7 @@ func NewLoxiClient(apiServer string, aliveCh chan *LoxiClient, deadCh chan bool,
return lc, nil
}

func (l *LoxiClient) StartLoxiHealthCheckChan(aliveCh chan *LoxiClient, deadCh chan bool) {
func (l *LoxiClient) StartLoxiHealthCheckChan(aliveCh chan *LoxiClient, deadCh chan struct{}) {
l.IsAlive = false

go wait.Until(func() {
Expand All @@ -79,7 +79,7 @@ func (l *LoxiClient) StartLoxiHealthCheckChan(aliveCh chan *LoxiClient, deadCh c
if time.Duration(time.Since(l.DeadSigTs).Seconds()) >= 3 && l.MasterLB {
klog.Infof("LoxiHealthCheckChan: master down")
l.DeadSigTs = time.Now()
deadCh <- true
deadCh <- struct{}{}
} else {
l.DeadSigTs = time.Now()
}
Expand Down
Loading