diff --git a/agent/agent.go b/agent/agent.go index abce307c3..e65d45f51 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -269,6 +269,17 @@ func (a *Agent) Start() error { return fmt.Errorf("Failed to setup node ID: %v", err) } + // Warn if the node name is incompatible with DNS + if InvalidDnsRe.MatchString(a.config.NodeName) { + a.logger.Printf("[WARN] agent: Node name %q will not be discoverable "+ + "via DNS due to invalid characters. Valid characters include "+ + "all alpha-numerics and dashes.", a.config.NodeName) + } else if ( len(a.config.NodeName) > MaxDNSLabelLength ) { + a.logger.Printf("[WARN] agent: Node name %q will not be discoverable "+ + "via DNS due to it being too long. Valid lengths are between "+ + "1 and 63 bytes.", a.config.NodeName) + } + // create the local state a.State = local.NewState(LocalConfig(c), a.logger, a.tokens) @@ -1549,6 +1560,10 @@ func (a *Agent) AddService(service *structs.NodeService, chkTypes []*structs.Che a.logger.Printf("[WARN] agent: Service name %q will not be discoverable "+ "via DNS due to invalid characters. Valid characters include "+ "all alpha-numerics and dashes.", service.Service) + } else if ( len(service.Service) > MaxDNSLabelLength ) { + a.logger.Printf("[WARN] agent: Service name %q will not be discoverable "+ + "via DNS due to it being too long. Valid lengths are between "+ + "1 and 63 bytes.", service.Service) } // Warn if any tags are incompatible with DNS @@ -1557,6 +1572,10 @@ func (a *Agent) AddService(service *structs.NodeService, chkTypes []*structs.Che a.logger.Printf("[DEBUG] agent: Service tag %q will not be discoverable "+ "via DNS due to invalid characters. Valid characters include "+ "all alpha-numerics and dashes.", tag) + } else if ( len(tag) > MaxDNSLabelLength ) { + a.logger.Printf("[DEBUG] agent: Service tag %q will not be discoverable "+ + "via DNS due to it being too long. Valid lengths are between "+ + "1 and 63 bytes.", tag) } } diff --git a/agent/dns.go b/agent/dns.go index eb59961e6..c9ba4e810 100644 --- a/agent/dns.go +++ b/agent/dns.go @@ -31,6 +31,8 @@ const ( staleCounterThreshold = 5 * time.Second defaultMaxUDPSize = 512 + + MaxDNSLabelLength = 63 ) var InvalidDnsRe = regexp.MustCompile(`[^A-Za-z0-9\\-]+`)