Skip to content
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
20 changes: 15 additions & 5 deletions router/core/init_config_poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,14 @@ func getConfigClient(r *Router, cdnProviders map[string]config.CDNStorageProvide
return nil, fmt.Errorf("unknown storage provider id '%s' for execution config", providerID)
}


if r.graphApiToken == "" {
// If the router is running in demo mode, we don't need a graph token
// but the router will just never poll for execution config
if r.demoMode {
return nil, nil
}

return nil, errors.New(
"graph token is required to fetch execution config from CDN. " +
"Alternatively, configure a custom storage provider or specify a static execution config",
Expand Down Expand Up @@ -125,7 +132,7 @@ func InitializeConfigPoller(r *Router, cdnProviders map[string]config.CDNStorage
return nil, err
}

if primaryClient == nil {
if primaryClient == nil && !r.demoMode {
return nil, nil
}

Expand All @@ -140,14 +147,17 @@ func InitializeConfigPoller(r *Router, cdnProviders map[string]config.CDNStorage
return nil, err
}
}

configPoller := configpoller.New(r.graphApiToken,
opts := []configpoller.Option{
configpoller.WithLogger(r.logger),
configpoller.WithPolling(r.routerConfigPollerConfig.PollInterval, r.routerConfigPollerConfig.PollJitter),
configpoller.WithClient(*primaryClient),
configpoller.WithFallbackClient(fallbackClient),
configpoller.WithDemoMode(r.demoMode),
)
}
if primaryClient != nil {
opts = append(opts, configpoller.WithClient(*primaryClient))
}

configPoller := configpoller.New(r.graphApiToken, opts...)

return &configPoller, nil
}
14 changes: 10 additions & 4 deletions router/pkg/controlplane/configpoller/config_poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ func (c *configPoller) Subscribe(ctx context.Context, handler func(newConfig *no
}

func (c *configPoller) getRouterConfig(ctx context.Context) (*routerconfig.Response, error) {
if c.configClient == nil && c.demoMode {
c.logger.Warn("The router is running in demo mode without an execution configuration source, using a demo execution config for testing purposes.")
return &routerconfig.Response{Config: routerconfig.GetDefaultConfig()}, nil
}

if c.configClient == nil {
return nil, errors.New("no execution configuration source found")
}

config, err := c.configClient.RouterConfig(ctx, c.latestRouterConfigVersion, c.latestRouterConfigDate)
if err == nil {
return config, nil
Expand All @@ -133,11 +142,8 @@ func (c *configPoller) getRouterConfig(ctx context.Context) (*routerconfig.Respo
return nil, err
}

if c.demoMode {
c.logger.Warn("The router is running in demo mode. If no execution config is found, the router will start with a demo execution config that can be used for testing purposes.")
}

if c.demoMode && c.fallbackConfigClient == nil && errors.Is(err, ErrConfigNotFound) {
c.logger.Warn("The router is running in demo mode and no execution config has been found, using a demo execution config for testing purposes.")
return &routerconfig.Response{Config: routerconfig.GetDefaultConfig()}, nil
}

Expand Down
Loading