diff --git a/internal/dataplane/kong_client.go b/internal/dataplane/kong_client.go index 582b677081..3c5141b990 100644 --- a/internal/dataplane/kong_client.go +++ b/internal/dataplane/kong_client.go @@ -117,6 +117,9 @@ type KongClient struct { // SHAs is a slice is configuration hashes send in last batch send. SHAs []string + // TODO: comment + LastValidKongState *kongstate.KongState + // clientsProvider allows retrieving the most recent set of clients. clientsProvider clients.AdminAPIClientsProvider @@ -386,6 +389,13 @@ func (c *KongClient) Update(ctx context.Context) error { // In case of a failure in syncing configuration with Gateways, propagate the error. if gatewaysSyncErr != nil { + if c.LastValidKongState != nil { + _, fallbackSyncErr := c.sendOutToGatewayClients(ctx, c.LastValidKongState, c.kongConfig) + if fallbackSyncErr != nil { + return errors.Join(gatewaysSyncErr, fallbackSyncErr) + } + c.logger.Debug("due to errors in the current config, the last valid config has been pushed to Gateways") + } return gatewaysSyncErr } @@ -503,6 +513,10 @@ func (c *KongClient) sendToClient( // update the lastConfigSHA with the new updated checksum client.SetLastConfigSHA(newConfigSHA) + if len(entityErrors) == 0 { + c.LastValidKongState = s + } + return string(newConfigSHA), nil } diff --git a/test/integration/config_error_fallback_test.go b/test/integration/config_error_fallback_test.go new file mode 100644 index 0000000000..65fa9f79cc --- /dev/null +++ b/test/integration/config_error_fallback_test.go @@ -0,0 +1,14 @@ +//go:build integration_tests + +package integration + +import ( + "testing" +) + +func TestConfigErrorWithFallback(t *testing.T) { + // This test is NOT parallel. + // The broken configuration prevents all updates and will break unrelated tests + + // TODO: add test +}