Skip to content
Open
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
5 changes: 4 additions & 1 deletion cmd/atenet/internal/router/xds.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package router

import (
"context"
"crypto/rand"
"fmt"
"log/slog"
"net"
Expand Down Expand Up @@ -104,6 +105,7 @@ type XdsServer struct {
snapshot cachev3.SnapshotCache
srv serverv3.Server
versionCount int64
versionEpoch string

mu sync.Mutex

Expand Down Expand Up @@ -145,6 +147,7 @@ func NewXdsServer(xdsPort int) *XdsServer {
xdsPort: xdsPort,
snapshot: cache,
srv: srv,
versionEpoch: strconv.FormatInt(time.Now().Unix(), 10) + "-" + rand.Text()[:8],
extprocPort: 50051, // matches default extproc port
extprocAddr: "127.0.0.1",
ingressPort: 8080,
Expand Down Expand Up @@ -299,7 +302,7 @@ func (x *XdsServer) UpdateSnapshot() error {
defer x.mu.Unlock()

x.versionCount++
ver := strconv.FormatInt(x.versionCount, 10)
ver := x.versionEpoch + "-" + strconv.FormatInt(x.versionCount, 10)

// Clusters
clusters := []types.Resource{
Expand Down
33 changes: 33 additions & 0 deletions cmd/atenet/internal/router/xds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,3 +649,36 @@ func TestXdsServer_SetOtlpCollector_EmptyDisablesTracing(t *testing.T) {
t.Errorf("snapshot contains cluster %q, want it omitted when tracing is disabled", OtlpClusterName)
}
}

func TestSnapshotVersionsUniqueAcrossRestarts(t *testing.T) {
deployAndGetVersion := func(t *testing.T, x *XdsServer) string {
t.Helper()
if err := x.UpdateSnapshot(); err != nil {
t.Fatalf("UpdateSnapshot: %v", err)
}
snap, err := x.snapshot.GetSnapshot(NodeID)
if err != nil {
t.Fatalf("GetSnapshot: %v", err)
}
return snap.GetVersion(resourcev3.ClusterType)
}

seen := map[string]bool{}
first := NewXdsServer(0)
for range 3 {
v := deployAndGetVersion(t, first)
if seen[v] {
t.Fatalf("version %q minted twice by the same server", v)
}
seen[v] = true
}

restarted := NewXdsServer(0)
for range 3 {
v := deployAndGetVersion(t, restarted)
if seen[v] {
t.Fatalf("version %q reused after restart; Envoy holding that version would not receive the new config", v)
}
seen[v] = true
}
}