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

edge sync loopback detection #378

Merged
merged 1 commit into from
May 13, 2024
Merged
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
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