-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Consul Syncer into new ServiceClient
Fixes #2478 #2474 #1995 #2294 The new client only handles agent and task service advertisement. Server discovery is mostly unchanged. The Nomad client agent now handles all Consul operations instead of the executor handling task related operations. When upgrading from an earlier version of Nomad existing executors will be told to deregister from Consul so that the Nomad agent can re-register the task's services and checks. Drivers - other than qemu - now support an Exec method for executing abritrary commands in a task's environment. This is used to implement script checks. Interfaces are used extensively to avoid interacting with Consul in tests that don't assert any Consul related behavior.
- Loading branch information
1 parent
aaf7343
commit 99e7126
Showing
44 changed files
with
2,360 additions
and
2,509 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package client | ||
|
||
import ( | ||
"github.com/hashicorp/nomad/command/agent/consul" | ||
"github.com/hashicorp/nomad/nomad/structs" | ||
) | ||
|
||
// ConsulServiceAPI is the interface the Nomad Client uses to register and | ||
// remove services and checks from Consul. | ||
type ConsulServiceAPI interface { | ||
RegisterTask(allocID string, task *structs.Task, exec consul.ScriptExecutor) error | ||
RemoveTask(allocID string, task *structs.Task) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package client | ||
|
||
import ( | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
"sync" | ||
"testing" | ||
|
||
"github.com/hashicorp/nomad/command/agent/consul" | ||
"github.com/hashicorp/nomad/nomad/structs" | ||
) | ||
|
||
// mockConsulOp represents the register/deregister operations. | ||
type mockConsulOp struct { | ||
allocID string | ||
task *structs.Task | ||
exec consul.ScriptExecutor | ||
} | ||
|
||
// mockConsulServiceClient implements the ConsulServiceAPI interface to record | ||
// and log task registration/deregistration. | ||
type mockConsulServiceClient struct { | ||
registers []mockConsulOp | ||
removes []mockConsulOp | ||
mu sync.Mutex | ||
|
||
logger *log.Logger | ||
} | ||
|
||
func newMockConsulServiceClient() *mockConsulServiceClient { | ||
m := mockConsulServiceClient{ | ||
registers: make([]mockConsulOp, 0, 10), | ||
removes: make([]mockConsulOp, 0, 10), | ||
logger: log.New(ioutil.Discard, "", 0), | ||
} | ||
if testing.Verbose() { | ||
m.logger = log.New(os.Stderr, "", log.LstdFlags) | ||
} | ||
return &m | ||
} | ||
|
||
func (m *mockConsulServiceClient) RegisterTask(allocID string, task *structs.Task, exec consul.ScriptExecutor) error { | ||
m.logger.Printf("[TEST] mock_consul: RegisterTask(%q, %q, %T)", allocID, task.Name, exec) | ||
m.mu.Lock() | ||
defer m.mu.Unlock() | ||
m.registers = append(m.registers, mockConsulOp{allocID, task, exec}) | ||
return nil | ||
} | ||
|
||
func (m *mockConsulServiceClient) RemoveTask(allocID string, task *structs.Task) { | ||
m.logger.Printf("[TEST] mock_consul: RemoveTask(%q, %q)", allocID, task.Name) | ||
m.mu.Lock() | ||
defer m.mu.Unlock() | ||
m.removes = append(m.removes, mockConsulOp{allocID, task, nil}) | ||
} |
Oops, something went wrong.