Skip to content

Commit

Permalink
feat: store and push last valid config
Browse files Browse the repository at this point in the history
Signed-off-by: Mattia Lavacca <lavacca.mattia@gmail.com>
  • Loading branch information
mlavacca committed Jun 21, 2023
1 parent b1db863 commit b5ea699
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions internal/dataplane/kong_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down
14 changes: 14 additions & 0 deletions test/integration/config_error_fallback_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//go:build integration_tests

package integration

import (
"testing"
)

func TestConfigErrorWithFallback(t *testing.T) {

Check failure on line 9 in test/integration/config_error_fallback_test.go

View workflow job for this annotation

GitHub Actions / linters / lint

unused-parameter: parameter 't' seems to be unused, consider removing or renaming it as _ (revive)
// This test is NOT parallel.
// The broken configuration prevents all updates and will break unrelated tests

// TODO: add test
}

0 comments on commit b5ea699

Please sign in to comment.