Skip to content

Commit

Permalink
address comments Again
Browse files Browse the repository at this point in the history
  • Loading branch information
randmonkey committed Nov 2, 2023
1 parent eca994d commit b201d82
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
6 changes: 6 additions & 0 deletions internal/clients/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ func (c *AdminAPIClientsManager) GatewayClients() []*adminapi.Client {
return lo.Values(c.readyGatewayClients)
}

// GatewayClientsToConfigure returns the gateway clients need to be configured with the new configuration
// in sending generated configurations.
// In DBLess mode, it returns ALL gateway clients
// because we need to update configurations of each gateway instance.
// In DB-backed mode, it returns ONE random gateway client
// because we only need to send configurations to one gateway instance, and other instances could be synced from DB.
func (c *AdminAPIClientsManager) GatewayClientsToConfigure() []*adminapi.Client {
c.lock.RLock()
defer c.lock.RUnlock()
Expand Down
8 changes: 5 additions & 3 deletions internal/dataplane/kong_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,9 +474,11 @@ func (c *KongClient) sendOutToGatewayClients(
return nil, err
}

// After a successful configuration update in DB mode, we should propagate the SHA from
// the chosen client to other clients as well as they will pick the configuration from the shared database.
if !dataplaneutil.IsDBLessMode(c.dbmode) &&
// After a successful configuration update in DB mode,
// since only ONE gateway client is chosen to send requests and store SHA of latest configurations,
// we should propagate the SHA from the chosen client to other clients
// as well as they will pick the configuration from the shared database.
if dataplaneutil.DBBacked(c.dbmode) &&
len(gatewayClients) > 1 {
for _, client := range gatewayClients {
client.SetLastConfigSHA([]byte(shas[0]))
Expand Down
6 changes: 6 additions & 0 deletions internal/util/dataplane/mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ package dataplane
func IsDBLessMode(mode string) bool {
return mode == "" || mode == "off"
}

// DBBacked returns true if the gateway is DB backed.
// reverse of IsDBLessMode for readability.
func DBBacked(mode string) bool {
return !IsDBLessMode(mode)
}

0 comments on commit b201d82

Please sign in to comment.