Skip to content

Agent Mesh

internal/node: drop legacy control-plane-URL backward-compat code

Antonio Ojead329761a262e
diff --git a/internal/node/controlplane.go b/internal/node/controlplane.go
index 823d0cb7..959fcb75 100644
--- a/internal/node/controlplane.go
+++ b/internal/node/controlplane.go
@@ -92,23 +92,6 @@ func SyncMeshConfig(ctx context.Context, s *Store) ([]byte, []multiaddr.Multiadd
routerAddrs = append(routerAddrs, ma)
}
- // Fallback for legacy databases: extract URL from multiaddr
- if controlPlaneURL == "" && len(routerAddrs) > 0 {
- for _, addr := range routerAddrs {
- if val, err := addr.ValueForProtocol(multiaddr.P_DNS4); err == nil {
- controlPlaneURL = "https://" + val
- break
- }
- if val, err := addr.ValueForProtocol(multiaddr.P_DNSADDR); err == nil {
- controlPlaneURL = "https://" + val
- break
- }
- }
- if controlPlaneURL != "" {
- logger.Infof("Extracted legacy control plane URL from multiaddrs: %s", controlPlaneURL)
- }
- }
-
// If we have a URL, fetch the latest info
if controlPlaneURL != "" {
logger.Infof("Fetching latest router addresses via HTTP from %s...", controlPlaneURL)
diff --git a/internal/node/store.go b/internal/node/store.go
index 0108422a..ff88a8d6 100644
--- a/internal/node/store.go
+++ b/internal/node/store.go
@@ -266,10 +266,6 @@ func (s *Store) ResetMeshIdentity() error {
"control_plane_public_key",
"router_addresses",
"control_plane_url",
- // Legacy pre-rename keys, cleared for good measure.
- "hub_public_key",
- "hub_addresses",
- "hub_url",
} {
if err := b.Delete([]byte(key)); err != nil {
return err
diff --git a/tests/integration/login_test.go b/tests/integration/login_test.go
index 4b0734a7..de1da1d4 100644
--- a/tests/integration/login_test.go
+++ b/tests/integration/login_test.go
@@ -322,85 +322,3 @@ func TestSamNodeRunControlPlaneMismatch(t *testing.T) {
t.Fatalf("expected re-enroll against B after reset to keep running, got: %v\nstdout:\n%s\nstderr:\n%s", err, stdout, stderr)
}
}
-
-// TestSamNodeRunLegacyStoreNoFalseMismatch covers nodes enrolled before
-// control-plane URL tracking existed (stored URL empty, identity/pubkey
-// still valid): passing --control-plane matching reality must not be
-// treated as a mismatch (this would break unattended upgrades/restarts of
-// pre-existing deployments), and the URL should be backfilled for next time.
-func TestSamNodeRunLegacyStoreNoFalseMismatch(t *testing.T) {
- nodeBin := buildBinary(t, "./cmd/sam-node")
- tmpHome := t.TempDir()
- env := []string{
- "HOME=" + tmpHome,
- "XDG_CONFIG_HOME=" + filepath.Join(tmpHome, ".config"),
- }
-
- _, routerAddr := startMockRouter(t)
-
- stdout, stderr, err := runCommand(
- t, repoRoot(t), 3*time.Second, env, "",
- nodeBin, "run", "--control-plane", routerAddr, "--jwt", "test-jwt",
- "--listen", "/ip4/127.0.0.1/udp/0/quic-v1",
- "--listen", "/ip4/127.0.0.1/tcp/0",
- "--bind-addr", "127.0.0.1:0",
- "--api-token-path", tokenPath(t, "dummy-token"),
- )
- if err != context.DeadlineExceeded {
- t.Fatalf("expected initial enroll+run to keep running, got: %v\nstdout:\n%s\nstderr:\n%s", err, stdout, stderr)
- }
-
- // Simulate a legacy store: clear just the tracked control-plane URL,
- // keeping the identity, pubkey, and router addresses.
- dataDir := filepath.Join(tmpHome, ".config", "sam-mesh")
- store, err := node.NewStore(dataDir)
- if err != nil {
- t.Fatalf("failed to open store: %v", err)
- }
- if err := store.SaveControlPlaneURL(""); err != nil {
- t.Fatalf("failed to clear control plane URL: %v", err)
- }
- if err := store.Close(); err != nil {
- t.Fatalf("failed to close store: %v", err)
- }
-
- // Passing the (correct) --control-plane on this now-legacy-shaped store
- // must not be treated as a mismatch.
- stdout, stderr, err = runCommand(
- t, repoRoot(t), 3*time.Second, env, "",
- nodeBin, "run", "--control-plane", routerAddr,
- "--listen", "/ip4/127.0.0.1/udp/0/quic-v1",
- "--listen", "/ip4/127.0.0.1/tcp/0",
- "--bind-addr", "127.0.0.1:0",
- "--api-token-path", tokenPath(t, "dummy-token"),
- )
- if err != context.DeadlineExceeded {
- t.Fatalf("expected legacy store + matching --control-plane to keep running, got: %v\nstdout:\n%s\nstderr:\n%s", err, stdout, stderr)
- }
- if out := stdout + stderr; strings.Contains(out, "does not match the mesh") {
- t.Fatalf("legacy store must not be treated as a mismatch:\n%s", out)
- }
-
- // The URL should now be backfilled for future runs.
- store, err = node.NewStore(dataDir)
- if err != nil {
- t.Fatalf("failed to reopen store: %v", err)
- }
- defer func() { _ = store.Close() }()
- got, err := store.LoadControlPlaneURL()
- if err != nil {
- t.Fatalf("LoadControlPlaneURL: %v", err)
- }
- if got != normalizeControlPlaneURLForTest(routerAddr) {
- t.Errorf("expected control plane URL to be backfilled to %q, got %q", normalizeControlPlaneURLForTest(routerAddr), got)
- }
-}
-
-// normalizeControlPlaneURLForTest mirrors cmd/sam-node's normalizeControlPlaneURL,
-// duplicated here since that's an unexported function in package main.
-func normalizeControlPlaneURLForTest(url string) string {
- if !strings.HasPrefix(url, "http://") && !strings.HasPrefix(url, "https://") {
- url = "https://" + url
- }
- return strings.TrimSuffix(url, "/")
-}