@@ -196,15 +196,15 @@ func NewKongClient(
196196 configChangeDetector sendconfig.ConfigurationChangeDetector ,
197197 kongConfigFetcher configfetcher.LastValidConfigFetcher ,
198198 kongConfigBuilder KongConfigBuilder ,
199- cacheStores store.CacheStores ,
199+ cacheStores * store.CacheStores ,
200200 fallbackConfigGenerator FallbackConfigGenerator ,
201201) (* KongClient , error ) {
202202 c := & KongClient {
203203 logger : logger ,
204204 requestTimeout : timeout ,
205205 diagnostic : diagnostic ,
206206 prometheusMetrics : metrics .NewCtrlFuncMetrics (),
207- cache : & cacheStores ,
207+ cache : cacheStores ,
208208 kongConfig : kongConfig ,
209209 eventRecorder : eventRecorder ,
210210 dbmode : dbMode ,
@@ -444,23 +444,30 @@ func (c *KongClient) Update(ctx context.Context) error {
444444 if c .kongConfig .FallbackConfiguration {
445445 var newSnapshotHash store.SnapshotHash
446446 var err error
447+ // Empty snapshot hash means that the cache hasn't changed since the last snapshot was taken. That optimization can be used
448+ // in main code path to avoid unnecessary processing. TODO: https://github.com/Kong/kubernetes-ingress-controller/issues/6095
447449 cacheSnapshot , newSnapshotHash , err = c .cache .TakeSnapshotIfChanged (c .lastProcessedSnapshotHash )
448450 if err != nil {
449451 return fmt .Errorf ("failed to take snapshot of cache: %w" , err )
450452 }
451- // Empty snapshot hash means that the cache hasn't changed since the last snapshot was taken. That optimization can be used
452- // in main code path to avoid unnecessary processing. TODO: https://github.com/Kong/kubernetes-ingress-controller/issues/6095
453- // TODO: We should short-circuit here only if all the Gateways were successfully synced with the current configuration.
454- // https://github.com/Kong/kubernetes-ingress-controller/issues/6219
455- if newSnapshotHash == store .SnapshotHashEmpty {
453+ hasNewSnapshotToBeProcessed := newSnapshotHash != store .SnapshotHashEmpty
454+ if ! hasNewSnapshotToBeProcessed {
456455 c .prometheusMetrics .RecordProcessedConfigSnapshotCacheHit ()
457- c .logger .V (util .DebugLevel ).Info ("No configuration change; pushing config to gateway is not necessary, skipping" )
458- return nil
456+ } else {
457+ c .prometheusMetrics .RecordProcessedConfigSnapshotCacheMiss ()
458+ }
459+ if hasNewSnapshotToBeProcessed {
460+ c .logger .V (util .DebugLevel ).Info ("New configuration snapshot detected" , "hash" , newSnapshotHash )
461+ c .lastProcessedSnapshotHash = newSnapshotHash
462+ c .kongConfigBuilder .UpdateCache (cacheSnapshot )
459463 }
460464
461- c .prometheusMetrics .RecordProcessedConfigSnapshotCacheMiss ()
462- c .lastProcessedSnapshotHash = newSnapshotHash
463- c .kongConfigBuilder .UpdateCache (cacheSnapshot )
465+ if allGatewaysAreInSync := lo .EveryBy (c .clientsProvider .GatewayClientsToConfigure (), func (cl * adminapi.Client ) bool {
466+ return cl .LastCacheStoresHash () == c .lastProcessedSnapshotHash
467+ }); allGatewaysAreInSync {
468+ c .logger .V (util .DebugLevel ).Info ("All gateways are in sync; pushing config is not necessary, skipping" )
469+ return nil
470+ }
464471 }
465472
466473 c .logger .V (util .DebugLevel ).Info ("Parsing kubernetes objects into data-plane configuration" )
@@ -700,6 +707,12 @@ func (c *KongClient) sendOutToGatewayClients(
700707 len (gatewayClients ) > 1 {
701708 for _ , client := range gatewayClients {
702709 client .SetLastConfigSHA ([]byte (shas [0 ]))
710+
711+ // If the last processed snapshot hash is not empty, we should set it to the clients as well.
712+ // It can be empty when FallbackConfiguration feature gate is off.
713+ if c .lastProcessedSnapshotHash != "" {
714+ client .SetLastCacheStoresHash (c .lastProcessedSnapshotHash )
715+ }
703716 }
704717 }
705718
@@ -840,7 +853,7 @@ func (c *KongClient) sendToClient(
840853 sendDiagnostic (diagnostics.DumpMeta {Failed : false , Hash : string (newConfigSHA )}, nil ) // No error occurred.
841854 // update the lastConfigSHA with the new updated checksum
842855 client .SetLastConfigSHA (newConfigSHA )
843-
856+ client . SetLastCacheStoresHash ( c . lastProcessedSnapshotHash )
844857 return string (newConfigSHA ), nil
845858}
846859
0 commit comments