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
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 @@ -152,6 +153,7 @@ type XdsServer struct {
snapshot cachev3.SnapshotCache
srv serverv3.Server
versionCount int64
versionEpoch string

mu sync.Mutex

Expand Down Expand Up @@ -204,6 +206,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 @@ -408,7 +411,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)

// connectEnabled is true when either CONNECT listener (plaintext or TLS) is
// configured; the main_internal cluster/listener only exist to serve them.
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 @@ -965,3 +965,36 @@ func TestXdsServer_BuildTracingRandomSamplingFromPolicy(t *testing.T) {
})
}
}

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
}
}
Loading