mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/kube-vip/kube-vip.git
synced 2026-09-20 08:03:47 +08:00
@@ -290,8 +290,8 @@ func (p *Processor) startLeaderElection(svcCtx *servicecontext.Context, service
|
||||
default:
|
||||
leaseNamespace, serviceLease := lease.ServiceName(service)
|
||||
id := lease.NewID(p.config.LeaderElectionType, leaseNamespace, serviceLease)
|
||||
// The lease is only dropped once its last service is gone, which races
|
||||
// with this loop noticing its own service context is done.
|
||||
// The lease is retired once its last service is gone, so an absent one means
|
||||
// this loop has nothing left to elect for.
|
||||
l := p.leaseMgr.Get(id)
|
||||
if l == nil {
|
||||
return
|
||||
|
||||
@@ -46,6 +46,14 @@ func (p *Processor) StartServicesLeaderElection(svcCtx *servicecontext.Context,
|
||||
return fmt.Errorf("no existing lease found for service %q with UID %q", service.Name, service.UID)
|
||||
}
|
||||
|
||||
// A cancelled service context means this call belongs to a torn-down incarnation of
|
||||
// the service. Its replacement is built as Cancel -> Delete -> Add, so the lease
|
||||
// fetched above may already be the replacement's. Registering on it here would let
|
||||
// the cleanup goroutine below retire a lease that is still in use.
|
||||
if err := svcCtx.Ctx.Err(); err != nil {
|
||||
return fmt.Errorf("service context cancelled before election start: %w", err)
|
||||
}
|
||||
|
||||
isNew := svcLease.Add(objectName)
|
||||
|
||||
svcLease.Lock()
|
||||
|
||||
Reference in New Issue
Block a user