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.

Adopt a member agent's connection address on cluster re-registration

rcourtman5cde383b988b
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index d411f8a56a..506e09ecb8 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -2909,6 +2909,20 @@ cluster source's primary connection is currently disconnected. Only the primary
configured endpoint may drive disconnected-source repair and token rotation; a
covered member endpoint must not rotate the cluster token just because it can
reach `/api/auto-register`.
+A covered member's re-registration must still land its address: canonical
+auto-register matches the agent against cluster member endpoints (address
+identity against the candidate list first, then an unambiguous corosync
+node-name match) instead of creating a standalone instance for consolidation
+to fold back in and silently discard. The Pulse-verified selected host is
+adopted as that member's `ClusterEndpoints[n].IPOverride` (the durable field
+re-discovery preserves and polling prefers) together with the certificate
+fingerprint captured from that address; an admin-managed override absent from
+the agent's candidate list is preserved, mirroring the top-level stored-host
+preservation rule. The only credential writes a member match may perform are
+a same-token-identity secret refresh (the agent rotates its own token in
+place on reinstall, so the stored secret is already invalid) and full token
+promotion onto a cluster source that has no credentials at all; a member's
+distinct per-node token must never replace working cluster credentials.
That same canonical behavior also includes one auth transport for Proxmox
completion: runtime-side Unified Agent and script callers must send `/api/auto-register`
authentication through a one-time setup token in the request-body
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index a4cfabb622..85246dbb08 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -6632,6 +6632,20 @@ remain re-discovery-owned and must not become client-writable through this
payload. `GET /api/config/nodes` continues to expose the stored value as the
optional `ipOverride` endpoint field consumed by the shared normalization in
`frontend-modern/src/api/nodes.ts`.
+`ClusterEndpoints[n].IPOverride` has a second canonical writer: when a
+canonical `/api/auto-register` PVE registration in
+`internal/api/config_setup_handlers.go` matches a non-primary cluster member
+endpoint (address identity against the agent's candidate list first, then an
+unambiguous corosync node-name match), the handler adopts the Pulse-verified
+selected host as that member's override plus the fingerprint captured from
+it, responds success without creating a node, and normalizes the stored
+value through the same scheme-less `host[:port]` rules as the node update
+payload. A member match must preserve an admin-managed override absent from
+the agent's candidate list, and its only credential writes are a
+same-token-identity secret refresh and full token promotion onto a
+credential-less cluster instance; it must not replace working cluster
+credentials with the member's per-node token, and discovered member `Host`
+and `IP` stay re-discovery-owned on this path too.
The same frontend API contract now also governs Proxmox agent-install command
transport in `frontend-modern/src/api/nodes.ts`: the canonical client request
shape for `/api/agent-install-command` must support both `type:"pve"` and
diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.md
index 24c0b76406..1a60e7c501 100644
--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md
+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md
@@ -127,7 +127,9 @@ readiness check remains authoritative before any action admission or dispatch.
Per-member cluster endpoint connection-address overrides accepted by
`internal/api/config_node_handlers.go` (`clusterEndpointOverrides` on the node
-update payload writing `ClusterEndpoints[n].IPOverride`) are monitoring
+update payload writing `ClusterEndpoints[n].IPOverride`), including the
+agent-driven writes of the same field by canonical auto-register member
+matching in `internal/api/config_setup_handlers.go`, are monitoring
connectivity state only. Storage- and recovery-adjacent surfaces may observe
the effective member address for support diagnostics, but they must not treat
a present or absent `ipOverride` as backup coverage, restore readiness, or
diff --git a/internal/api/config_handlers_canonical_auto_register_test.go b/internal/api/config_handlers_canonical_auto_register_test.go
index ee40740dab..edea6a8037 100644
--- a/internal/api/config_handlers_canonical_auto_register_test.go
+++ b/internal/api/config_handlers_canonical_auto_register_test.go
@@ -232,6 +232,153 @@ func TestHandleCanonicalAutoRegisterSelectsReachableFallbackCandidateHost(t *tes
}
}
+func TestHandleCanonicalAutoRegisterAdoptsClusterMemberConnectionAddress(t *testing.T) {
+ tempDir := t.TempDir()
+ t.Setenv("PULSE_DATA_DIR", tempDir)
+
+ cfg := &config.Config{
+ DataPath: tempDir,
+ ConfigPath: tempDir,
+ PVEInstances: []config.PVEInstance{
+ {
+ Name: "homelab",
+ Host: "https://192.0.2.10:8006",
+ TokenName: "pulse-monitor@pve!pulse-pve01",
+ TokenValue: "cluster-secret",
+ IsCluster: true,
+ ClusterName: "homelab",
+ ClusterEndpoints: []config.ClusterEndpoint{
+ {NodeID: "node/pve01", NodeName: "pve01", Host: "https://pve01:8006", IP: "192.0.2.10"},
+ {NodeID: "node/pve02", NodeName: "pve02", Host: "https://pve02:8006", IP: "192.0.2.11"},
+ },
+ },
+ },
+ }
+ handler := newTestConfigHandlers(t, cfg)
+
+ server := newIPv4TLSServer(t, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
+ w.WriteHeader(http.StatusOK)
+ }))
+ defer server.Close()
+
+ // A reinstalled agent on the second cluster member re-registers with a
+ // fresh route-aware address; the member's stored short-DNS host must not
+ // win. The stale hostname rides along as an outranked candidate.
+ reqBody := AutoRegisterRequest{
+ Type: "pve",
+ Host: server.URL,
+ CandidateHosts: []string{server.URL, "https://pve02:8006"},
+ ServerName: "pve02",
+ TokenID: "pulse-monitor@pve!pulse-pve02",
+ TokenValue: "member-token",
+ Source: "agent",
+ }
+
+ req := httptest.NewRequest(http.MethodPost, "/api/auto-register", nil)
+ rec := httptest.NewRecorder()
+
+ handler.handleCanonicalAutoRegister(rec, req, &reqBody, "127.0.0.1")
+
+ if rec.Code != http.StatusOK {
+ t.Fatalf("status = %d, want 200: %s", rec.Code, rec.Body.String())
+ }
+
+ if len(handler.defaultConfig.PVEInstances) != 1 {
+ t.Fatalf("expected member match to not create an instance, got %d instances", len(handler.defaultConfig.PVEInstances))
+ }
+
+ instance := handler.defaultConfig.PVEInstances[0]
+ if instance.Host != "https://192.0.2.10:8006" {
+ t.Fatalf("cluster host = %q, want untouched primary host", instance.Host)
+ }
+ if instance.TokenName != "pulse-monitor@pve!pulse-pve01" || instance.TokenValue != "cluster-secret" {
+ t.Fatalf("cluster credentials = (%q, %q), want untouched shared token", instance.TokenName, instance.TokenValue)
+ }
+
+ member := instance.ClusterEndpoints[1]
+ wantOverride, err := normalizeClusterEndpointIPOverride(server.URL)
+ if err != nil {
+ t.Fatalf("normalize expected override: %v", err)
+ }
+ if member.IPOverride != wantOverride {
+ t.Fatalf("member override = %q, want adopted agent address %q", member.IPOverride, wantOverride)
+ }
+
+ expectedFingerprint, err := tlsutil.FetchFingerprint(server.URL)
+ if err != nil {
+ t.Fatalf("fetch expected fingerprint: %v", err)
+ }
+ if member.Fingerprint != expectedFingerprint {
+ t.Fatalf("member fingerprint = %q, want pin captured from adopted address %q", member.Fingerprint, expectedFingerprint)
+ }
+
+ untouched := instance.ClusterEndpoints[0]
+ if untouched.IPOverride != "" || untouched.Fingerprint != "" {
+ t.Fatalf("primary member endpoint mutated: override=%q fingerprint=%q", untouched.IPOverride, untouched.Fingerprint)
+ }
+}
+
+func TestHandleCanonicalAutoRegisterPreservesAdminManagedClusterMemberOverride(t *testing.T) {
+ tempDir := t.TempDir()
+ t.Setenv("PULSE_DATA_DIR", tempDir)
+
+ cfg := &config.Config{
+ DataPath: tempDir,
+ ConfigPath: tempDir,
+ PVEInstances: []config.PVEInstance{
+ {
+ Name: "homelab",
+ Host: "https://192.0.2.10:8006",
+ TokenName: "pulse-monitor@pve!pulse-pve01",
+ TokenValue: "cluster-secret",
+ IsCluster: true,
+ ClusterName: "homelab",
+ ClusterEndpoints: []config.ClusterEndpoint{
+ {NodeID: "node/pve01", NodeName: "pve01", Host: "https://pve01:8006", IP: "192.0.2.10"},
+ {NodeID: "node/pve02", NodeName: "pve02", Host: "https://pve02:8006", IP: "192.0.2.11", IPOverride: "10.99.0.5:8006", Fingerprint: "AA:BB"},
+ },
+ },
+ },
+ }
+ handler := newTestConfigHandlers(t, cfg)
+
+ server := newIPv4TLSServer(t, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
+ w.WriteHeader(http.StatusOK)
+ }))
+ defer server.Close()
+
+ reqBody := AutoRegisterRequest{
+ Type: "pve",
+ Host: server.URL,
+ CandidateHosts: []string{server.URL, "https://pve02:8006"},
+ ServerName: "pve02",
+ TokenID: "pulse-monitor@pve!pulse-pve02",
+ TokenValue: "member-token",
+ Source: "agent",
+ }
+
+ req := httptest.NewRequest(http.MethodPost, "/api/auto-register", nil)
+ rec := httptest.NewRecorder()
+
+ handler.handleCanonicalAutoRegister(rec, req, &reqBody, "127.0.0.1")
+
+ if rec.Code != http.StatusOK {
+ t.Fatalf("status = %d, want 200: %s", rec.Code, rec.Body.String())
+ }
+
+ if len(handler.defaultConfig.PVEInstances) != 1 {
+ t.Fatalf("expected member match to not create an instance, got %d instances", len(handler.defaultConfig.PVEInstances))
+ }
+
+ member := handler.defaultConfig.PVEInstances[0].ClusterEndpoints[1]
+ if member.IPOverride != "10.99.0.5:8006" {
+ t.Fatalf("member override = %q, want admin-managed override preserved", member.IPOverride)
+ }
+ if member.Fingerprint != "AA:BB" {
+ t.Fatalf("member fingerprint = %q, want pin for the admin-managed address preserved", member.Fingerprint)
+ }
+}
+
func TestHandleCanonicalAutoRegisterDisablesStrictTLSWhenFingerprintCaptureFails(t *testing.T) {
tempDir := t.TempDir()
t.Setenv("PULSE_DATA_DIR", tempDir)
diff --git a/internal/api/config_setup_handlers.go b/internal/api/config_setup_handlers.go
index 4c76c62054..6dbfe4c6af 100644
--- a/internal/api/config_setup_handlers.go
+++ b/internal/api/config_setup_handlers.go
@@ -11,7 +11,9 @@ import (
"errors"
"fmt"
"io"
+ "net"
"net/http"
+ "net/url"
"os"
"path/filepath"
"strings"
@@ -440,6 +442,168 @@ func shouldPreserveExistingAutoRegisterHost(existingHost string, candidateHosts
return true
}
+// clusterMemberOverrideIdentity canonicalizes a connection address (bare
+// host, host:port, or URL) to lowercase host:port for comparisons, defaulting
+// to the PVE API port. Mirrors config's cluster endpoint identity
+// normalization.
+func clusterMemberOverrideIdentity(value string) string {
+ v := strings.TrimSpace(value)
+ if v == "" {
+ return ""
+ }
+ if !strings.Contains(v, "://") {
+ v = "https://" + v
+ }
+ parsed, err := url.Parse(v)
+ if err != nil || parsed.Hostname() == "" {
+ return ""
+ }
+ host := strings.ToLower(parsed.Hostname())
+ if ip := net.ParseIP(host); ip != nil {
+ host = ip.String()
+ }
+ port := parsed.Port()
+ if port == "" {
+ port = config.DefaultPVEPort
+ }
+ return net.JoinHostPort(host, port)
+}
+
+// findCanonicalAutoRegisterClusterMember locates the cluster member endpoint
+// an auto-registering agent corresponds to when no top-level instance host
+// matched. Endpoint address identity against the agent's candidate list is
+// authoritative; a corosync node-name match (agent hostnames may be FQDNs
+// while corosync names are short) is accepted only when it is unambiguous
+// across every configured instance.
+func findCanonicalAutoRegisterClusterMember(instances []config.PVEInstance, serverName string, candidateHosts []string) (int, int, bool) {
+ for i := range instances {
+ for j := range instances[i].ClusterEndpoints {
+ if autoRegisterClusterEndpointMatchesCandidates(instances[i].ClusterEndpoints[j], candidateHosts) {
+ return i, j, true
+ }
+ }
+ }
+
+ name := strings.ToLower(strings.TrimSpace(serverName))
+ if name == "" {
+ return -1, -1, false
+ }
+ short := name
+ if dot := strings.IndexByte(short, '.'); dot > 0 {
+ short = short[:dot]
+ }
+ matchInstance, matchEndpoint, matches := -1, -1, 0
+ for i := range instances {
+ for j := range instances[i].ClusterEndpoints {
+ nodeName := strings.ToLower(strings.TrimSpace(instances[i].ClusterEndpoints[j].NodeName))
+ if nodeName == "" {
+ continue
+ }
+ if nodeName == name || nodeName == short {
+ matchInstance, matchEndpoint = i, j
+ matches++
+ }
+ }
+ }
+ if matches == 1 {
+ return matchInstance, matchEndpoint, true
+ }
+ return -1, -1, false
+}
+
+// shouldAdoptClusterMemberAutoRegisterAddress reports whether a member-matched
+// re-registration may replace the endpoint's connection override. Discovered
+// member Host/IP are rebuilt from cluster status on every re-discovery, so an
+// empty override always adopts the agent's Pulse-verified address. An existing
+// override is replaced only when it appears in the agent's candidate list
+// (deliberately outranked, the member analogue of
+// shouldPreserveExistingAutoRegisterHost); an override the agent cannot see is
+// admin-managed and kept.
+func shouldAdoptClusterMemberAutoRegisterAddress(existingOverride string, candidateHosts []string) bool {
+ override := clusterMemberOverrideIdentity(existingOverride)
+ if override == "" {
+ return true
+ }
+ for _, candidate := range candidateHosts {
+ if identity := clusterMemberOverrideIdentity(candidate); identity != "" && identity == override {
+ return true
+ }
+ }
+ return false
+}
+
+// adoptCanonicalAutoRegisterClusterMember handles re-registration of an agent
+// whose node is a non-primary cluster member rather than a top-level instance:
+// the cluster connection already covers it, so instead of creating a
+// standalone duplicate (which ConsolidatePVEInstances would fold back in,
+// discarding the agent's address), adopt the Pulse-verified selected host as
+// the member's connection override. A covered member must not replace the
+// cluster's credentials with its own per-node token; the only credential
+// writes are a same-token-identity secret refresh (the agent rotates its
+// token in place on reinstall, so the stored secret is already dead) and a
+// full promotion onto a cluster that has no credentials at all.
+func (h *ConfigHandlers) adoptCanonicalAutoRegisterClusterMember(ctx context.Context, serverName, selectedHost, fingerprint, tokenID, tokenValue string, candidateHosts []string, source string) bool {
+ instances := h.getConfig(ctx).PVEInstances
+ i, j, ok := findCanonicalAutoRegisterClusterMember(instances, serverName, candidateHosts)
+ if !ok {
+ return false
+ }
+ instance := &instances[i]
+ endpoint := &instance.ClusterEndpoints[j]
+
+ switch {
+ case tokenID != "" && instance.TokenName == tokenID:
+ if tokenValue != "" {
+ instance.TokenValue = tokenValue
+ }
+ case tokenID != "" && instance.TokenName == "" && instance.TokenValue == "" && instance.User == "" && instance.Password == "":
+ instance.TokenName = tokenID
+ instance.TokenValue = tokenValue
+ }
+ if instance.Source == "" && strings.TrimSpace(source) != "" {
+ instance.Source = strings.TrimSpace(source)
+ }
+
+ selectedIdentity := clusterMemberOverrideIdentity(selectedHost)
+ effectiveIdentity := clusterMemberOverrideIdentity(endpoint.EffectiveIP())
+ switch {
+ case selectedIdentity == "":
+ return true
+ case selectedIdentity == effectiveIdentity:
+ // The member's effective address already routes to the agent's
+ // selection; just refresh the certificate pin below.
+ case shouldAdoptClusterMemberAutoRegisterAddress(endpoint.IPOverride, candidateHosts):
+ override, err := normalizeClusterEndpointIPOverride(selectedHost)
+ if err != nil || override == "" {
+ return true
+ }
+ log.Info().
+ Str("cluster", instances[i].Name).
+ Str("node", endpoint.NodeName).
+ Str("previousOverride", endpoint.IPOverride).
+ Str("override", override).
+ Msg(canonicalAutoRegisterMatchMessage("cluster member endpoint; adopted agent connection address"))
+ endpoint.IPOverride = override
+ default:
+ // Admin-managed override the agent cannot see; keep it and leave the
+ // fingerprint pinned to that address.
+ log.Info().
+ Str("cluster", instances[i].Name).
+ Str("node", endpoint.NodeName).
+ Str("override", endpoint.IPOverride).
+ Msg(canonicalAutoRegisterMatchMessage("cluster member endpoint; preserved admin-managed override"))
+ return true
+ }
+
+ // The fingerprint was captured from selectedHost, which is now the
+ // member's effective address; a reinstall may have regenerated the node's
+ // TLS certificate, so refresh the pin whenever one was captured.
+ if strings.TrimSpace(fingerprint) != "" {
+ endpoint.Fingerprint = fingerprint
+ }
+ return true
+}
+
func canonicalAutoRegisterCompletionPayloadMessage() string {
return "Incomplete canonical auto-register token completion payload"
}
@@ -1371,6 +1535,11 @@ func (h *ConfigHandlers) handleCanonicalAutoRegister(w http.ResponseWriter, r *h
}
instance.VerifySSL = pveNode.VerifySSL
log.Info().Str("host", host).Str("type", "pve").Msg(canonicalAutoRegisterMatchMessage("host; updated token in-place"))
+ } else if h.adoptCanonicalAutoRegisterClusterMember(r.Context(), serverName, host, fingerprint, fullTokenID, tokenValue, candidateHosts, registrationSource) {
+ // A non-primary cluster member: the cluster connection already
+ // covers this node, so no instance is created and the shared
+ // cluster token is left untouched.
+ log.Info().Str("host", host).Str("type", "pve").Msg(canonicalAutoRegisterMatchMessage("cluster member endpoint"))
} else {
// Agent-token auth is restricted to updating existing nodes only.
if isAgentAutoRegAuth(r.Context()) {
diff --git a/internal/api/config_setup_handlers_test.go b/internal/api/config_setup_handlers_test.go
index f57d5c6741..6cfb4f2354 100644
--- a/internal/api/config_setup_handlers_test.go
+++ b/internal/api/config_setup_handlers_test.go
@@ -1,6 +1,10 @@
package api
-import "testing"
+import (
+ "testing"
+
+ "github.com/rcourtman/pulse-go-rewrite/internal/config"
+)
func TestShouldPreserveExistingAutoRegisterHost(t *testing.T) {
tests := []struct {
@@ -44,3 +48,123 @@ func TestShouldPreserveExistingAutoRegisterHost(t *testing.T) {
})
}
}
+
+func TestClusterMemberOverrideIdentity(t *testing.T) {
+ tests := []struct {
+ name string
+ value string
+ want string
+ }{
+ {name: "url with port", value: "https://192.168.1.12:8006", want: "192.168.1.12:8006"},
+ {name: "bare host defaults port", value: "192.168.1.12", want: "192.168.1.12:8006"},
+ {name: "host with port", value: "pve02:9000", want: "pve02:9000"},
+ {name: "hostname lowercased and port defaulted", value: "PVE02", want: "pve02:8006"},
+ {name: "empty", value: " ", want: ""},
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := clusterMemberOverrideIdentity(tt.value); got != tt.want {
+ t.Fatalf("clusterMemberOverrideIdentity(%q) = %q, want %q", tt.value, got, tt.want)
+ }
+ })
+ }
+}
+
+func TestFindCanonicalAutoRegisterClusterMember(t *testing.T) {
+ instances := []config.PVEInstance{
+ {
+ Name: "clusterA", Host: "https://192.0.2.10:8006", IsCluster: true,
+ ClusterEndpoints: []config.ClusterEndpoint{
+ {NodeName: "pve01", Host: "https://pve01:8006", IP: "192.0.2.10"},
+ {NodeName: "pve02", Host: "https://pve02:8006", IP: "192.0.2.11"},
+ },
+ },
+ {
+ Name: "clusterB", Host: "https://198.51.100.10:8006", IsCluster: true,
+ ClusterEndpoints: []config.ClusterEndpoint{
+ {NodeName: "alpha", Host: "https://alpha:8006", IP: "198.51.100.11"},
+ },
+ },
+ }
+
+ t.Run("endpoint IP identity match wins", func(t *testing.T) {
+ i, j, ok := findCanonicalAutoRegisterClusterMember(instances, "unrelated-name", []string{"https://192.0.2.11:8006"})
+ if !ok || i != 0 || j != 1 {
+ t.Fatalf("got (%d, %d, %v), want (0, 1, true)", i, j, ok)
+ }
+ })
+
+ t.Run("unique node-name match", func(t *testing.T) {
+ i, j, ok := findCanonicalAutoRegisterClusterMember(instances, "pve02", []string{"https://203.0.113.5:8006"})
+ if !ok || i != 0 || j != 1 {
+ t.Fatalf("got (%d, %d, %v), want (0, 1, true)", i, j, ok)
+ }
+ })
+
+ t.Run("fqdn agent hostname matches short corosync name", func(t *testing.T) {
+ i, j, ok := findCanonicalAutoRegisterClusterMember(instances, "pve02.internal.example.com", []string{"https://203.0.113.5:8006"})
+ if !ok || i != 0 || j != 1 {
+ t.Fatalf("got (%d, %d, %v), want (0, 1, true)", i, j, ok)
+ }
+ })
+
+ t.Run("no match", func(t *testing.T) {
+ if _, _, ok := findCanonicalAutoRegisterClusterMember(instances, "unknown", []string{"https://203.0.113.5:8006"}); ok {
+ t.Fatal("expected no match")
+ }
+ })
+
+ t.Run("ambiguous node name across clusters is rejected", func(t *testing.T) {
+ ambiguous := append([]config.PVEInstance(nil), instances...)
+ ambiguous[1].ClusterEndpoints = []config.ClusterEndpoint{
+ {NodeName: "pve02", Host: "https://pve02.other:8006", IP: "198.51.100.12"},
+ }
+ if _, _, ok := findCanonicalAutoRegisterClusterMember(ambiguous, "pve02", []string{"https://203.0.113.5:8006"}); ok {
+ t.Fatal("expected ambiguous name match to be rejected")
+ }
+ })
+}
+
+func TestShouldAdoptClusterMemberAutoRegisterAddress(t *testing.T) {
+ tests := []struct {
+ name string
+ existingOverride string
+ candidateHosts []string
+ want bool
+ }{
+ {
+ name: "empty override always adopts",
+ existingOverride: "",
+ candidateHosts: nil,
+ want: true,
+ },
+ {
+ name: "override outranked in candidate list is replaced",
+ existingOverride: "192.168.1.12:8006",
+ candidateHosts: []string{"https://192.168.1.50:8006", "https://192.168.1.12:8006"},
+ want: true,
+ },
+ {
+ name: "portless override matches default-port candidate",
+ existingOverride: "192.168.1.12",
+ candidateHosts: []string{"https://192.168.1.50:8006", "https://192.168.1.12:8006"},
+ want: true,
+ },
+ {
+ name: "admin-managed override absent from candidates is preserved",
+ existingOverride: "10.99.0.5:8006",
+ candidateHosts: []string{"https://192.168.1.50:8006", "https://192.168.1.12:8006"},
+ want: false,
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := shouldAdoptClusterMemberAutoRegisterAddress(tt.existingOverride, tt.candidateHosts); got != tt.want {
+ t.Fatalf("shouldAdoptClusterMemberAutoRegisterAddress(%q, %v) = %v, want %v",
+ tt.existingOverride, tt.candidateHosts, got, tt.want)
+ }
+ })
+ }
+}