Make pod status updates concurrent. (#433)
This uses the same number of workers as the pod sync workers. We may want to start a worker queue here instead, but I think for now this is ok, particularly because we are limiting the number of goroutines being spun up at once.
This commit is contained in:
@@ -3,6 +3,7 @@ package vkubelet
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/cpuguy83/strongerrors/status/ocstatus"
|
"github.com/cpuguy83/strongerrors/status/ocstatus"
|
||||||
@@ -138,19 +139,31 @@ func (s *Server) updatePodStatuses(ctx context.Context) {
|
|||||||
pods := s.resourceManager.GetPods()
|
pods := s.resourceManager.GetPods()
|
||||||
span.AddAttributes(trace.Int64Attribute("nPods", int64(len(pods))))
|
span.AddAttributes(trace.Int64Attribute("nPods", int64(len(pods))))
|
||||||
|
|
||||||
for _, pod := range pods {
|
sema := make(chan struct{}, s.podSyncWorkers)
|
||||||
select {
|
var wg sync.WaitGroup
|
||||||
case <-ctx.Done():
|
wg.Add(len(pods))
|
||||||
span.Annotate(nil, ctx.Err().Error())
|
|
||||||
return
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := s.updatePodStatus(ctx, pod); err != nil {
|
for _, pod := range pods {
|
||||||
logger := log.G(ctx).WithField("pod", pod.GetName()).WithField("namespace", pod.GetNamespace()).WithField("status", pod.Status.Phase).WithField("reason", pod.Status.Reason)
|
go func(pod *corev1.Pod) {
|
||||||
logger.Error(err)
|
defer wg.Done()
|
||||||
}
|
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
span.SetStatus(ocstatus.FromError(ctx.Err()))
|
||||||
|
return
|
||||||
|
case sema <- struct{}{}:
|
||||||
|
}
|
||||||
|
defer func() { <-sema }()
|
||||||
|
|
||||||
|
if err := s.updatePodStatus(ctx, pod); err != nil {
|
||||||
|
logger := log.G(ctx).WithField("pod", pod.GetName()).WithField("namespace", pod.GetNamespace()).WithField("status", pod.Status.Phase).WithField("reason", pod.Status.Reason)
|
||||||
|
logger.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
}(pod)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) updatePodStatus(ctx context.Context, pod *corev1.Pod) error {
|
func (s *Server) updatePodStatus(ctx context.Context, pod *corev1.Pod) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user