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.

Merge linked Kubernetes nodes into agent resources

rcourtmane8b0d638d9bc
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index b2733d05db..dfbaf91b75 100644
--- a/docs/release-control/v6/internal/subsystems/unified-resources.md
+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md
@@ -149,6 +149,11 @@ assembly branch.
websocket-backed refreshes so equal-name resources do not silently reshuffle
between cold hydrate and later runtime updates
`internal/unifiedresources/top_level_systems.go`
+ Explicit linked-host correlation is canonical here: when Kubernetes node
+ ingest has a resolved backing host agent, the registry must merge that node
+ into the agent resource instead of publishing duplicate top-level
+ infrastructure rows for the same machine under both `agent` and `k8s-node`
+ identities.
6. Add canonical governed name-resolution or policy-aware resource lookup behavior through `internal/unifiedresources/resolve.go` and `internal/unifiedresources/resolve_context.go`
7. Add or change resource drawer timeline/facet presentation through `frontend-modern/src/components/Infrastructure/ResourceDetailDrawer.tsx`, `frontend-modern/src/components/Infrastructure/ResourceDetailDrawerOverviewTab.tsx`, `frontend-modern/src/components/Infrastructure/ResourceDetailDrawerDebugTab.tsx`, `frontend-modern/src/components/Infrastructure/useResourceDetailDrawerState.ts`, `frontend-modern/src/components/Infrastructure/ResourceFacetSummary.tsx`, `frontend-modern/src/components/Infrastructure/resourceDetailMappers.ts`, and the governed `internal/api/resources.go` facet/timeline contract together
8. Add or change discovery-support runtime under the resource drawer through `frontend-modern/src/components/Discovery/DiscoveryTab.tsx` for shell/presentation ownership and `frontend-modern/src/components/Discovery/useDiscoveryTabState.ts` for fetch, websocket-progress, and notes-mutation ownership
diff --git a/internal/unifiedresources/registry.go b/internal/unifiedresources/registry.go
index 90024f5c03..b6bd98d02d 100644
--- a/internal/unifiedresources/registry.go
+++ b/internal/unifiedresources/registry.go
@@ -671,6 +671,9 @@ func (rr *ResourceRegistry) ingestKubernetesNode(cluster models.KubernetesCluste
if sourceID == "" {
return
}
+ if rr.mergeLinkedKubernetesNode(sourceID, resource, identity, linkedHost) {
+ return
+ }
rr.ingest(SourceK8s, sourceID, resource, identity)
}
@@ -765,6 +768,42 @@ func (rr *ResourceRegistry) ingest(source DataSource, sourceID string, resource
return resource.ID
}
+func (rr *ResourceRegistry) mergeLinkedKubernetesNode(
+ sourceID string,
+ resource Resource,
+ identity ResourceIdentity,
+ linkedHost *models.Host,
+) bool {
+ if linkedHost == nil {
+ return false
+ }
+
+ linkedAgentSourceID := normalizeSourceID(strings.TrimSpace(linkedHost.ID))
+ if linkedAgentSourceID == "" {
+ return false
+ }
+
+ rr.mu.Lock()
+ defer rr.mu.Unlock()
+
+ existingID := rr.bySource[SourceAgent][linkedAgentSourceID]
+ existing := rr.resources[existingID]
+ if existing == nil || existing.Agent == nil {
+ return false
+ }
+
+ resource.Identity = identity
+ resource.Type = CanonicalResourceType(resource.Type)
+ if resource.LastSeen.IsZero() {
+ resource.LastSeen = time.Now().UTC()
+ }
+
+ rr.mergeInto(existing, resource, SourceK8s)
+ rr.bySource[SourceK8s][sourceID] = existing.ID
+ rr.matcher.Add(existing.ID, existing.Identity)
+ return true
+}
+
func (rr *ResourceRegistry) findMatch(identity ResourceIdentity, resourceType ResourceType, candidateID string) (*MatchResult, bool) {
excludedMatch := false
candidates := rr.matcher.FindCandidates(identity)
diff --git a/internal/unifiedresources/registry_test.go b/internal/unifiedresources/registry_test.go
index daa75907ce..a3535925ff 100644
--- a/internal/unifiedresources/registry_test.go
+++ b/internal/unifiedresources/registry_test.go
@@ -2,6 +2,7 @@ package unifiedresources
import (
"reflect"
+ "strings"
"testing"
"time"
@@ -2135,6 +2136,72 @@ func TestRegistryIngestSnapshotPublishesCanonicalKubernetesMetricsTargets(t *tes
assertMetricsTarget(ResourceTypeK8sDeployment, "cluster-1:deployment:deploy-1")
}
+func TestRegistryIngestSnapshotMergesLinkedKubernetesNodeIntoAgentResource(t *testing.T) {
+ rr := NewRegistry(nil)
+
+ rr.IngestSnapshot(models.StateSnapshot{
+ Hosts: []models.Host{
+ {
+ ID: "host-1",
+ Hostname: "prod-euw1-k8s-01",
+ MachineID: "machine-k8s-1",
+ Status: "online",
+ },
+ },
+ KubernetesClusters: []models.KubernetesCluster{
+ {
+ ID: "cluster-1",
+ Name: "production",
+ AgentID: "agent-cluster-1",
+ Nodes: []models.KubernetesNode{
+ {
+ UID: "node-1",
+ Name: "prod-euw1-k8s-01",
+ Ready: true,
+ },
+ },
+ },
+ },
+ })
+
+ resources := rr.List()
+ if got := len(resources); got != 2 {
+ t.Fatalf("expected cluster + merged agent resource, got %d resources", got)
+ }
+
+ var cluster *Resource
+ var host *Resource
+ for i := range resources {
+ switch resources[i].Type {
+ case ResourceTypeK8sCluster:
+ cluster = &resources[i]
+ case ResourceTypeAgent:
+ host = &resources[i]
+ case ResourceTypeK8sNode:
+ t.Fatalf("expected linked kubernetes node to merge into backing agent, got standalone node %+v", resources[i])
+ }
+ }
+
+ if cluster == nil {
+ t.Fatal("expected kubernetes cluster resource")
+ }
+ if host == nil {
+ t.Fatal("expected merged agent resource")
+ }
+ if !hasDataSource(host.Sources, SourceAgent) || !hasDataSource(host.Sources, SourceK8s) {
+ t.Fatalf("expected merged host sources to include agent+kubernetes, got %+v", host.Sources)
+ }
+ if host.Kubernetes == nil {
+ t.Fatal("expected merged host to retain kubernetes node payload")
+ }
+ if got := strings.TrimSpace(host.Kubernetes.NodeName); got != "prod-euw1-k8s-01" {
+ t.Fatalf("kubernetes node name = %q, want prod-euw1-k8s-01", got)
+ }
+ if host.ParentID == nil || strings.TrimSpace(*host.ParentID) != cluster.ID {
+ t.Fatalf("expected merged host parent to point at kubernetes cluster %q, got %+v", cluster.ID, host.ParentID)
+ }
+}
+
func TestRegistryHasMatchingMonitoredSystemRejectsInvalidCandidate(t *testing.T) {
rr := NewRegistry(nil)
rr.IngestRecords(SourceAgent, []IngestRecord{