Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add kong update sha checks #1282

Merged
merged 1 commit into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/sendconfig/sendconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func PerformUpdate(ctx context.Context,
}
// disable optimization if reverse sync is enabled
if !reverseSync {
// use the previous SHA to determine whether or not to perform an update
if equalSHA(oldSHA, newSHA) {
log.Info("no configuration change, skipping sync to kong")
return oldSHA, nil
Expand Down
15 changes: 5 additions & 10 deletions railgun/internal/proxy/clientgo_cached_proxy_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ type clientgoCachedProxyResolver struct {
k8s client.Client
cache *store.CacheStores

// lastConfigSHA indicates the last SHA sum for the last configuration
// updated in the Kong Proxy and is used to avoid making unnecessary updates.
lastConfigSHA []byte

// kong configuration
kongConfig sendconfig.Kong

Expand Down Expand Up @@ -149,31 +153,22 @@ func (p *clientgoCachedProxyResolver) startCacheServer() {
syncTicker := time.NewTicker(p.stagger)

// updates tracks whether any updates/deletes were tracked this cycle
updates := false
for {
select {
case cobj := <-p.update:
if err := p.cacheUpdate(cobj); err != nil {
p.logger.Error(err, "object could not be updated in the cache and will be discarded")
break
}
updates = true
case cobj := <-p.del:
if err := p.cacheDelete(cobj); err != nil {
p.logger.Error(err, "object could not be deleted from the cache and will be discarded")
break
}
updates = true
case <-syncTicker.C:
// if there are no relevant object updates for this cycle, then there's no reason to
// bother the Kong Proxy with updates from the cache.
if !updates {
break
}
if err := p.updateKongAdmin(); err != nil {
p.logger.Error(err, "could not update kong admin")
}
updates = false
case <-p.ctx.Done():
p.logger.Info("the proxy cache server's context is done, shutting down")
return
Expand Down Expand Up @@ -218,7 +213,7 @@ func (p *clientgoCachedProxyResolver) updateKongAdmin() error {
// apply the configuration update in Kong
timedCtx, cancel := context.WithTimeout(p.ctx, 10*time.Second)
defer cancel()
_, err = sendconfig.PerformUpdate(timedCtx, logrus.StandardLogger(), &p.kongConfig, true, false, targetConfig, nil, nil, nil)
p.lastConfigSHA, err = sendconfig.PerformUpdate(timedCtx, logrus.StandardLogger(), &p.kongConfig, true, false, targetConfig, nil, nil, p.lastConfigSHA)
if err != nil {
return err
}
Expand Down