From ff9621bbd521dd76c0464481755f86b7e4518b67 Mon Sep 17 00:00:00 2001 From: Devin Carr Date: Fri, 5 May 2023 12:41:11 -0700 Subject: [PATCH] TUN-7404: Default configuration version set to -1 We need to set the default configuration to -1 to accommodate local to remote configuration migrations that will set the configuration version to 0. This make's sure to override the local configuration with the new remote configuration when sent as it does a check against the local current configuration version. --- orchestration/orchestrator.go | 4 +++- orchestration/orchestrator_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/orchestration/orchestrator.go b/orchestration/orchestrator.go index 5967ee84..a45dbfc4 100644 --- a/orchestration/orchestrator.go +++ b/orchestration/orchestrator.go @@ -44,7 +44,9 @@ type Orchestrator struct { func NewOrchestrator(ctx context.Context, config *Config, tags []tunnelpogs.Tag, localRules []ingress.Rule, log *zerolog.Logger) (*Orchestrator, error) { o := &Orchestrator{ // Lowest possible version, any remote configuration will have version higher than this - currentVersion: 0, + // Starting at -1 allows a configuration migration (local to remote) to override the current configuration as it + // will start at version 0. + currentVersion: -1, localRules: localRules, config: config, tags: tags, diff --git a/orchestration/orchestrator_test.go b/orchestration/orchestrator_test.go index 17d54f47..b9bac16a 100644 --- a/orchestration/orchestrator_test.go +++ b/orchestration/orchestrator_test.go @@ -181,6 +181,35 @@ func TestUpdateConfiguration(t *testing.T) { require.NotEqual(t, originProxyV10, originProxyV2) } +// Validates that a new version 0 will be applied if the configuration is loaded locally. +// This will happen when a locally managed tunnel is migrated to remote configuration and receives its first configuration. +func TestUpdateConfiguration_FromMigration(t *testing.T) { + initConfig := &Config{ + Ingress: &ingress.Ingress{}, + } + orchestrator, err := NewOrchestrator(context.Background(), initConfig, testTags, []ingress.Rule{}, &testLogger) + require.NoError(t, err) + initOriginProxy, err := orchestrator.GetOriginProxy() + require.NoError(t, err) + require.Implements(t, (*connection.OriginProxy)(nil), initOriginProxy) + require.False(t, orchestrator.WarpRoutingEnabled()) + + configJSONV2 := []byte(` +{ + "ingress": [ + { + "service": "http_status:404" + } + ], + "warp-routing": { + "enabled": true + } +} +`) + updateWithValidation(t, orchestrator, 0, configJSONV2) + require.Len(t, orchestrator.config.Ingress.Rules, 1) +} + // TestConcurrentUpdateAndRead makes sure orchestrator can receive updates and return origin proxy concurrently func TestConcurrentUpdateAndRead(t *testing.T) { const (