Skip to content

armgit / Pulse

Public Imported from GitHub
0

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.

Keep guest primary addresses associated with their interfaces

pulse-triage[bot]5c3d18e248e6
diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.md
index 6d5e8ad6d3..dc80ccbdd8 100644
--- a/docs/release-control/v6/internal/subsystems/monitoring.md
+++ b/docs/release-control/v6/internal/subsystems/monitoring.md
@@ -3188,6 +3188,26 @@ truthfulness, not native thaw, containing-release or workload acceptance.
## Current State
+### Interface-associated guest address selection
+
+LXC status, configuration and existing runtime-interface fallback collection,
+and QEMU guest-agent network metadata, select display addresses by their named
+interface rather than globally sorting flattened IP text. Name-ordered guest
+interfaces without common local-container/overlay names lead; remaining scalar
+addresses keep unknown association, and secondary interfaces remain useful as
+fallbacks. All collected addresses and interface/traffic metadata are retained.
+Within an interface valid IPs sort numerically, IPv4 before IPv6; unparsed
+metadata retains a deterministic fallback. This is a display hint, not evidence
+of physical NICs, default routes or reachability. No new guest query, permission,
+poll cadence, cache/backoff or machine-identity behaviour is introduced.
+
+`TestIssue2757ContainerAddressSelection` covers status, stopped/config-only,
+DHCP fallback, IPv6, duplicates, numeric sorting, unknown associations and
+secondary-only/management-bridge paths through canonical listing and broadcast.
+`TestIssue2757VMAddressSelectionAndCache` exercises the actual metadata fetch
+and warm cache with reversed input order, preserving interfaces and ownership.
+These source fixtures are not native #2757 recovery or released availability.
+
### TrueNAS physical-disk History — issue #2519
The actual all-metric drawer request also reaches this reader when stored I/O
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index 0c37acd80e..536db50dd8 100644
--- a/docs/release-control/v6/internal/subsystems/unified-resources.md
+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md
@@ -3084,6 +3084,21 @@ application resource-provider or WebSocket lifecycle.
## Current State
+### Interface-associated display addresses
+
+VM and LXC projections retain the collector's interface-associated IP order in
+canonical identity and broadcast. Agent-host display address selection also
+recognises Podman interface names as secondary, retaining every address and the
+explicit `--report-ip` preference. The shared `pkg/netutil` name hint does not
+drop management bridges, bonds, VLANs or tunnels, prove a default route, or
+change the agent's separate MAC-based machine-ID fallback. No identity key or
+wire shape changes. `TestIssue2757AgentDisplayPrefersNonContainerInterfaces`
+and `TestIssue2757AgentDisplayKeepsSecondaryOnlyAddresses` bind Podman,
+management-interface, supplied identity and explicit-override controls to the
+production host adapter; monitoring's #2757 fixtures bind guest list/broadcast
+order and name/address/traffic association. Native readings and publication
+remain separate evidence.
+
Discovery-led availability proposals present their evidence and canonical
attachment boundary as short, complete sentences in both the inline card and
machine-wide review. The colocated component test pins that operator-facing
diff --git a/internal/monitoring/guest_metadata.go b/internal/monitoring/guest_metadata.go
index e5d4364fe5..f924a088d3 100644
--- a/internal/monitoring/guest_metadata.go
+++ b/internal/monitoring/guest_metadata.go
@@ -552,7 +552,7 @@ func processGuestNetworkInterfaces(raw []proxmox.VMNetworkInterface) ([]string,
}
if len(addresses) > 1 {
- sort.Strings(addresses)
+ sortGuestAddresses(addresses)
}
rxBytes := parseInterfaceStat(iface.Statistics, "rx-bytes")
@@ -582,17 +582,13 @@ func processGuestNetworkInterfaces(raw []proxmox.VMNetworkInterface) ([]string,
})
}
- if len(ipAddresses) > 1 {
- sort.Strings(ipAddresses)
- }
-
if len(guestIfaces) > 1 {
sort.SliceStable(guestIfaces, func(i, j int) bool {
return guestIfaces[i].Name < guestIfaces[j].Name
})
}
- return ipAddresses, guestIfaces
+ return guestIPAddressesByInterface(ipAddresses, guestIfaces), guestIfaces
}
func parseInterfaceStat(stats interface{}, key string) int64 {
diff --git a/internal/monitoring/guest_metadata_test.go b/internal/monitoring/guest_metadata_test.go
index a1bbf464b3..9159f08a09 100644
--- a/internal/monitoring/guest_metadata_test.go
+++ b/internal/monitoring/guest_metadata_test.go
@@ -523,7 +523,7 @@ func TestProcessGuestNetworkInterfaces(t *testing.T) {
},
},
},
- wantIPs: []string{"10.0.0.5", "192.168.1.10"},
+ wantIPs: []string{"192.168.1.10", "10.0.0.5"}, // keep interface priority, not global IP order
wantIfaces: []models.GuestNetworkInterface{
{Name: "eth0", MAC: "00:11:22:33:44:55", Addresses: []string{"192.168.1.10"}},
{Name: "eth1", MAC: "AA:BB:CC:DD:EE:FF", Addresses: []string{"10.0.0.5"}},
diff --git a/internal/monitoring/guest_network_addresses.go b/internal/monitoring/guest_network_addresses.go
new file mode 100644
index 0000000000..ed056b3ca9
--- /dev/null
+++ b/internal/monitoring/guest_network_addresses.go
@@ -0,0 +1,79 @@
+package monitoring
+
+import (
+ "net/netip"
+ "sort"
+
+ "github.com/rcourtman/pulse-go-rewrite/internal/models"
+ "github.com/rcourtman/pulse-go-rewrite/pkg/netutil"
+)
+
+// guestIPAddressesByInterface keeps interface/address association when choosing
+// the first displayed guest address. The existing name-ordered interface view
+// remains unchanged; local-container/overlay addresses follow other interfaces.
+// Scalar addresses with no known interface remain useful, ahead of secondary
+// addresses. No address is dropped and no route or reachability is inferred.
+func guestIPAddressesByInterface(addresses []string, interfaces []models.GuestNetworkInterface) []string {
+ if len(addresses) < 2 {
+ return addresses
+ }
+ remaining := make(map[string]bool, len(addresses))
+ for _, address := range addresses {
+ remaining[address] = true
+ }
+ associated := make(map[string]bool)
+ for _, iface := range interfaces {
+ for _, address := range iface.Addresses {
+ associated[address] = true
+ }
+ }
+ ordered := make([]string, 0, len(addresses))
+ appendAddress := func(address string) {
+ if remaining[address] {
+ ordered = append(ordered, address)
+ delete(remaining, address)
+ }
+ }
+ // Callers have sorted interface names for stable presentation. Sort only
+ // within each interface, never the flattened list (#2757).
+ for pass := 0; pass < 2; pass++ {
+ for _, iface := range interfaces {
+ if (pass == 0) == netutil.IsSecondaryInterfaceName(iface.Name) {
+ continue
+ }
+ local := cloneStringSlice(iface.Addresses)
+ sortGuestAddresses(local)
+ for _, address := range local {
+ appendAddress(address)
+ }
+ }
+ if pass == 0 {
+ unassociated := cloneStringSlice(addresses)
+ sortGuestAddresses(unassociated)
+ for _, address := range unassociated {
+ if !associated[address] {
+ appendAddress(address)
+ }
+ }
+ }
+ }
+ return ordered
+}
+
+// sortGuestAddresses orders valid IPs numerically (IPv4 before IPv6). Existing
+// unparsed metadata is retained with a deterministic text fallback, not silently
+// turned into a valid or reachable address.
+func sortGuestAddresses(addresses []string) {
+ sort.SliceStable(addresses, func(i, j int) bool {
+ left, leftErr := netip.ParseAddr(addresses[i])
+ right, rightErr := netip.ParseAddr(addresses[j])
+ if leftErr == nil && rightErr == nil {
+ if comparison := left.Compare(right); comparison != 0 {
+ return comparison < 0
+ }
+ } else if (leftErr == nil) != (rightErr == nil) {
+ return leftErr == nil
+ }
+ return addresses[i] < addresses[j]
+ })
+}
diff --git a/internal/monitoring/guest_network_addresses_test.go b/internal/monitoring/guest_network_addresses_test.go
new file mode 100644
index 0000000000..8a4543c4c2
--- /dev/null
+++ b/internal/monitoring/guest_network_addresses_test.go
@@ -0,0 +1,27 @@
+package monitoring
+
+import (
+ "reflect"
+ "testing"
+
+ "github.com/rcourtman/pulse-go-rewrite/internal/models"
+)
+
+func TestGuestAddressOrderingDoesNotAddFilteredOrMutateAddresses(t *testing.T) {
+ t.Parallel()
+ addresses := []string{"10.88.0.1", "192.0.2.10", "192.0.2.2", "unparsed-status"}
+ interfaces := []models.GuestNetworkInterface{
+ {Name: "eth0", Addresses: []string{"192.0.2.10", "fe80::1", "192.0.2.2"}},
+ {Name: "podman0", Addresses: []string{"10.88.0.1"}},
+ }
+ beforeAddresses := cloneStringSlice(addresses)
+ beforeInterfaces := cloneGuestNetworkInterfaces(interfaces)
+ got := guestIPAddressesByInterface(addresses, interfaces)
+ want := []string{"192.0.2.2", "192.0.2.10", "unparsed-status", "10.88.0.1"}
+ if !reflect.DeepEqual(got, want) {
+ t.Fatalf("addresses = %v, want %v", got, want)
+ }
+ if !reflect.DeepEqual(addresses, beforeAddresses) || !reflect.DeepEqual(interfaces, beforeInterfaces) {
+ t.Fatal("address ordering mutated its input")
+ }
+}
diff --git a/internal/monitoring/monitor_pve.go b/internal/monitoring/monitor_pve.go
index 08f19fa68f..f563b5276d 100644
--- a/internal/monitoring/monitor_pve.go
+++ b/internal/monitoring/monitor_pve.go
@@ -341,12 +341,8 @@ func (m *Monitor) enrichContainerMetadata(ctx context.Context, client PVEClientI
})
}
- if len(addressOrder) > 1 {
- sort.Strings(addressOrder)
- }
-
if len(addressOrder) > 0 {
- container.IPAddresses = addressOrder
+ container.IPAddresses = guestIPAddressesByInterface(addressOrder, networkIfaces)
}
if len(networkIfaces) > 0 {
diff --git a/internal/monitoring/monitor_pve_guest_lxc_test.go b/internal/monitoring/monitor_pve_guest_lxc_test.go
index 23988711d7..d05f8ca166 100644
--- a/internal/monitoring/monitor_pve_guest_lxc_test.go
+++ b/internal/monitoring/monitor_pve_guest_lxc_test.go
@@ -8,12 +8,15 @@ import (
"fmt"
"net/http"
"net/http/httptest"
+ "reflect"
+ "slices"
"strings"
"sync/atomic"
"testing"
"time"
"github.com/rcourtman/pulse-go-rewrite/internal/models"
+ "github.com/rcourtman/pulse-go-rewrite/internal/unifiedresources"
agentshost "github.com/rcourtman/pulse-go-rewrite/pkg/agents/host"
"github.com/rcourtman/pulse-go-rewrite/pkg/proxmox"
"github.com/rs/zerolog"
@@ -27,6 +30,284 @@ type stubPVEClientLXCStatus struct {
statusCalls int
}
+type issue2757ContainerClient struct {
+ stubPVEClient
+ status *proxmox.Container
+ config map[string]interface{}
+ interfaces []proxmox.ContainerInterface
+ statusCalls, configCalls int
+ interfaceCalls int
+}
+
+func (c *issue2757ContainerClient) GetContainerStatus(context.Context, string, int) (*proxmox.Container, error) {
+ c.statusCalls++
+ return c.status, nil
+}
+
+func (c *issue2757ContainerClient) GetContainerConfig(context.Context, string, int) (map[string]interface{}, error) {
+ c.configCalls++
+ return c.config, nil
+}
+
+func (c *issue2757ContainerClient) GetContainerInterfaces(context.Context, string, int) ([]proxmox.ContainerInterface, error) {
+ c.interfaceCalls++
+ return c.interfaces, nil
+}
+
+// These are source fixtures, not the reporter's inventory or native recovery.
+// All addresses are synthetic; choosing one says nothing about its default route.
+func TestIssue2757ContainerAddressSelection(t *testing.T) {
+ t.Parallel()
+ for _, tc := range []struct {
+ name string
+ status *proxmox.Container
+ config map[string]interface{}
+ interfaces []proxmox.ContainerInterface
+ stopped bool
+ want []string
+ wantIfaceCalls int
+ }{
+ {
+ name: "status interface association beats flattened text order",
+ status: &proxmox.Container{IP: "10.88.0.1 192.0.2.80", Network: map[string]proxmox.ContainerNetworkConfig{
+ "net1": {Name: "podman0", IP: "10.88.0.1/16"},
+ "net0": {Name: "eth0", IP: "192.0.2.80/24"},
+ }},
+ want: []string{"192.0.2.80", "10.88.0.1"},
+ },
+ {
+ name: "stopped config-only guest needs no runtime query",
+ config: map[string]interface{}{
+ "net1": "name=podman0,ip=10.88.0.1/16",
+ "net0": "name=eth0,ip=192.0.2.80/24",
+ },
+ stopped: true,
+ want: []string{"192.0.2.80", "10.88.0.1"},
+ },
+ {
+ name: "DHCP interfaces fallback keeps named addresses and filters loopback",
+ config: map[string]interface{}{"net0": "name=eth0,ip=dhcp,ip6=auto"},
+ interfaces: []proxmox.ContainerInterface{
+ {Name: "podman0", Inet: "10.88.0.1/16"},
+ {Name: "veth0", IPAddresses: []proxmox.VMIPAddress{{Address: "10.89.0.1/16"}}},
+ {Name: "eth0", IPAddresses: []proxmox.VMIPAddress{{Address: "192.0.2.80/24"}, {Address: "2001:db8::80/64"}, {Address: "fe80::1/64"}}},
+ {Name: "lo", Inet: "127.0.0.1/8 ::1/128"},
+ },
+ want: []string{"192.0.2.80", "2001:db8::80", "10.88.0.1", "10.89.0.1"},
+ wantIfaceCalls: 1,
+ },
+ {
+ name: "IPv6 on preferred interface precedes secondary IPv4",
+ status: &proxmox.Container{Network: map[string]proxmox.ContainerNetworkConfig{
+ "podman0": {IP: "10.88.0.1"}, "eth0": {IP6: "2001:db8::80"},
+ }},
+ want: []string{"2001:db8::80", "10.88.0.1"},
+ },
+ {
+ name: "secondary-only guest keeps useful addresses",
+ status: &proxmox.Container{Network: map[string]proxmox.ContainerNetworkConfig{
+ "podman0": {IP: "10.88.0.1"}, "docker0": {IP: "192.0.2.80"},
+ }},
+ want: []string{"192.0.2.80", "10.88.0.1"},
+ },
+ {
+ name: "management bridge is not discarded or treated as a container bridge",
+ status: &proxmox.Container{Network: map[string]proxmox.ContainerNetworkConfig{
+ "podman0": {IP: "10.88.0.1"}, "br0": {IP: "192.0.2.80"},
+ }},
+ want: []string{"192.0.2.80", "10.88.0.1"},
+ },
+ {
+ name: "unassociated status IP stays useful without inventing its interface",
+ status: &proxmox.Container{IP: "192.0.2.80", Network: map[string]proxmox.ContainerNetworkConfig{
+ "podman0": {IP: "10.88.0.1"},
+ }},
+ want: []string{"192.0.2.80", "10.88.0.1"},
+ },
+ {
+ name: "empty preferred interface does not hide the only address",
+ config: map[string]interface{}{"net0": "name=eth0,ip=dhcp"},
+ status: &proxmox.Container{Network: map[string]proxmox.ContainerNetworkConfig{
+ "podman0": {IP: "10.88.0.1"},
+ }},
+ want: []string{"10.88.0.1"},
+ },
+ {
+ name: "deduplicate globally but sort numerically only within each interface",
+ status: &proxmox.Container{Network: map[string]proxmox.ContainerNetworkConfig{
+ "eth0": {IP: "192.0.2.10 192.0.2.2", IP6: "2001:db8::10 2001:db8::2"},
+ "eth1": {IP: "10.0.0.1"}, "podman0": {IP: "192.0.2.2 10.88.0.1"},
+ }},
+ want: []string{"192.0.2.2", "192.0.2.10", "2001:db8::2", "2001:db8::10", "10.0.0.1", "10.88.0.1"},
+ },
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ t.Parallel()
+ client := &issue2757ContainerClient{status: tc.status, config: tc.config, interfaces: tc.interfaces}
+ before, err := json.Marshal([]interface{}{client.status, client.config, client.interfaces})
+ if err != nil {
+ t.Fatal(err)
+ }
+ container := models.Container{ID: "site-a-node-a-2757", VMID: 2757, Name: "guest", Instance: "site-a", Node: "node-a", Status: "running", Type: "lxc", LastSeen: time.Now()}
+ if tc.stopped {
+ container.Status = "stopped"
+ }
+ monitor := &Monitor{}
+ monitor.enrichContainerMetadata(context.Background(), client, "site-a", "node-a", &container)
+ if !reflect.DeepEqual(container.IPAddresses, tc.want) {
+ t.Fatalf("guest IP selection = %v, want %v", container.IPAddresses, tc.want)
+ }
+ wantStatusCalls := 1
+ if tc.stopped {
+ wantStatusCalls = 0
+ }
+ if client.configCalls != 1 || client.statusCalls != wantStatusCalls || client.interfaceCalls != tc.wantIfaceCalls {
+ t.Fatalf("metadata query counts = status:%d config:%d interfaces:%d", client.statusCalls, client.configCalls, client.interfaceCalls)
+ }
+ after, err := json.Marshal([]interface{}{client.status, client.config, client.interfaces})
+ if err != nil || !bytes.Equal(before, after) {
+ t.Fatal("client changed while enriching")
+ }
+ monitor.state = models.NewState()
+ monitor.state.UpdateContainers([]models.Container{container})
+ assertIssue2757GuestWire(t, monitor, container.ID, tc.want, container.NetworkInterfaces)
+ })
+ }
+}
+
+type issue2757VMClient struct {
+ emptyGuestMetadataClient
+ interfaces []proxmox.VMNetworkInterface
+ calls int
+}
+
+func (c *issue2757VMClient) GetVMNetworkInterfaces(context.Context, string, int) ([]proxmox.VMNetworkInterface, error) {
+ c.calls++
+ return c.interfaces, nil
+}
+
+func TestIssue2757VMAddressSelectionAndCache(t *testing.T) {
+ t.Parallel()
+ for _, tc := range []struct {
+ name string
+ interfaces []proxmox.VMNetworkInterface
+ want []string
+ }{
+ {
+ name: "prefer named interface even with lower secondary addresses",
+ interfaces: []proxmox.VMNetworkInterface{
+ {Name: "podman0", IPAddresses: []proxmox.VMIPAddress{{Address: "10.88.0.1"}}},
+ {Name: "eth1", IPAddresses: []proxmox.VMIPAddress{{Address: "10.0.0.1"}}},
+ {Name: "eth0", IPAddresses: []proxmox.VMIPAddress{{Address: "192.0.2.10"}, {Address: "192.0.2.2"}, {Address: "2001:db8::10"}, {Address: "2001:db8::2"}, {Address: "192.0.2.2"}, {Address: "fe80::1"}}},
+ },
+ want: []string{"192.0.2.2", "192.0.2.10", "2001:db8::2", "2001:db8::10", "10.0.0.1", "10.88.0.1"},
+ },
+ {
+ name: "secondary-only VM keeps every useful address",
+ interfaces: []proxmox.VMNetworkInterface{
+ {Name: "podman0", IPAddresses: []proxmox.VMIPAddress{{Address: "10.88.0.1"}}},
+ {Name: "docker0", IPAddresses: []proxmox.VMIPAddress{{Address: "192.0.2.80"}}},
+ },
+ want: []string{"192.0.2.80", "10.88.0.1"},
+ },
+ {
+ name: "management bridge remains a usable first interface",
+ interfaces: []proxmox.VMNetworkInterface{
+ {Name: "podman0", IPAddresses: []proxmox.VMIPAddress{{Address: "10.88.0.1"}}},
+ {Name: "br0", HardwareAddr: "02:00:00:00:00:01", IPAddresses: []proxmox.VMIPAddress{{Address: "192.0.2.80"}}, Statistics: map[string]interface{}{"rx-bytes": float64(123), "tx-bytes": float64(456)}},
+ },
+ want: []string{"192.0.2.80", "10.88.0.1"},
+ },
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ t.Parallel()
+ for permutation := 0; permutation < 2; permutation++ {
+ raw := append([]proxmox.VMNetworkInterface(nil), tc.interfaces...)
+ if permutation == 1 {
+ for i, j := 0, len(raw)-1; i < j; i, j = i+1, j-1 {
+ raw[i], raw[j] = raw[j], raw[i]
+ }
+ }
+ before, err := json.Marshal(raw)
+ if err != nil {
+ t.Fatal(err)
+ }
+ client := &issue2757VMClient{interfaces: raw}
+ monitor := &Monitor{}
+ status := &proxmox.VMStatus{Agent: proxmox.VMAgentField{Value: 1}}
+ for poll := 0; poll < 2; poll++ {
+ ips, ifaces, _, _, _, deferred := monitor.fetchGuestAgentMetadata(context.Background(), client, "site-a", "node-a", "guest", 2757, status, false)
+ if deferred || !reflect.DeepEqual(ips, tc.want) {
+ t.Fatalf("guest IP selection = %v, deferred:%v, want %v", ips, deferred, tc.want)
+ }
+ monitor.state = models.NewState()
+ monitor.state.UpdateVMs([]models.VM{{ID: "site-a-node-a-2757", VMID: 2757, Name: "guest", Instance: "site-a", Node: "node-a", Status: "running", LastSeen: time.Now(), IPAddresses: ips, NetworkInterfaces: ifaces}})
+ assertIssue2757GuestWire(t, monitor, "site-a-node-a-2757", tc.want, ifaces)
+ }
+ if client.calls != 1 {
+ t.Fatalf("fresh cache issued %d network queries, want one", client.calls)
+ }
+ after, err := json.Marshal(raw)
+ if err != nil || !bytes.Equal(before, after) {
+ t.Fatal("guest-agent input was mutated")
+ }
+ }
+ })
+ }
+}
+
+func assertIssue2757GuestWire(t *testing.T, monitor *Monitor, nativeID string, want []string, interfaces []models.GuestNetworkInterface) {
+ t.Helper()
+ monitor.state.UpdateNodes([]models.Node{{ID: "site-a-node-a", Name: "node-a", Instance: "site-a", Status: "online", LastSeen: time.Now()}})
+ monitor.resourceStore = unifiedresources.NewMonitorAdapter(nil)
+ frontend := monitor.BuildBroadcastFrontendState()
+ var listed *unifiedresources.Resource
+ for _, resource := range monitor.GetUnifiedResources() {
+ if resource.Proxmox != nil && resource.Proxmox.SourceID == nativeID {
+ copy := resource
+ listed = &copy
+ }
+ }
+ if listed == nil || !reflect.DeepEqual(listed.Identity.IPAddresses, want) {
+ t.Fatalf("canonical listing lost guest addresses: %+v, want %v", listed, want)
+ }
+ var projected *models.ResourceFrontend
+ for _, resource := range frontend.Resources {
+ if resource.ID == listed.ID {
+ copy := resource
+ projected = &copy
+ }
+ }
+ if projected == nil || projected.Identity == nil || !reflect.DeepEqual(projected.Identity.IPs, want) {
+ t.Fatalf("broadcast lost guest address order: %+v, want %v", projected, want)
+ }
+ var facet unifiedresources.ProxmoxData
+ if err := json.Unmarshal(projected.Proxmox, &facet); err != nil {
+ t.Fatal(err)
+ }
+ if facet.SourceID != nativeID || facet.Instance != "site-a" || facet.NodeName != "node-a" || facet.VMID != 2757 || listed.ParentID == nil || projected.ParentID != *listed.ParentID {
+ t.Fatalf("broadcast changed guest ownership: %+v, listing parent:%v broadcast parent:%q", facet, listed.ParentID, projected.ParentID)
+ }
+ parentFound := false
+ for _, resource := range monitor.GetUnifiedResources() {
+ if resource.ID == *listed.ParentID && resource.Proxmox != nil && resource.Proxmox.SourceID == "site-a-node-a" {
+ parentFound = true
+ }
+ }
+ if !parentFound {
+ t.Fatalf("guest parent does not name the supplying node: %s", *listed.ParentID)
+ }
+ if !reflect.DeepEqual(facet.NetworkInterfaces, listed.Proxmox.NetworkInterfaces) || len(facet.NetworkInterfaces) != len(interfaces) {
+ t.Fatalf("listing/broadcast lost named interfaces: %+v", facet.NetworkInterfaces)
+ }
+ for i, iface := range interfaces {
+ wire := facet.NetworkInterfaces[i]
+ if wire.Name != iface.Name || wire.MAC != iface.MAC || !slices.Equal(wire.Addresses, iface.Addresses) || wire.RXBytes != uint64(max(0, iface.RXBytes)) || wire.TXBytes != uint64(max(0, iface.TXBytes)) {
+ t.Fatalf("interface association or traffic changed: %+v, want %+v", wire, iface)
+ }
+ }
+}
+
func (s *stubPVEClientLXCStatus) GetContainerStatus(ctx context.Context, node string, vmid int) (*proxmox.Container, error) {
s.statusCalls++
return s.containerStatus, nil
diff --git a/internal/unifiedresources/adapters.go b/internal/unifiedresources/adapters.go
index e5220c3800..e95d6a5ac1 100644
--- a/internal/unifiedresources/adapters.go
+++ b/internal/unifiedresources/adapters.go
@@ -15,6 +15,7 @@ import (
"github.com/rcourtman/pulse-go-rewrite/internal/storagehealth"
"github.com/rcourtman/pulse-go-rewrite/pkg/agents/filesystem"
"github.com/rcourtman/pulse-go-rewrite/pkg/diskinventory"
+ "github.com/rcourtman/pulse-go-rewrite/pkg/netutil"
)
func resourceFromProxmoxNode(node models.Node, linkedHost *models.Host) (Resource, ResourceIdentity) {
@@ -3933,8 +3934,9 @@ func collectInterfaceIDs(interfaces []models.HostNetworkInterface) ([]string, []
var macs []string
// Agents report interfaces sorted by name, which places docker0/br-* bridges
// ahead of eth*/en*, and consumers treat the first IP as the host's primary
- // address. Collect physical-looking interfaces first so bridge and overlay
- // addresses never lead the list. Mirrors hostagent.isLikelyVirtualInterfaceName.
+ // address. Prefer interfaces without local-container/overlay names, keeping
+ // secondary-only hosts useful. This display hint is not a physical-NIC or
+ // default-route assertion and must not alter the agent's MAC-based identity.
for pass := 0; pass < 2; pass++ {
for _, iface := range interfaces {
if (pass == 0) == isLikelyVirtualInterfaceName(iface.Name) {
@@ -3956,27 +3958,7 @@ func collectInterfaceIDs(interfaces []models.HostNetworkInterface) ([]string, []
}
func isLikelyVirtualInterfaceName(name string) bool {
- name = strings.ToLower(strings.TrimSpace(name))
- switch {
- case name == "" || name == "lo":
- return true
- case strings.HasPrefix(name, "docker"):
- return true
- case strings.HasPrefix(name, "veth"):
- return true
- case strings.HasPrefix(name, "br-"):
- return true
- case strings.HasPrefix(name, "cni"):
- return true
- case strings.HasPrefix(name, "flannel"):
- return true
- case strings.HasPrefix(name, "virbr"):
- return true
- case strings.HasPrefix(name, "zt"):
- return true
- default:
- return false
- }
+ return netutil.IsSecondaryInterfaceName(name)
}
func extractHostname(raw string) string {
diff --git a/internal/unifiedresources/adapters_test.go b/internal/unifiedresources/adapters_test.go
index b6309233d1..ca7701c96a 100644
--- a/internal/unifiedresources/adapters_test.go
+++ b/internal/unifiedresources/adapters_test.go
@@ -1943,6 +1943,48 @@ func TestCollectInterfaceIDsAllVirtualStillCollects(t *testing.T) {
}
}
+func TestIssue2757AgentDisplayPrefersNonContainerInterfaces(t *testing.T) {
+ t.Parallel()
+ for _, name := range []string{"eth0", "wlp2s0", "br0", "vmbr0", "bond0", "vlan100", "eth0.100", "tun0", "wg0"} {
+ t.Run(name, func(t *testing.T) {
+ t.Parallel()
+ host := models.Host{ID: "agent-a", Hostname: "agent", MachineID: "machine-a", NetworkInterfaces: []models.HostNetworkInterface{
+ {Name: "podman0", MAC: "02:00:00:00:00:01", Addresses: []string{"10.88.0.1/16"}},
+ {Name: name, MAC: "02:00:00:00:00:02", Addresses: []string{"192.0.2.80/24"}},
+ }}
+ before, err := json.Marshal(host)
+ if err != nil {
+ t.Fatal(err)
+ }
+ resource, identity := resourceFromHost(host)
+ if !reflect.DeepEqual(identity.IPAddresses, []string{"192.0.2.80", "10.88.0.1"}) || identity.MachineID != "machine-a" || resource.Agent.AgentID != "agent-a" {
+ t.Fatalf("agent display IPs or supplied identity changed: %+v", identity)
+ }
+ host.ReportIP = "10.88.0.1"
+ _, override := resourceFromHost(host)
+ if !reflect.DeepEqual(override.IPAddresses, []string{"10.88.0.1", "192.0.2.80"}) {
+ t.Fatalf("explicit report IP did not lead: %v", override.IPAddresses)
+ }
+ host.ReportIP = ""
+ after, err := json.Marshal(host)
+ if err != nil || string(before) != string(after) {
+ t.Fatal("host input mutated")
+ }
+ })
+ }
+}
+
+func TestIssue2757AgentDisplayKeepsSecondaryOnlyAddresses(t *testing.T) {
+ t.Parallel()
+ _, identity := resourceFromHost(models.Host{ID: "agent-a", NetworkInterfaces: []models.HostNetworkInterface{
+ {Name: "podman0", Addresses: []string{"10.88.0.1/16"}},
+ {Name: "veth0", Addresses: []string{"10.89.0.1/16"}},
+ }})
+ if !reflect.DeepEqual(identity.IPAddresses, []string{"10.88.0.1", "10.89.0.1"}) {
+ t.Fatalf("secondary-only host lost addresses: %v", identity.IPAddresses)
+ }
+}
+
func TestPhysicalDiskWearoutFromSMARTAttributesClampsExhaustedMedia(t *testing.T) {
percentageUsed := 143
got := physicalDiskWearoutFromSMARTAttributes(&models.SMARTAttributes{
diff --git a/pkg/netutil/interface_priority.go b/pkg/netutil/interface_priority.go
new file mode 100644
index 0000000000..340948f0ec
--- /dev/null
+++ b/pkg/netutil/interface_priority.go
@@ -0,0 +1,21 @@
+// Package netutil contains display-only network metadata helpers.
+package netutil
+
+import "strings"
+
+// IsSecondaryInterfaceName recognises common local-container/overlay names.
+// It is only an address-ordering hint: it proves neither a physical NIC nor a
+// default route. Do not use it to discard interfaces or change machine identity.
+// Management bridges, bonds, VLANs and tunnels are deliberately not excluded.
+func IsSecondaryInterfaceName(name string) bool {
+ name = strings.ToLower(strings.TrimSpace(name))
+ if name == "" || name == "lo" {
+ return true
+ }
+ for _, prefix := range []string{"docker", "podman", "veth", "br-", "cni", "flannel", "virbr", "zt"} {
+ if strings.HasPrefix(name, prefix) {
+ return true
+ }
+ }
+ return false
+}
diff --git a/pkg/netutil/interface_priority_test.go b/pkg/netutil/interface_priority_test.go
new file mode 100644
index 0000000000..a71ba847cb
--- /dev/null
+++ b/pkg/netutil/interface_priority_test.go
@@ -0,0 +1,21 @@
+package netutil
+
+import "testing"
+
+func TestSecondaryInterfaceNamesAreOnlyDisplayHints(t *testing.T) {
+ t.Parallel()
+ for _, name := range []string{"", "lo", "docker0", "podman0", " PODMAN1 ", "veth123", "br-abc", "cni0", "flannel.1", "virbr0", "ztabc"} {
+ t.Run("secondary:"+name, func(t *testing.T) {
+ if !IsSecondaryInterfaceName(name) {
+ t.Fatalf("expected secondary name %q", name)
+ }
+ })
+ }
+ for _, name := range []string{"eth0", "ens18", "Ethernet", "wlp2s0", "br0", "vmbr0", "bond0", "vlan100", "eth0.100", "tun0", "wg0", "tailscale0"} {
+ t.Run("management:"+name, func(t *testing.T) {
+ if IsSecondaryInterfaceName(name) {
+ t.Fatalf("management interface %q must not be classified as local-container/overlay", name)
+ }
+ })
+ }
+}