Make invalid clusterID be fatal
This commit is contained in:
parent
957aaf69ab
commit
bd5e569dc7
|
@ -946,8 +946,12 @@ func (a *Agent) consulConfig() (*consul.Config, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if base.CAConfig.ClusterID == "" {
|
if base.CAConfig.ClusterID == "" {
|
||||||
a.logger.Println("[WARN] connect CA config cluster_id specified but ",
|
// If the tried to specify an ID but typoed it don't ignore as they will
|
||||||
"is not a valid UUID, ignoring")
|
// then bootstrap with a new ID and have to throw away the whole cluster
|
||||||
|
// and start again.
|
||||||
|
a.logger.Println("[ERR] connect CA config cluster_id specified but " +
|
||||||
|
"is not a valid UUID, aborting startup")
|
||||||
|
return nil, fmt.Errorf("cluster_id was supplied but was not a valid UUID")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1315,9 +1319,11 @@ func (a *Agent) ShutdownAgent() error {
|
||||||
// NOTE(mitchellh): we use Kill for now to kill the processes since
|
// NOTE(mitchellh): we use Kill for now to kill the processes since
|
||||||
// the local state isn't snapshotting meaning the proxy tokens are
|
// the local state isn't snapshotting meaning the proxy tokens are
|
||||||
// regenerated each time forcing the processes to restart anyways.
|
// regenerated each time forcing the processes to restart anyways.
|
||||||
|
if a.proxyManager != nil {
|
||||||
if err := a.proxyManager.Kill(); err != nil {
|
if err := a.proxyManager.Kill(); err != nil {
|
||||||
a.logger.Printf("[WARN] agent: error shutting down proxy manager: %s", err)
|
a.logger.Printf("[WARN] agent: error shutting down proxy manager: %s", err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
if a.delegate != nil {
|
if a.delegate != nil {
|
||||||
|
@ -2177,8 +2183,7 @@ func (a *Agent) verifyProxyToken(token, targetService, targetProxy string) (stri
|
||||||
|
|
||||||
// Resolve the actual ACL token used to register the proxy/service and
|
// Resolve the actual ACL token used to register the proxy/service and
|
||||||
// return that for use in RPC calls.
|
// return that for use in RPC calls.
|
||||||
aclToken := a.State.ServiceToken(targetService)
|
return a.State.ServiceToken(targetService), nil
|
||||||
return aclToken, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve the service specified. This should always exist because
|
// Retrieve the service specified. This should always exist because
|
||||||
|
|
|
@ -60,6 +60,7 @@ func TestAgent_ConnectClusterIDConfig(t *testing.T) {
|
||||||
name string
|
name string
|
||||||
hcl string
|
hcl string
|
||||||
wantClusterID string
|
wantClusterID string
|
||||||
|
wantPanic bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "default TestAgent has fixed cluster id",
|
name: "default TestAgent has fixed cluster id",
|
||||||
|
@ -72,7 +73,7 @@ func TestAgent_ConnectClusterIDConfig(t *testing.T) {
|
||||||
wantClusterID: "",
|
wantClusterID: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "non-UUID cluster_id is ignored",
|
name: "non-UUID cluster_id is fatal",
|
||||||
hcl: `connect {
|
hcl: `connect {
|
||||||
enabled = true
|
enabled = true
|
||||||
ca_config {
|
ca_config {
|
||||||
|
@ -80,14 +81,28 @@ func TestAgent_ConnectClusterIDConfig(t *testing.T) {
|
||||||
}
|
}
|
||||||
}`,
|
}`,
|
||||||
wantClusterID: "",
|
wantClusterID: "",
|
||||||
|
wantPanic: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
a := NewTestAgent("test", tt.hcl)
|
// Indirection to support panic recovery cleanly
|
||||||
|
testFn := func() {
|
||||||
|
a := &TestAgent{Name: "test", HCL: tt.hcl}
|
||||||
|
a.ExpectConfigError = tt.wantPanic
|
||||||
|
a.Start()
|
||||||
|
defer a.Shutdown()
|
||||||
|
|
||||||
cfg := a.consulConfig()
|
cfg := a.consulConfig()
|
||||||
assert.Equal(t, tt.wantClusterID, cfg.CAConfig.ClusterID)
|
assert.Equal(t, tt.wantClusterID, cfg.CAConfig.ClusterID)
|
||||||
|
}
|
||||||
|
|
||||||
|
if tt.wantPanic {
|
||||||
|
require.Panics(t, testFn)
|
||||||
|
} else {
|
||||||
|
testFn()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,7 +110,7 @@ func TestAgent_ConnectClusterIDConfig(t *testing.T) {
|
||||||
func TestAgent_StartStop(t *testing.T) {
|
func TestAgent_StartStop(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
a := NewTestAgent(t.Name(), "")
|
a := NewTestAgent(t.Name(), "")
|
||||||
// defer a.Shutdown()
|
defer a.Shutdown()
|
||||||
|
|
||||||
if err := a.Leave(); err != nil {
|
if err := a.Leave(); err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
|
|
|
@ -45,6 +45,12 @@ type TestAgent struct {
|
||||||
|
|
||||||
HCL string
|
HCL string
|
||||||
|
|
||||||
|
// ExpectConfigError can be set to prevent the agent retrying Start on errors
|
||||||
|
// and eventually blowing up with runtime.Goexit. This enables tests to assert
|
||||||
|
// that some specific bit of config actually does prevent startup entirely in
|
||||||
|
// a reasonable way without reproducing a lot of the boilerplate here.
|
||||||
|
ExpectConfigError bool
|
||||||
|
|
||||||
// Config is the agent configuration. If Config is nil then
|
// Config is the agent configuration. If Config is nil then
|
||||||
// TestConfig() is used. If Config.DataDir is set then it is
|
// TestConfig() is used. If Config.DataDir is set then it is
|
||||||
// the callers responsibility to clean up the data directory.
|
// the callers responsibility to clean up the data directory.
|
||||||
|
@ -159,6 +165,11 @@ func (a *TestAgent) Start() *TestAgent {
|
||||||
} else if i == 0 {
|
} else if i == 0 {
|
||||||
fmt.Println(id, a.Name, "Error starting agent:", err)
|
fmt.Println(id, a.Name, "Error starting agent:", err)
|
||||||
runtime.Goexit()
|
runtime.Goexit()
|
||||||
|
} else if a.ExpectConfigError {
|
||||||
|
// Panic the error since this can be caught if needed. Pretty gross way to
|
||||||
|
// detect errors but enough for now and this is a tiny edge case that I'd
|
||||||
|
// otherwise not have a way to test at all...
|
||||||
|
panic(err)
|
||||||
} else {
|
} else {
|
||||||
agent.ShutdownAgent()
|
agent.ShutdownAgent()
|
||||||
agent.ShutdownEndpoints()
|
agent.ShutdownEndpoints()
|
||||||
|
|
Loading…
Reference in New Issue