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.

Reject ambiguous Kubernetes host enrichment

pulse-triage[bot]847564635829
diff --git a/internal/unifiedresources/resolved_host_set.go b/internal/unifiedresources/resolved_host_set.go
index 074382493a..c647b5c55e 100644
--- a/internal/unifiedresources/resolved_host_set.go
+++ b/internal/unifiedresources/resolved_host_set.go
@@ -470,14 +470,20 @@ func enrichK8sNodeIdentity(identity *ResourceIdentity, nodeName string, hosts []
// hostname. Besides being unnecessary, that could create a transitive merge
// between two different machines that happen to share a hostname.
if machineID := strings.TrimSpace(identity.MachineID); machineID != "" {
+ var matched *models.Host
for i := range hosts {
host := &hosts[i]
if strings.TrimSpace(host.MachineID) != machineID {
continue
}
- _, macs := collectInterfaceIDs(host.NetworkInterfaces)
+ if matched != nil {
+ return
+ }
+ matched = host
+ }
+ if matched != nil {
+ _, macs := collectInterfaceIDs(matched.NetworkInterfaces)
identity.MACAddresses = uniqueStrings(append(identity.MACAddresses, macs...))
- return
}
return
}
@@ -488,17 +494,24 @@ func enrichK8sNodeIdentity(identity *ResourceIdentity, nodeName string, hosts []
return
}
+ var exactMatch *models.Host
for i := range hosts {
host := &hosts[i]
if strings.EqualFold(strings.TrimSpace(host.Hostname), nodeName) {
- if host.MachineID != "" && identity.MachineID == "" {
- identity.MachineID = strings.TrimSpace(host.MachineID)
+ if exactMatch != nil {
+ return
}
- _, macs := collectInterfaceIDs(host.NetworkInterfaces)
- identity.MACAddresses = uniqueStrings(append(identity.MACAddresses, macs...))
- return
+ exactMatch = host
}
}
+ if exactMatch != nil {
+ if exactMatch.MachineID != "" {
+ identity.MachineID = strings.TrimSpace(exactMatch.MachineID)
+ }
+ _, macs := collectInterfaceIDs(exactMatch.NetworkInterfaces)
+ identity.MACAddresses = uniqueStrings(append(identity.MACAddresses, macs...))
+ return
+ }
normName := NormalizeHostname(nodeName)
if normName == "" {
diff --git a/internal/unifiedresources/resolved_host_set_test.go b/internal/unifiedresources/resolved_host_set_test.go
index f9a3d7ad40..647cf8bd65 100644
--- a/internal/unifiedresources/resolved_host_set_test.go
+++ b/internal/unifiedresources/resolved_host_set_test.go
@@ -444,6 +444,19 @@ func TestEnrichK8sNodeIdentity_AmbiguousNormalizedHostnameSkipsEnrichment(t *tes
}
}
+func TestEnrichK8sNodeIdentity_AmbiguousExactHostnameSkipsEnrichment(t *testing.T) {
+ hosts := []models.Host{
+ {ID: "h1", Hostname: "k8s-node1", MachineID: "machine-abc", NetworkInterfaces: []models.HostNetworkInterface{{MAC: "00:11:22:33:44:55"}}},
+ {ID: "h2", Hostname: "K8S-NODE1", MachineID: "machine-def", NetworkInterfaces: []models.HostNetworkInterface{{MAC: "00:11:22:33:44:66"}}},
+ }
+ identity := ResourceIdentity{Hostnames: []string{"k8s-node1"}}
+ enrichK8sNodeIdentity(&identity, "k8s-node1", hosts)
+
+ if identity.MachineID != "" || len(identity.MACAddresses) != 0 {
+ t.Fatalf("expected ambiguous exact hostname to skip enrichment, got %+v", identity)
+ }
+}
+
func TestEnrichK8sNodeIdentity_MachineIDDoesNotTrustDuplicateHostname(t *testing.T) {
hosts := []models.Host{
{ID: "wrong", Hostname: "node1", MachineID: "machine-wrong", NetworkInterfaces: []models.HostNetworkInterface{{MAC: "00:11:22:33:44:55"}}},
@@ -457,6 +470,19 @@ func TestEnrichK8sNodeIdentity_MachineIDDoesNotTrustDuplicateHostname(t *testing
}
}
+func TestEnrichK8sNodeIdentity_AmbiguousMachineIDSkipsMACEnrichment(t *testing.T) {
+ hosts := []models.Host{
+ {ID: "one", MachineID: "machine-cloned", NetworkInterfaces: []models.HostNetworkInterface{{MAC: "00:11:22:33:44:55"}}},
+ {ID: "two", MachineID: "machine-cloned", NetworkInterfaces: []models.HostNetworkInterface{{MAC: "00:11:22:33:44:66"}}},
+ }
+ identity := ResourceIdentity{MachineID: "machine-cloned"}
+ enrichK8sNodeIdentity(&identity, "node1", hosts)
+
+ if len(identity.MACAddresses) != 0 {
+ t.Fatalf("expected ambiguous machine ID to skip MAC enrichment, got %v", identity.MACAddresses)
+ }
+}
+
func TestEnrichK8sNodeIdentity_SystemUUIDDoesNotTrustHostname(t *testing.T) {
hosts := []models.Host{{
ID: "same-name", Hostname: "node1", MachineID: "machine-other",