From 110d56983d5ebc3f2ee880aa3c8ccc0ed7be74f5 Mon Sep 17 00:00:00 2001 From: Dan Fuhry Date: Fri, 25 Oct 2024 11:43:29 -0400 Subject: [PATCH] [sd] add SRVHost option Kubernetes support, commit 2 of 3: publish `pod-name.service.` as the name in the SRV record when Kubernetes is detected. Preserve legacy behavior by defaulting to `AdvertiseHost` if configured, or our FQDN if not. --- sd/publish.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/sd/publish.go b/sd/publish.go index d2af708..2c56fc8 100644 --- a/sd/publish.go +++ b/sd/publish.go @@ -23,6 +23,7 @@ const ( type SDPublisher struct { AdvertiseHost string + SRVHost string AdvertisePort uint16 Domain string Protocol Layer4Protocol @@ -75,6 +76,18 @@ func (s *SDPublisher) init() error { errors := make([]string, 0) + if s.SRVHost == "" { + if s.AdvertiseHost != "" { + s.SRVHost = s.AdvertiseHost + } else { + if hostname.Containerization() == hostname.ContainerKubernetes { + s.SRVHost = fmt.Sprintf("%s.%s.%s", hostname.Hostname(), s.Service, constants.SDDomain) + } else { + s.SRVHost = hostname.Fqdn() + } + } + } + if s.AdvertiseHost == "" { s.AdvertiseHost = hostname.Fqdn() } @@ -292,7 +305,7 @@ func (s *SDPublisher) srvRecordJson(region string) string { prio = 10 } recordValue, _ := json.Marshal(srvRecord{ - Host: s.AdvertiseHost, + Host: s.SRVHost, Port: s.AdvertisePort, Priority: prio, TTL: uint(leaseRenewalInterval), -- 2.50.1