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
Fix storage listed on nodes excluded by its node restriction (#1645)
Richard Courtman97c5449bef1f
diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.mdindex 7f7ddd0d66..8702933e71 100644--- a/docs/release-control/v6/internal/subsystems/monitoring.md+++ b/docs/release-control/v6/internal/subsystems/monitoring.md@@ -2517,3 +2517,38 @@ that has compounded to fifteen minutes.repeat polls stay on the DNS cache, that the link-local blocklist still rejectshostname endpoints resolving into it, and that the SSH backoffs suppress,decay, and reset as described.++### Datacenter storage node restriction bounds the per-node storage surface++Proxmox's per-node storage endpoint (`GET /nodes/{node}/storage`) is not a view+of what that node can use. It returns every storage in the datacenter+configuration, and reports the ones the node is excluded from with+`enabled:0`/`active:0` rather than omitting them. The canonical storage poller+must therefore treat the datacenter `nodes` restriction, not the per-node+enabled/active flags, as the authority on which node a storage belongs to.++In `internal/monitoring/monitor_polling_storage.go`, `pollStorageWithNodes`+already reads the datacenter configuration once through `GetAllStorage` before+fanning out per node. When a storage name is present in that configuration and+its `nodes` field parses to a non-empty set (`parseClusterStorageNodes`) that+does not contain the node currently being polled, the per-node row is dropped+and never becomes a `models.Storage`. Node-name matching is case-insensitive+and whitespace-tolerant, matching how node identity is compared elsewhere in+the poller.++The restriction is the only permitted reason to drop a row here. A storage with+no `nodes` restriction stays visible on every node it is reported from,+including when it is disabled everywhere — a datacenter-wide disabled storage+must still surface as a `disabled` entry rather than disappearing, because+disappearing would hide a real misconfiguration. Because the shared-storage+aggregation derives `Nodes`, `NodeIDs`, and `NodeCount` from the surviving+per-node rows, honouring the restriction at ingest is also what keeps a+restricted shared storage from claiming cluster members that cannot mount it.+The cluster-only synthesis path further down already derives its node list from+the same restriction, so both paths now agree.++`internal/monitoring/monitor_additional_test.go` is the registered proof+(`Issue1645*`) that a restricted storage is dropped on excluded nodes, that an+unrestricted storage still appears on every node, that a globally disabled+unrestricted storage still surfaces as disabled, and that the shared-storage+node list excludes non-member nodes.diff --git a/internal/monitoring/monitor_additional_test.go b/internal/monitoring/monitor_additional_test.goindex dded09cf97..0bb583f593 100644--- a/internal/monitoring/monitor_additional_test.go+++ b/internal/monitoring/monitor_additional_test.go@@ -9,6 +9,7 @@ import ("github.com/rcourtman/pulse-go-rewrite/internal/config""github.com/rcourtman/pulse-go-rewrite/internal/models"unifiedresources "github.com/rcourtman/pulse-go-rewrite/internal/unifiedresources"+ "github.com/rcourtman/pulse-go-rewrite/pkg/proxmox")type fakeDockerChecker struct{}@@ -404,3 +405,194 @@ func TestRecordGuestMetricsSkipsGracePeriodGuestsButKeepsObservedOnes(t *testing}}}++// Issue1645: PVE's per-node endpoint GET /nodes/{node}/storage returns every+// storage in the datacenter config, including ones the node is not allowed to+// use. Those come back enabled:0/active:0 and used to be ingested as "disabled"+// rows, which the UI rendered as an offline storage on every node.+func TestIssue1645StorageRestrictedToOtherNodesIsNotListed(t *testing.T) {+ monitor := &Monitor{+ state: models.NewState(),+ config: &config.Config{+ PVEInstances: []config.PVEInstance{+ {+ Name: "inst1",+ IsCluster: true,+ ClusterName: "cluster-a",+ },+ },+ },+ }++ client := &fakeStorageClient{+ allStorage: []proxmox.Storage{+ // Restricted to node1 only.+ {Storage: "node1-only", Type: "dir", Content: "images", Nodes: "node1", Enabled: 1, Active: 1, Total: 100, Used: 10, Available: 90},+ // No node restriction at all.+ {Storage: "everywhere", Type: "dir", Content: "images", Enabled: 1, Active: 1, Total: 200, Used: 20, Available: 180},+ // No node restriction, but disabled across the whole datacenter.+ {Storage: "off-everywhere", Type: "dir", Content: "images", Enabled: 0, Active: 0, Total: 300, Used: 30, Available: 270},+ },+ storageByNode: map[string][]proxmox.Storage{+ "node1": {+ {Storage: "node1-only", Type: "dir", Content: "images", Enabled: 1, Active: 1, Total: 100, Used: 10, Available: 90},+ {Storage: "everywhere", Type: "dir", Content: "images", Enabled: 1, Active: 1, Total: 200, Used: 20, Available: 180},+ {Storage: "off-everywhere", Type: "dir", Content: "images", Enabled: 0, Active: 0, Total: 300, Used: 30, Available: 270},+ },+ "node2": {+ // PVE still lists the restricted storage here, flagged unusable.+ {Storage: "node1-only", Type: "dir", Content: "images", Enabled: 0, Active: 0, Total: 100, Used: 10, Available: 90},+ {Storage: "everywhere", Type: "dir", Content: "images", Enabled: 1, Active: 1, Total: 200, Used: 25, Available: 175},+ {Storage: "off-everywhere", Type: "dir", Content: "images", Enabled: 0, Active: 0, Total: 300, Used: 30, Available: 270},+ },+ },+ }++ nodes := []proxmox.Node{+ {Node: "node1", Status: "online"},+ {Node: "node2", Status: "online"},+ }++ monitor.pollStorageWithNodes(context.Background(), "inst1", client, nodes)++ byName := map[string][]models.Storage{}+ for _, storage := range monitor.state.GetSnapshot().Storage {+ byName[storage.Name] = append(byName[storage.Name], storage)+ }++ // (a) The restricted storage must only exist on the node it is assigned to.+ restricted := byName["node1-only"]+ if len(restricted) != 1 {+ t.Fatalf("expected node-restricted storage on exactly one node, got %+v", restricted)+ }+ if restricted[0].Node != "node1" {+ t.Fatalf("expected node-restricted storage on node1, got %+v", restricted[0])+ }++ // (b) An unrestricted storage still shows up on every node.+ unrestricted := byName["everywhere"]+ if len(unrestricted) != 2 {+ t.Fatalf("expected unrestricted storage on both nodes, got %+v", unrestricted)+ }+ seenNodes := map[string]bool{}+ for _, storage := range unrestricted {+ seenNodes[storage.Node] = true+ }+ if !seenNodes["node1"] || !seenNodes["node2"] {+ t.Fatalf("expected unrestricted storage on node1 and node2, got %+v", unrestricted)+ }++ // (c) A globally disabled storage with no restriction is still reported, as disabled.+ disabled := byName["off-everywhere"]+ if len(disabled) != 2 {+ t.Fatalf("expected globally disabled storage to remain visible on both nodes, got %+v", disabled)+ }+ for _, storage := range disabled {+ if storage.Status != "disabled" || storage.Enabled {+ t.Fatalf("expected globally disabled storage to report disabled, got %+v", storage)+ }+ }+}++// Issue1645: the shared-storage aggregation derives its node list from the+// per-node rows, so honouring the datacenter restriction must also stop+// non-member nodes from being credited with the storage.+func TestIssue1645SharedStorageNodeListExcludesRestrictedNodes(t *testing.T) {+ monitor := &Monitor{+ state: models.NewState(),+ config: &config.Config{+ PVEInstances: []config.PVEInstance{+ {+ Name: "inst1",+ IsCluster: true,+ ClusterName: "cluster-a",+ },+ },+ },+ }++ sharedRow := proxmox.Storage{+ Storage: "shared-nfs",+ Type: "nfs",+ Content: "images,backup",+ Shared: 1,+ Enabled: 1,+ Active: 1,+ Total: 1000,+ Used: 400,+ Available: 600,+ }+ unusableRow := sharedRow+ unusableRow.Enabled = 0+ unusableRow.Active = 0++ clusterRow := sharedRow+ clusterRow.Nodes = "node1,node2"++ client := &fakeStorageClient{+ allStorage: []proxmox.Storage{clusterRow},+ storageByNode: map[string][]proxmox.Storage{+ "node1": {sharedRow},+ "node2": {sharedRow},+ // node3 is not in the restriction but PVE lists the storage anyway.+ "node3": {unusableRow},+ },+ }++ nodes := []proxmox.Node{+ {Node: "node1", Status: "online"},+ {Node: "node2", Status: "online"},+ {Node: "node3", Status: "online"},+ }++ monitor.pollStorageWithNodes(context.Background(), "inst1", client, nodes)++ var shared *models.Storage+ for _, storage := range monitor.state.GetSnapshot().Storage {+ if storage.Name == "shared-nfs" {+ storageCopy := storage+ shared = &storageCopy+ break+ }+ }+ if shared == nil {+ t.Fatalf("expected shared storage in state, got %+v", monitor.state.GetSnapshot().Storage)+ }+ if shared.NodeCount != 2 {+ t.Fatalf("expected shared storage node count of 2, got %+v", *shared)+ }+ for _, nodeName := range shared.Nodes {+ if nodeName == "node3" {+ t.Fatalf("node3 is excluded by the storage node restriction but was listed: %+v", *shared)+ }+ }+ for _, nodeID := range shared.NodeIDs {+ if nodeID == "cluster-a-node3" {+ t.Fatalf("node3 is excluded by the storage node restriction but was listed: %+v", *shared)+ }+ }+}++func TestIssue1645ClusterStorageRestrictedToOtherNodes(t *testing.T) {+ cases := []struct {+ name string+ restriction string+ node string+ want bool+ }{+ {name: "no restriction", restriction: "", node: "node1", want: false},+ {name: "member", restriction: "node1,node2", node: "node2", want: false},+ {name: "non member", restriction: "node1,node2", node: "node3", want: true},+ {name: "case insensitive member", restriction: "Node1", node: "node1", want: false},+ {name: "spaced restriction", restriction: " node1 ; node2 ", node: "node2", want: false},+ {name: "empty node name", restriction: "node1", node: "", want: false},+ }++ for _, tc := range cases {+ t.Run(tc.name, func(t *testing.T) {+ if got := clusterStorageRestrictedToOtherNodes(tc.restriction, tc.node); got != tc.want {+ t.Fatalf("clusterStorageRestrictedToOtherNodes(%q, %q) = %v, want %v", tc.restriction, tc.node, got, tc.want)+ }+ })+ }+}diff --git a/internal/monitoring/monitor_polling_storage.go b/internal/monitoring/monitor_polling_storage.goindex fc30b0d30e..c35feea2f4 100644--- a/internal/monitoring/monitor_polling_storage.go+++ b/internal/monitoring/monitor_polling_storage.go@@ -336,6 +336,26 @@ func (m *Monitor) pollStorageWithNodes(ctx context.Context, instanceName string,continue}+ // Get cluster config for this storage+ clusterConfig, hasClusterConfig := clusterStorageMap[storage.Storage]++ // PVE's per-node endpoint returns every storage in the datacenter+ // config, including ones this node is not allowed to use (those come+ // back enabled:0/active:0). Honour the datacenter "nodes" restriction+ // so a storage limited to other nodes does not show up here as an+ // offline entry (#1645). A storage with no restriction is still+ // ingested even when disabled, so globally disabled storages keep+ // showing up as disabled.+ if hasClusterConfig && clusterStorageRestrictedToOtherNodes(clusterConfig.Nodes, n.Node) {+ log.Debug().+ Str("instance", instanceName).+ Str("node", n.Node).+ Str("storage", storage.Storage).+ Str("restrictedTo", clusterConfig.Nodes).+ Msg("Skipping storage not assigned to this node by the datacenter node restriction")+ continue+ }+// Create storage IDvar storageID stringif instanceName == n.Node {@@ -344,9 +364,6 @@ func (m *Monitor) pollStorageWithNodes(ctx context.Context, instanceName string,storageID = fmt.Sprintf("%s-%s-%s", instanceName, n.Node, storage.Storage)}- // Get cluster config for this storage- clusterConfig, hasClusterConfig := clusterStorageMap[storage.Storage]-// Determine if shared - check multiple sources:// 1. Per-node API returns shared flag directly// 2. Cluster config API also has shared flag (if available)@@ -822,3 +839,24 @@ func parseClusterStorageNodes(raw string) []string {}return result}++// clusterStorageRestrictedToOtherNodes reports whether a datacenter storage+// definition carries a node restriction that excludes nodeName. An empty+// restriction means the storage is available on every node, so it returns+// false in that case.+func clusterStorageRestrictedToOtherNodes(restriction string, nodeName string) bool {+ allowed := parseClusterStorageNodes(restriction)+ if len(allowed) == 0 {+ return false+ }+ nodeName = strings.TrimSpace(nodeName)+ if nodeName == "" {+ return false+ }+ for _, candidate := range allowed {+ if strings.EqualFold(strings.TrimSpace(candidate), nodeName) {+ return false+ }+ }+ return true+}