]> go.fuhry.dev Git - runtime.git/commitdiff
[sd] add SRVHost option
authorDan Fuhry <dan@fuhry.com>
Fri, 25 Oct 2024 15:43:29 +0000 (11:43 -0400)
committerDan Fuhry <dan@fuhry.com>
Fri, 25 Oct 2024 15:43:29 +0000 (11:43 -0400)
Kubernetes support, commit 2 of 3: publish `pod-name.service.<SDDomain>` 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

index d2af7080e43ac3f7f87dbfa5db2a5794bad22d82..2c56fc89e94ff84b58e85ad554cb58812a97a94a 100644 (file)
@@ -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),