Skip to content

Commit

Permalink
fix: Generate only a single CDS config update per render round
Browse files Browse the repository at this point in the history
So far muliple config updates have been sent in each rendering round, one per gateway-class. This
confuses clients watching for all configs. This change makes sure that we send only single CDS
config update that contains all active configs.
  • Loading branch information
rg0now committed Feb 7, 2024
1 parent 3a08da9 commit ce2870f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
11 changes: 5 additions & 6 deletions internal/renderer/render_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,21 @@ type RenderContext struct {
}

func NewRenderContext(e *event.EventRender, r *Renderer, gc *gwapiv1.GatewayClass) *RenderContext {
logger := r.log
if gc != nil {
logger = r.log.WithValues("gateway-class", gc.GetName())
}
return &RenderContext{
origin: e,
update: event.NewEventUpdate(r.gen),
gc: gc,
gws: store.NewGatewayStore(),
log: r.log.WithValues("gateway-class", gc.GetName()),
log: logger,
}
}

// Merge merges the update queues of two rendering contexts.
func (r *RenderContext) Merge(mergeable *RenderContext) {
if store.GetObjectKey(r.gc) != store.GetObjectKey(mergeable.gc) ||
store.GetObjectKey(r.gwConf) != store.GetObjectKey(mergeable.gwConf) {
panic("MergeUpdateQueue: trying to merge incompatible render contexts")
}

// MUST BE KEPT IN SYNC WITH EventUpdate

// merge upsert queues
Expand Down
7 changes: 5 additions & 2 deletions internal/renderer/render_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@ func (r *Renderer) renderGatewayClass(e *event.EventRender) {
func (r *Renderer) renderManagedGateways(e *event.EventRender) {
r.log.Info("commencing dataplane render", "mode", "managed")

pipelineCtx := NewRenderContext(e, r, nil)

r.log.V(1).Info("obtaining gateway-class objects")
gcs := r.getGatewayClasses()

if len(gcs) == 0 {
r.log.Info("no gateway-class objects found", "event", e.String())
return
Expand Down Expand Up @@ -165,8 +166,10 @@ func (r *Renderer) renderManagedGateways(e *event.EventRender) {

setGatewayClassStatusAccepted(gc, nil)

r.operatorCh <- gcCtx.update.DeepCopy()
pipelineCtx.Merge(gcCtx)
}

r.operatorCh <- pipelineCtx.update.DeepCopy()
}

// renderForGateways renders a configuration for a set of Gateways (c.gws)
Expand Down

0 comments on commit ce2870f

Please sign in to comment.