Skip to content

Commit ff9621b

Browse files
committed
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.
1 parent 7a0a618 commit ff9621b

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

orchestration/orchestrator.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ type Orchestrator struct {
4444
func NewOrchestrator(ctx context.Context, config *Config, tags []tunnelpogs.Tag, localRules []ingress.Rule, log *zerolog.Logger) (*Orchestrator, error) {
4545
o := &Orchestrator{
4646
// Lowest possible version, any remote configuration will have version higher than this
47-
currentVersion: 0,
47+
// Starting at -1 allows a configuration migration (local to remote) to override the current configuration as it
48+
// will start at version 0.
49+
currentVersion: -1,
4850
localRules: localRules,
4951
config: config,
5052
tags: tags,

orchestration/orchestrator_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,35 @@ func TestUpdateConfiguration(t *testing.T) {
181181
require.NotEqual(t, originProxyV10, originProxyV2)
182182
}
183183

184+
// Validates that a new version 0 will be applied if the configuration is loaded locally.
185+
// This will happen when a locally managed tunnel is migrated to remote configuration and receives its first configuration.
186+
func TestUpdateConfiguration_FromMigration(t *testing.T) {
187+
initConfig := &Config{
188+
Ingress: &ingress.Ingress{},
189+
}
190+
orchestrator, err := NewOrchestrator(context.Background(), initConfig, testTags, []ingress.Rule{}, &testLogger)
191+
require.NoError(t, err)
192+
initOriginProxy, err := orchestrator.GetOriginProxy()
193+
require.NoError(t, err)
194+
require.Implements(t, (*connection.OriginProxy)(nil), initOriginProxy)
195+
require.False(t, orchestrator.WarpRoutingEnabled())
196+
197+
configJSONV2 := []byte(`
198+
{
199+
"ingress": [
200+
{
201+
"service": "http_status:404"
202+
}
203+
],
204+
"warp-routing": {
205+
"enabled": true
206+
}
207+
}
208+
`)
209+
updateWithValidation(t, orchestrator, 0, configJSONV2)
210+
require.Len(t, orchestrator.config.Ingress.Rules, 1)
211+
}
212+
184213
// TestConcurrentUpdateAndRead makes sure orchestrator can receive updates and return origin proxy concurrently
185214
func TestConcurrentUpdateAndRead(t *testing.T) {
186215
const (

0 commit comments

Comments
 (0)