mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/kube-vip/kube-vip.git
synced 2026-09-20 08:03:47 +08:00
Fixed services error handling (#1478)
* Fixed services error handling Signed-off-by: Patryk Strusiewicz-Surmacki <patryk.pawel.strusiewicz-surmacki@external.telekom.de> * Removed redundant code Signed-off-by: Patryk Strusiewicz-Surmacki <patryk.pawel.strusiewicz-surmacki@external.telekom.de> --------- Signed-off-by: Patryk Strusiewicz-Surmacki <patryk.pawel.strusiewicz-surmacki@external.telekom.de> Co-authored-by: Patryk Strusiewicz-Surmacki <patryk.pawel.strusiewicz-surmacki@external.telekom.de>
This commit is contained in:
committed by
GitHub
parent
dcd8fe0392
commit
ca47abfc3a
@@ -75,14 +75,7 @@ func (p *Processor) AddOrModify(svcCtx *servicecontext.Context, event watch.Even
|
||||
// start leader election if it's enabled and not already started
|
||||
if !svcCtx.IsActive && p.config.EnableServicesElection {
|
||||
wg.Go(func() {
|
||||
for {
|
||||
select {
|
||||
case <-svcCtx.Ctx.Done():
|
||||
return
|
||||
default:
|
||||
startLeaderElection(svcCtx, service, serviceFunc, wg)
|
||||
}
|
||||
}
|
||||
startLeaderElection(svcCtx, service, serviceFunc, wg)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -177,10 +170,6 @@ func startLeaderElection(svcCtx *servicecontext.Context, service *v1.Service, se
|
||||
if err != nil {
|
||||
log.Error(err.Error())
|
||||
}
|
||||
if !svcCtx.HasEndpoints.Load() {
|
||||
log.Debug("there are no available endpoints for this service, exiting watch", "service", service.Name, "uid", service.UID)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -389,7 +389,8 @@ func (sm *Manager) startMode(ctx context.Context) error {
|
||||
w.ConfigureServices()
|
||||
|
||||
if err = w.StartServices(modeCtx); err != nil {
|
||||
return fmt.Errorf("failed to start services: %w", err)
|
||||
sm.Kill()
|
||||
return fmt.Errorf("failed to reconcile services: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -131,8 +131,8 @@ func (p *Processor) AddOrModify(ctx context.Context, event watch.Event, serviceF
|
||||
|
||||
_, usesCommonLease := svc.Annotations[kubevip.ServiceLease]
|
||||
if usesCommonLease && svc.Spec.ExternalTrafficPolicy != v1.ServiceExternalTrafficPolicyTypeCluster {
|
||||
return false, fmt.Errorf("annotation %q cannot be used with service traffic policy other than %q",
|
||||
kubevip.ServiceLease, v1.ServiceExternalTrafficPolicyTypeCluster)
|
||||
return false, fmt.Errorf("annotation %q cannot be used with service traffic policy other than %q, service %s/%s",
|
||||
kubevip.ServiceLease, v1.ServiceExternalTrafficPolicyTypeCluster, svc.Namespace, svc.Name)
|
||||
}
|
||||
|
||||
svcCtx, err := p.getServiceContext(svc.UID)
|
||||
|
||||
@@ -55,9 +55,12 @@ func (p *Processor) ServicesWatcher(ctx context.Context, serviceFunc func(*servi
|
||||
wg := sync.WaitGroup{}
|
||||
defer wg.Wait()
|
||||
|
||||
watcherCtx, watcherCancel := context.WithCancel(ctx)
|
||||
defer watcherCancel()
|
||||
|
||||
wg.Go(func() {
|
||||
<-ctx.Done()
|
||||
log.Debug("(svcs) context cancelled")
|
||||
<-watcherCtx.Done()
|
||||
log.Debug("(svcs) watcher context cancelled")
|
||||
rw.Stop()
|
||||
p.Stop()
|
||||
})
|
||||
@@ -70,7 +73,7 @@ func (p *Processor) ServicesWatcher(ctx context.Context, serviceFunc func(*servi
|
||||
// We need to inspect the event and get ResourceVersion out of it
|
||||
switch event.Type {
|
||||
case watch.Added, watch.Modified:
|
||||
restart, err := p.AddOrModify(ctx, event, serviceFunc, &wg)
|
||||
restart, err := p.AddOrModify(watcherCtx, event, serviceFunc, &wg)
|
||||
if restart {
|
||||
break
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user