Skip to content

Commit

Permalink
add leader check when applying ggv2 post translation plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
inFocus7 committed Jun 11, 2024
1 parent daed4c5 commit 11fb99b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions projects/gateway2/controller/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func Start(ctx context.Context, cfg StartConfig) error {
k8sGwExtensions,
cfg.ProxyClient,
cfg.QueueStatusForProxies,
cfg.Opts.Identity,
)
if err := mgr.Add(proxySyncer); err != nil {
setupLog.Error(err, "unable to add proxySyncer runnable")
Expand Down
25 changes: 18 additions & 7 deletions projects/gateway2/proxy_syncer/proxy_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package proxy_syncer

import (
"context"
"github.com/solo-io/gloo/pkg/bootstrap/leaderelector"
"strconv"
"time"

Expand Down Expand Up @@ -41,6 +42,8 @@ type ProxySyncer struct {
// queueStatusForProxies stores a list of proxies that need the proxy status synced and the plugin registry
// that produced them for a given sync iteration
queueStatusForProxies QueueStatusForProxiesFn

identity leaderelector.Identity
}

type GatewayInputChannels struct {
Expand Down Expand Up @@ -82,6 +85,7 @@ func NewProxySyncer(
k8sGwExtensions extensions.K8sGatewayExtensions,
proxyClient gloo_solo_io.ProxyClient,
queueStatusForProxies QueueStatusForProxiesFn,
identity leaderelector.Identity,
) *ProxySyncer {
return &ProxySyncer{
controllerName: controllerName,
Expand All @@ -91,6 +95,7 @@ func NewProxySyncer(
k8sGwExtensions: k8sGwExtensions,
proxyReconciler: gloo_solo_io.NewProxyReconciler(proxyClient, statusutils.NewNoOpStatusClient()),
queueStatusForProxies: queueStatusForProxies,
identity: identity,
}
}

Expand Down Expand Up @@ -148,7 +153,7 @@ func (s *ProxySyncer) Start(ctx context.Context) error {
}
}

applyPostTranslationPlugins(ctx, pluginRegistry, &gwplugins.PostTranslationContext{
s.applyPostTranslationPlugins(ctx, pluginRegistry, &gwplugins.PostTranslationContext{
TranslatedGateways: translatedGateways,
})

Expand Down Expand Up @@ -235,15 +240,21 @@ func (s *ProxySyncer) reconcileProxies(ctx context.Context, proxyList gloo_solo_
}
}

func applyPostTranslationPlugins(ctx context.Context, pluginRegistry registry.PluginRegistry, translationContext *gwplugins.PostTranslationContext) {
func (s *ProxySyncer) applyPostTranslationPlugins(ctx context.Context, pluginRegistry registry.PluginRegistry, translationContext *gwplugins.PostTranslationContext) {
ctx = contextutils.WithLogger(ctx, "postTranslation")
logger := contextutils.LoggerFrom(ctx)

for _, postTranslationPlugin := range pluginRegistry.GetPostTranslationPlugins() {
err := postTranslationPlugin.ApplyPostTranslationPlugin(ctx, translationContext)
if err != nil {
logger.Errorf("Error applying post-translation plugin: %v", err)
continue
// we only run post translation plugins on the leader, as they upsert resources
// in portal, for instance, route plugins set up data that are used for modifying resources through the post-translation plugin
if s.identity.IsLeader() {
for _, postTranslationPlugin := range pluginRegistry.GetPostTranslationPlugins() {
err := postTranslationPlugin.ApplyPostTranslationPlugin(ctx, translationContext)
if err != nil {
logger.Errorf("Error applying post-translation plugin: %v", err)
continue
}
}
} else {
logger.Debug("skipping post-translation plugins on non-leader")
}
}

0 comments on commit 11fb99b

Please sign in to comment.