Skip to content

Commit

Permalink
edge sync loopback detection (#378)
Browse files Browse the repository at this point in the history
  • Loading branch information
gertd authored May 13, 2024
1 parent a02deb9 commit 5c1e017
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion plugins/edge/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ func (p *Plugin) Start(ctx context.Context) error {

p.manager.UpdatePluginStatus(PluginName, &plugins.Status{State: plugins.StateOK})

if p.hasLoopBack() {
p.logger.Warn().
Str("edge-directory", p.config.Addr).
Str("remote-directory", p.topazConfig.DirectoryResolver.Address).
Bool("has-loopback", p.hasLoopBack()).
Msg("EdgePlugin.Start")
return nil
}

go p.scheduler()

return nil
Expand All @@ -86,7 +95,7 @@ func (p *Plugin) Reconfigure(ctx context.Context, config interface{}) {
newConfig := config.(*Config)

// handle enabled status changed
if p.config.Enabled != newConfig.Enabled {
if p.config.Enabled != newConfig.Enabled && !p.hasLoopBack() {
p.logger.Info().Str("id", p.manager.ID).Bool("old", p.config.Enabled).Bool("new", newConfig.Enabled).Msg("sync enabled changed")
if newConfig.Enabled {
p.resetContext()
Expand All @@ -101,6 +110,17 @@ func (p *Plugin) Reconfigure(ctx context.Context, config interface{}) {
p.config.SessionID = uuid.NewString()
}

// A loopback configuration exists when Topaz is configured with a remote directory AND
// an edge sync that points to the same directory instance and tenant as the edge-sync configuration.
// The edge sync can be either explicitly configured in the Topaz configuration file or
// implicitly contributed as part of the discovery response.
// When a loopback is detected, the remote directory configuration takes precedence,
// and the edge sync will be disabled.
func (p *Plugin) hasLoopBack() bool {
return (p.config.Addr == p.topazConfig.DirectoryResolver.Address &&
p.config.TenantID == p.topazConfig.DirectoryResolver.TenantID)
}

func (p *Plugin) SyncNow() {
p.syncNow <- true
}
Expand Down

0 comments on commit 5c1e017

Please sign in to comment.