Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Follow guest metadata across cluster node migrations
rcourtmanaad62ff3230b
diff --git a/internal/config/guest_metadata.go b/internal/config/guest_metadata.goindex c9390e1219..d8555d82fb 100644--- a/internal/config/guest_metadata.go+++ b/internal/config/guest_metadata.go@@ -5,6 +5,7 @@ import ("fmt""os""path/filepath"+ "strings""sync""github.com/rs/zerolog/log"@@ -195,9 +196,45 @@ func (s *GuestMetadataStore) GetWithLegacyMigration(guestID, instance, node stri}}+ // A guest that migrated to another cluster node keeps its VMID but shows+ // up under a new node-scoped ID, orphaning its metadata (#1669). VMIDs+ // are unique within a Proxmox cluster, so an entry for the same instance+ // and VMID on a different node belongs to this guest.+ if movedID := s.findGuestIDOnOtherNode(guestID, instance, vmID); movedID != "" {+ if result := migrate(movedID); result != nil {+ return result+ }+ }+return nil}+// findGuestIDOnOtherNode returns a stored metadata ID for the same instance+// and VMID under a different node, or "" when none exists.+func (s *GuestMetadataStore) findGuestIDOnOtherNode(guestID, instance string, vmID int) string {+ prefix := instance + ":"+ suffix := fmt.Sprintf(":%d", vmID)++ s.mu.RLock()+ defer s.mu.RUnlock()+ for id := range s.metadata {+ if id == guestID || len(id) <= len(prefix)+len(suffix) {+ continue+ }+ if !strings.HasPrefix(id, prefix) || !strings.HasSuffix(id, suffix) {+ continue+ }+ // The middle segment must be exactly one node name: an ID with more+ // separators is a different key shape, not a node-scoped guest ID.+ middle := id[len(prefix) : len(id)-len(suffix)]+ if middle == "" || strings.Contains(middle, ":") {+ continue+ }+ return id+ }+ return ""+}+// GetAll retrieves all guest metadatafunc (s *GuestMetadataStore) GetAll() map[string]*GuestMetadata {s.mu.RLock()diff --git a/internal/config/guest_metadata_test.go b/internal/config/guest_metadata_test.goindex 9133f4270a..3d68ef32be 100644--- a/internal/config/guest_metadata_test.go+++ b/internal/config/guest_metadata_test.go@@ -710,3 +710,49 @@ func TestGuestMetadataStoreUpdateAllRollsBackFailedPersistence(t *testing.T) {t.Fatalf("failed update remained in memory: %#v", meta)}}++// Issue #1669: a guest migrating to another cluster node keeps its VMID but+// gets a new node-scoped ID, which orphaned its metadata (custom URL, tags,+// notes). The store must follow the guest across nodes.+func TestGuestMetadataStore_GetWithLegacyMigration_NodeMigration(t *testing.T) {+ tmpDir := t.TempDir()+ store := NewGuestMetadataStore(tmpDir, nil)++ store.metadata["pve1:node1:100"] = &GuestMetadata{+ ID: "pve1:node1:100",+ CustomURL: "http://haos.example",+ Tags: []string{"prod"},+ }++ // The guest moved from node1 to node2.+ result := store.GetWithLegacyMigration("pve1:node2:100", "pve1", "node2", 100)+ if result == nil {+ t.Fatal("expected metadata to follow the guest to its new node")+ }+ if result.CustomURL != "http://haos.example" {+ t.Errorf("CustomURL = %q, want %q", result.CustomURL, "http://haos.example")+ }+ if result.ID != "pve1:node2:100" {+ t.Errorf("migrated ID = %q, want %q", result.ID, "pve1:node2:100")+ }+ if store.Get("pve1:node1:100") != nil {+ t.Error("expected old node-scoped entry to be removed after migration")+ }+}++// A different VMID or a different instance must never be treated as the same+// guest.+func TestGuestMetadataStore_GetWithLegacyMigration_NodeMigrationDoesNotCrossGuests(t *testing.T) {+ tmpDir := t.TempDir()+ store := NewGuestMetadataStore(tmpDir, nil)++ store.metadata["pve1:node1:101"] = &GuestMetadata{ID: "pve1:node1:101", CustomURL: "http://other-guest"}+ store.metadata["pve2:node1:100"] = &GuestMetadata{ID: "pve2:node1:100", CustomURL: "http://other-instance"}++ if result := store.GetWithLegacyMigration("pve1:node2:100", "pve1", "node2", 100); result != nil {+ t.Fatalf("expected no migration across guests, got %+v", result)+ }+ if store.Get("pve1:node1:101") == nil || store.Get("pve2:node1:100") == nil {+ t.Error("unrelated entries must remain untouched")+ }+}