Skip to content

Commit

Permalink
Merge pull request #2716 from openziti/no-rdm-if-no-edge
Browse files Browse the repository at this point in the history
Don't subscribe to RDM updates if no edge xgress enabled. Fixes #2713
  • Loading branch information
plorenz authored Jan 31, 2025
2 parents 2775fda + 3a0b766 commit 1ab3ec1
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 5 deletions.
2 changes: 2 additions & 0 deletions router/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ type RouterEnv interface {
GetRouterDataModel() *common.RouterDataModel
GetConnectEventsConfig() *ConnectEventsConfig
GetRouterDataModelEnabledConfig() *config.Value[bool]
IsRouterDataModelRequired() bool
MarkRouterDataModelRequired()
}

type ConnectEventsConfig struct {
Expand Down
9 changes: 9 additions & 0 deletions router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ type Router struct {
xwebs []xweb.Instance
xwebFactoryRegistry xweb.Registry
agentBindHandlers []channel.BindHandler
rdmRequired atomic.Bool
}

func (self *Router) GetRouterId() *identity.TokenId {
Expand Down Expand Up @@ -413,6 +414,14 @@ func (self *Router) GetCtrlRateLimiter() rate.AdaptiveRateLimitTracker {
return self.ctrlRateLimiter
}

func (self *Router) IsRouterDataModelRequired() bool {
return self.rdmRequired.Load()
}

func (self *Router) MarkRouterDataModelRequired() {
self.rdmRequired.Store(true)
}

func (self *Router) registerComponents() error {
self.xlinkFactories = make(map[string]xlink.Factory)
xlinkAccepter := newXlinkAccepter(self.forwarder)
Expand Down
5 changes: 5 additions & 0 deletions router/state/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type DisconnectCB func(token string)
type Env interface {
GetRouterDataModelEnabledConfig() *config.Value[bool]
IsRouterDataModelEnabled() bool
IsRouterDataModelRequired() bool
GetCloseNotify() <-chan struct{}
DefaultRequestTimeout() time.Duration
GetMetricsRegistry() metrics2.UsageRegistry
Expand Down Expand Up @@ -251,6 +252,10 @@ func (self *ManagerImpl) manageRouterDataModelSubscription() {
}

func (self *ManagerImpl) checkRouterDataModelSubscription() {
if !self.env.IsRouterDataModelRequired() {
return
}

ctrl := self.env.GetNetworkControllers().GetNetworkController(self.dataModelSubCtrlId.Load())
if ctrl == nil || time.Now().After(self.dataModelSubTimeout) {
if bestCtrl := self.env.GetNetworkControllers().AnyCtrlChannel(); bestCtrl != nil {
Expand Down
2 changes: 2 additions & 0 deletions router/xgress_edge/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ func (factory *Factory) LoadConfig(configMap map[interface{}]interface{}) error
factory.edgeRouterConfig = edgeConfig
factory.stateManager.LoadRouterModel(factory.edgeRouterConfig.Db)

factory.env.MarkRouterDataModelRequired()

go apiproxy.Start(edgeConfig)

return nil
Expand Down
8 changes: 4 additions & 4 deletions router/xgress_edge_tunnel/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ package xgress_edge_tunnel

import (
"github.com/michaelquigley/pfxlog"
"github.com/openziti/ziti/router/xgress_common"
"github.com/openziti/ziti/tunnel"
"github.com/openziti/ziti/controller/xt"
"github.com/openziti/sdk-golang/ziti/edge"
"github.com/openziti/ziti/common/ctrl_msg"
"github.com/openziti/ziti/common/logcontext"
"github.com/openziti/ziti/controller/xt"
"github.com/openziti/ziti/router/xgress"
"github.com/openziti/sdk-golang/ziti/edge"
"github.com/openziti/ziti/router/xgress_common"
"github.com/openziti/ziti/tunnel"
"github.com/pkg/errors"
)

Expand Down
6 changes: 5 additions & 1 deletion router/xgress_edge_tunnel/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ func NewV1Factory(env env.RouterEnv, routerConfig *router.Config, stateManager s

// CreateListener creates a new Edge Tunnel Xgress listener
func (self *Factory) CreateListener(optionsData xgress.OptionsData) (xgress.Listener, error) {
self.env.MarkRouterDataModelRequired()

options := &Options{}
if err := options.load(optionsData); err != nil {
return nil, err
Expand All @@ -125,12 +127,14 @@ func (self *Factory) CreateListener(optionsData xgress.OptionsData) (xgress.List

// CreateDialer creates a new Edge Xgress dialer
func (self *Factory) CreateDialer(optionsData xgress.OptionsData) (xgress.Dialer, error) {
self.env.MarkRouterDataModelRequired()

options := &Options{}
if err := options.load(optionsData); err != nil {
return nil, err
}

pfxlog.Logger().Infof("xgress edge tunnel dialer options: %v", options.ToLoggableString())
pfxlog.Logger().Debugf("xgress edge tunnel dialer options: %v", options.ToLoggableString())

self.tunneler.dialOptions = options
return self.tunneler, nil
Expand Down
4 changes: 4 additions & 0 deletions router/xgress_edge_tunnel_v2/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ func NewFactory(env env.RouterEnv, routerConfig *router.Config, stateManager sta

// CreateListener creates a new Edge Tunnel Xgress listener
func (self *Factory) CreateListener(optionsData xgress.OptionsData) (xgress.Listener, error) {
self.env.MarkRouterDataModelRequired()

options := &Options{}
if err := options.load(optionsData); err != nil {
return nil, err
Expand All @@ -112,6 +114,8 @@ func (self *Factory) CreateListener(optionsData xgress.OptionsData) (xgress.List

// CreateDialer creates a new Edge Xgress dialer
func (self *Factory) CreateDialer(optionsData xgress.OptionsData) (xgress.Dialer, error) {
self.env.MarkRouterDataModelRequired()

options := &Options{}
if err := options.load(optionsData); err != nil {
return nil, err
Expand Down

0 comments on commit 1ab3ec1

Please sign in to comment.