Skip to content

Commit

Permalink
move krt registration to after the client is warm (#10303)
Browse files Browse the repository at this point in the history
Co-authored-by: soloio-bulldozer[bot] <48420018+soloio-bulldozer[bot]@users.noreply.github.com>
  • Loading branch information
yuval-k and soloio-bulldozer[bot] authored Nov 9, 2024
1 parent 443ef01 commit 7985d0f
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions projects/gateway2/proxy_syncer/proxy_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ type ProxySyncer struct {
statusReport krt.Singleton[report]
mostXdsSnapshots krt.Collection[xdsSnapWrapper]
perclientSnapCollection krt.Collection[xdsSnapWrapper]
proxiesToReconcile krt.Singleton[proxyList]
proxyTrigger *krt.RecomputeTrigger

destRules DestinationRuleIndex
Expand Down Expand Up @@ -449,22 +450,14 @@ func (s *ProxySyncer) Init(ctx context.Context, dbg *krt.DebugHandler) error {
s.perclientSnapCollection = snapshotPerClient(logger.Desugar(), dbg, s.uniqueClients, s.mostXdsSnapshots, epPerClient, clustersPerClient)

// build ProxyList collection as glooProxies change
proxiesToReconcile := krt.NewSingleton(func(kctx krt.HandlerContext) *proxyList {
s.proxiesToReconcile = krt.NewSingleton(func(kctx krt.HandlerContext) *proxyList {
proxies := krt.Fetch(kctx, glooProxies)
var l gloov1.ProxyList
for _, p := range proxies {
l = append(l, p.proxy)
}
return &proxyList{l}
})
// handler to reconcile ProxyList for in-memory proxy client
proxiesToReconcile.Register(func(o krt.Event[proxyList]) {
var l gloov1.ProxyList
if o.Event != controllers.EventDelete {
l = o.Latest().list
}
s.reconcileProxies(l)
})

// as proxies are created, they also contain a reportMap containing status for the Gateway and associated xRoutes (really parentRefs)
// here we will merge reports that are per-Proxy to a singleton Report used to persist to k8s on a timer
Expand Down Expand Up @@ -536,13 +529,6 @@ func (s *ProxySyncer) Start(ctx context.Context) error {
// latestReport will be constantly updated to contain the merged status report for Kube Gateway status
// when timer ticks, we will use the state of the mergedReports at that point in time to sync the status to k8s
latestReportQueue := ggv2utils.NewAsyncQueue[reports.ReportMap]()
s.statusReport.Register(func(o krt.Event[report]) {
if o.Event == controllers.EventDelete {
// TODO: handle garbage collection (see: https://github.com/solo-io/solo-projects/issues/7086)
return
}
latestReportQueue.Enqueue(o.Latest().ReportMap)
})
logger.Infof("waiting for cache to sync")

// wait for krt collections to sync
Expand All @@ -558,6 +544,25 @@ func (s *ProxySyncer) Start(ctx context.Context) error {
}

logger.Infof("caches warm!")

// caches are warm, now we can do registrations
s.statusReport.Register(func(o krt.Event[report]) {
if o.Event == controllers.EventDelete {
// TODO: handle garbage collection (see: https://github.com/solo-io/solo-projects/issues/7086)
return
}
latestReportQueue.Enqueue(o.Latest().ReportMap)
})

// handler to reconcile ProxyList for in-memory proxy client
s.proxiesToReconcile.Register(func(o krt.Event[proxyList]) {
var l gloov1.ProxyList
if o.Event != controllers.EventDelete {
l = o.Latest().list
}
s.reconcileProxies(l)
})

go func() {
timer := time.NewTicker(time.Second * 1)
for {
Expand Down

0 comments on commit 7985d0f

Please sign in to comment.