mirror of
https://github.com/status-im/consul.git
synced 2025-01-24 20:51:10 +00:00
agent: Warn on dns-incompatible characters during service registration. Fixes #683.
This commit is contained in:
parent
ebee060dcd
commit
5e801c905d
@ -8,6 +8,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -35,6 +36,11 @@ const (
|
|||||||
"service, but no reason was provided. This is a default message."
|
"service, but no reason was provided. This is a default message."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// serviceNameRe checks if a service name is compatible with DNS.
|
||||||
|
serviceNameRe = regexp.MustCompile(`^[a-zA-Z0-9\-]+$`)
|
||||||
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
The agent is the long running process that is run on every machine.
|
The agent is the long running process that is run on every machine.
|
||||||
It exposes an RPC interface that is used by the CLI to control the
|
It exposes an RPC interface that is used by the CLI to control the
|
||||||
@ -595,6 +601,12 @@ func (a *Agent) AddService(service *structs.NodeService, chkTypes CheckTypes, pe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Warn if the service name is incompatible with DNS
|
||||||
|
if !serviceNameRe.MatchString(service.Service) {
|
||||||
|
a.logger.Printf("[WARN] Service name %q will not be discoverable "+
|
||||||
|
"via DNS due to invalid characters", service.Service)
|
||||||
|
}
|
||||||
|
|
||||||
// Add the service
|
// Add the service
|
||||||
a.state.AddService(service)
|
a.state.AddService(service)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user