Skip to content

Commit

Permalink
add timer to trigger recompute
Browse files Browse the repository at this point in the history
  • Loading branch information
lgadban committed Oct 16, 2024
1 parent 6f2fc6d commit e6dca2d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions projects/gateway2/proxy_syncer/proxy_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ func (s *ProxySyncer) Start(ctx context.Context) error {
kubeEndpoints := krt.WrapClient(epClient, krt.WithName("Endpoints"))

glooEndpoints := krt.NewManyFromNothing(func(kctx krt.HandlerContext) []*glooEndpoint {
logger.Info("in gloo endpoints transformation")
// NOTE: buildEndpoints(...) effectively duplicates the existing GE endpoint logic
// into a KRT collection; this will be refactored entirely in a follow up from Yuval
return buildEndpoints(kctx, logger, finalUpstreams, kubeEndpoints, services, pods)
Expand All @@ -362,6 +363,7 @@ func (s *ProxySyncer) Start(ctx context.Context) error {
})

xdsSnapshots := krt.NewCollection(glooProxies, func(kctx krt.HandlerContext, proxy glooProxy) *xdsSnapWrapper {
logger.Info("in xds snapshot transformation")
xdsSnap := s.buildXdsSnapshot(
ctx,
kctx,
Expand Down Expand Up @@ -484,16 +486,23 @@ func (s *ProxySyncer) Start(ctx context.Context) error {
applyStatusPlugins(ctx, proxiesWithReports, snap.pluginRegistry)
})

timer := time.NewTicker(time.Second * 1)
needsSync := false
// wait for ctrl-rtime events to trigger syncs
// this will not be necessary once we switch the "front side" of translation to krt
for {
select {
case <-ctx.Done():
contextutils.LoggerFrom(ctx).Debug("context done, stopping proxy syncer")
return nil
case <-timer.C:
if needsSync {
logger.Info("timer tick and needs sync, triggering recompute")
proxyTrigger.TriggerRecomputation()
}
case <-s.inputs.genericEvent.Next():
logger.Info("LAW: got generic event, triggering recompute")
proxyTrigger.TriggerRecomputation()
logger.Info("got generic event, setting needs sync")
needsSync = true
}
}
}
Expand Down

0 comments on commit e6dca2d

Please sign in to comment.