@@ -196,15 +196,15 @@ func NewKongClient(
196
196
configChangeDetector sendconfig.ConfigurationChangeDetector ,
197
197
kongConfigFetcher configfetcher.LastValidConfigFetcher ,
198
198
kongConfigBuilder KongConfigBuilder ,
199
- cacheStores store.CacheStores ,
199
+ cacheStores * store.CacheStores ,
200
200
fallbackConfigGenerator FallbackConfigGenerator ,
201
201
) (* KongClient , error ) {
202
202
c := & KongClient {
203
203
logger : logger ,
204
204
requestTimeout : timeout ,
205
205
diagnostic : diagnostic ,
206
206
prometheusMetrics : metrics .NewCtrlFuncMetrics (),
207
- cache : & cacheStores ,
207
+ cache : cacheStores ,
208
208
kongConfig : kongConfig ,
209
209
eventRecorder : eventRecorder ,
210
210
dbmode : dbMode ,
@@ -444,23 +444,30 @@ func (c *KongClient) Update(ctx context.Context) error {
444
444
if c .kongConfig .FallbackConfiguration {
445
445
var newSnapshotHash store.SnapshotHash
446
446
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
447
449
cacheSnapshot , newSnapshotHash , err = c .cache .TakeSnapshotIfChanged (c .lastProcessedSnapshotHash )
448
450
if err != nil {
449
451
return fmt .Errorf ("failed to take snapshot of cache: %w" , err )
450
452
}
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 {
456
455
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 )
459
463
}
460
464
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
+ }
464
471
}
465
472
466
473
c .logger .V (util .DebugLevel ).Info ("Parsing kubernetes objects into data-plane configuration" )
@@ -700,6 +707,12 @@ func (c *KongClient) sendOutToGatewayClients(
700
707
len (gatewayClients ) > 1 {
701
708
for _ , client := range gatewayClients {
702
709
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
+ }
703
716
}
704
717
}
705
718
@@ -840,7 +853,7 @@ func (c *KongClient) sendToClient(
840
853
sendDiagnostic (diagnostics.DumpMeta {Failed : false , Hash : string (newConfigSHA )}, nil ) // No error occurred.
841
854
// update the lastConfigSHA with the new updated checksum
842
855
client .SetLastConfigSHA (newConfigSHA )
843
-
856
+ client . SetLastCacheStoresHash ( c . lastProcessedSnapshotHash )
844
857
return string (newConfigSHA ), nil
845
858
}
846
859
0 commit comments