agent: re-use ConsulServiceID from consul package
This commit is contained in:
parent
5e66e2ae1e
commit
ece81c11ac
|
@ -14,9 +14,6 @@ import (
|
||||||
"github.com/hashicorp/serf/serf"
|
"github.com/hashicorp/serf/serf"
|
||||||
)
|
)
|
||||||
|
|
||||||
// The internal service ID of the consul service
|
|
||||||
const internalServiceID = "consul"
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
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
|
||||||
|
@ -120,8 +117,8 @@ func Create(config *Config, logOutput io.Writer) (*Agent, error) {
|
||||||
|
|
||||||
// Automatically register the "consul" service on server nodes
|
// Automatically register the "consul" service on server nodes
|
||||||
consulService := structs.NodeService{
|
consulService := structs.NodeService{
|
||||||
Service: internalServiceID,
|
Service: consul.ConsulServiceName,
|
||||||
ID: internalServiceID,
|
ID: consul.ConsulServiceID,
|
||||||
Port: agent.config.Ports.Server,
|
Port: agent.config.Ports.Server,
|
||||||
}
|
}
|
||||||
agent.state.AddService(&consulService)
|
agent.state.AddService(&consulService)
|
||||||
|
@ -464,9 +461,9 @@ func (a *Agent) AddService(service *structs.NodeService, chkType *CheckType) err
|
||||||
// The agent will make a best effort to ensure it is deregistered
|
// The agent will make a best effort to ensure it is deregistered
|
||||||
func (a *Agent) RemoveService(serviceID string) error {
|
func (a *Agent) RemoveService(serviceID string) error {
|
||||||
// Protect "consul" service from deletion by a user
|
// Protect "consul" service from deletion by a user
|
||||||
if a.server != nil && serviceID == internalServiceID {
|
if a.server != nil && serviceID == consul.ConsulServiceID {
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"Deregistering the %s service is not allowed", internalServiceID)
|
"Deregistering the %s service is not allowed", consul.ConsulServiceID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove service immeidately
|
// Remove service immeidately
|
||||||
|
|
|
@ -327,7 +327,7 @@ func TestAgent_ConsulService(t *testing.T) {
|
||||||
defer agent.Shutdown()
|
defer agent.Shutdown()
|
||||||
|
|
||||||
services := agent.state.Services()
|
services := agent.state.Services()
|
||||||
if _, ok := services[internalServiceID]; !ok {
|
if _, ok := services[consul.ConsulServiceID]; !ok {
|
||||||
t.Fatalf("%s service should be registered", internalServiceID)
|
t.Fatalf("%s service should be registered", consul.ConsulServiceID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue