Documentation ¶
Index ¶
- Constants
- func MakeCheckID(serviceID string, check *structs.ServiceCheck) string
- func MakeTaskServiceID(allocID, taskName string, service *structs.Service) string
- type AgentAPI
- type AllocRegistration
- type CatalogAPI
- type ChecksAPI
- type MockAgent
- func (c *MockAgent) CheckDeregister(checkID string) error
- func (c *MockAgent) CheckRegister(check *api.AgentCheckRegistration) error
- func (c *MockAgent) CheckRegs() []*api.AgentCheckRegistration
- func (c *MockAgent) Checks() (map[string]*api.AgentCheck, error)
- func (c *MockAgent) Self() (map[string]map[string]interface{}, error)
- func (c *MockAgent) ServiceDeregister(serviceID string) error
- func (c *MockAgent) ServiceRegister(service *api.AgentServiceRegistration) error
- func (c *MockAgent) Services() (map[string]*api.AgentService, error)
- func (c *MockAgent) SetStatus(s string) string
- func (c *MockAgent) UpdateTTL(id string, output string, status string) error
- type MockCatalog
- type ServiceClient
- func (c *ServiceClient) AllocRegistrations(allocID string) (*AllocRegistration, error)
- func (c *ServiceClient) RegisterAgent(role string, services []*structs.Service) error
- func (c *ServiceClient) RegisterGroup(alloc *structs.Allocation) error
- func (c *ServiceClient) RegisterTask(task *TaskServices) error
- func (c *ServiceClient) RemoveGroup(alloc *structs.Allocation) error
- func (c *ServiceClient) RemoveTask(task *TaskServices)
- func (c *ServiceClient) Run()
- func (c *ServiceClient) Shutdown() error
- func (c *ServiceClient) UpdateGroup(oldAlloc, newAlloc *structs.Allocation) error
- func (c *ServiceClient) UpdateTTL(id, output, status string) error
- func (c *ServiceClient) UpdateTask(old, newTask *TaskServices) error
- type ServiceRegistration
- type TaskRegistration
- type TaskRestarter
- type TaskServices
Constants ¶
const ( // DefaultQueryWaitDuration is the max duration the Consul Agent will // spend waiting for a response from a Consul Query. DefaultQueryWaitDuration = 2 * time.Second // ServiceTagHTTP is the tag assigned to HTTP services ServiceTagHTTP = "http" // ServiceTagRPC is the tag assigned to RPC services ServiceTagRPC = "rpc" // ServiceTagSerf is the tag assigned to Serf services ServiceTagSerf = "serf" )
Variables ¶
This section is empty.
Functions ¶
func MakeCheckID ¶ added in v0.10.0
func MakeCheckID(serviceID string, check *structs.ServiceCheck) string
MakeCheckID creates a unique ID for a check.
Example Check ID: _nomad-check-434ae42f9a57c5705344974ac38de2aee0ee089d
Types ¶
type AgentAPI ¶ added in v0.6.0
type AgentAPI interface { Services() (map[string]*api.AgentService, error) Checks() (map[string]*api.AgentCheck, error) CheckRegister(check *api.AgentCheckRegistration) error CheckDeregister(checkID string) error Self() (map[string]map[string]interface{}, error) ServiceRegister(service *api.AgentServiceRegistration) error ServiceDeregister(serviceID string) error UpdateTTL(id, output, status string) error }
AgentAPI is the consul/api.Agent API used by Nomad.
type AllocRegistration ¶ added in v0.6.1
type AllocRegistration struct { // Tasks maps the name of a task to its registered services and checks Tasks map[string]*TaskRegistration }
AllocRegistration holds the status of services registered for a particular allocations by task.
func (*AllocRegistration) NumChecks ¶ added in v0.6.1
func (a *AllocRegistration) NumChecks() int
NumChecks returns the number of registered checks
func (*AllocRegistration) NumServices ¶ added in v0.6.1
func (a *AllocRegistration) NumServices() int
NumServices returns the number of registered services
type CatalogAPI ¶ added in v0.6.0
type CatalogAPI interface { Datacenters() ([]string, error) Service(service, tag string, q *api.QueryOptions) ([]*api.CatalogService, *api.QueryMeta, error) }
CatalogAPI is the consul/api.Catalog API used by Nomad.
type ChecksAPI ¶ added in v0.7.0
type ChecksAPI interface { // Checks returns a list of all checks. Checks() (map[string]*api.AgentCheck, error) }
ChecksAPI is the part of the Consul API the checkWatcher requires.
type MockAgent ¶ added in v0.7.0
type MockAgent struct {
// contains filtered or unexported fields
}
MockAgent is a fake in-memory Consul backend for ServiceClient.
func NewMockAgent ¶ added in v0.7.0
func NewMockAgent() *MockAgent
NewMockAgent that returns all checks as passing.
func (*MockAgent) CheckDeregister ¶ added in v0.7.0
func (*MockAgent) CheckRegister ¶ added in v0.7.0
func (c *MockAgent) CheckRegister(check *api.AgentCheckRegistration) error
func (*MockAgent) CheckRegs ¶ added in v0.7.1
func (c *MockAgent) CheckRegs() []*api.AgentCheckRegistration
CheckRegs returns the raw AgentCheckRegistrations registered with this mock agent.
func (*MockAgent) Checks ¶ added in v0.7.0
func (c *MockAgent) Checks() (map[string]*api.AgentCheck, error)
Checks implements the Agent API Checks method.
func (*MockAgent) ServiceDeregister ¶ added in v0.7.0
func (*MockAgent) ServiceRegister ¶ added in v0.7.0
func (c *MockAgent) ServiceRegister(service *api.AgentServiceRegistration) error
func (*MockAgent) Services ¶ added in v0.7.0
func (c *MockAgent) Services() (map[string]*api.AgentService, error)
type MockCatalog ¶ added in v0.6.0
type MockCatalog struct {
// contains filtered or unexported fields
}
MockCatalog can be used for testing where the CatalogAPI is needed.
func NewMockCatalog ¶ added in v0.6.0
func NewMockCatalog(l log.Logger) *MockCatalog
func (*MockCatalog) Datacenters ¶ added in v0.6.0
func (m *MockCatalog) Datacenters() ([]string, error)
func (*MockCatalog) Service ¶ added in v0.6.0
func (m *MockCatalog) Service(service, tag string, q *api.QueryOptions) ([]*api.CatalogService, *api.QueryMeta, error)
type ServiceClient ¶ added in v0.6.0
type ServiceClient struct {
// contains filtered or unexported fields
}
ServiceClient handles task and agent service registration with Consul.
func NewServiceClient ¶ added in v0.6.0
func NewServiceClient(consulClient AgentAPI, logger log.Logger, isNomadClient bool) *ServiceClient
NewServiceClient creates a new Consul ServiceClient from an existing Consul API Client, logger and takes whether the client is being used by a Nomad Client agent. When being used by a Nomad client, this Consul client reconciles all services and checks created by Nomad on behalf of running tasks.
func (*ServiceClient) AllocRegistrations ¶ added in v0.6.1
func (c *ServiceClient) AllocRegistrations(allocID string) (*AllocRegistration, error)
AllocRegistrations returns the registrations for the given allocation. If the allocation has no reservations, the response is a nil object.
func (*ServiceClient) RegisterAgent ¶ added in v0.6.0
func (c *ServiceClient) RegisterAgent(role string, services []*structs.Service) error
RegisterAgent registers Nomad agents (client or server). The Service.PortLabel should be a literal port to be parsed with SplitHostPort. Script checks are not supported and will return an error. Registration is asynchronous.
Agents will be deregistered when Shutdown is called.
func (*ServiceClient) RegisterGroup ¶ added in v0.10.0
func (c *ServiceClient) RegisterGroup(alloc *structs.Allocation) error
RegisterGroup services with Consul. Adds all task group-level service entries and checks to Consul.
func (*ServiceClient) RegisterTask ¶ added in v0.6.0
func (c *ServiceClient) RegisterTask(task *TaskServices) error
RegisterTask with Consul. Adds all service entries and checks to Consul. If exec is nil and a script check exists an error is returned.
If the service IP is set it used as the address in the service registration. Checks will always use the IP from the Task struct (host's IP).
Actual communication with Consul is done asynchronously (see Run).
func (*ServiceClient) RemoveGroup ¶ added in v0.10.0
func (c *ServiceClient) RemoveGroup(alloc *structs.Allocation) error
RemoveGroup services with Consul. Removes all task group-level service entries and checks from Consul.
func (*ServiceClient) RemoveTask ¶ added in v0.6.0
func (c *ServiceClient) RemoveTask(task *TaskServices)
RemoveTask from Consul. Removes all service entries and checks.
Actual communication with Consul is done asynchronously (see Run).
func (*ServiceClient) Run ¶ added in v0.6.0
func (c *ServiceClient) Run()
Run the Consul main loop which retries operations against Consul. It should be called exactly once.
func (*ServiceClient) Shutdown ¶ added in v0.6.0
func (c *ServiceClient) Shutdown() error
Shutdown the Consul client. Update running task registrations and deregister agent from Consul. On first call blocks up to shutdownWait before giving up on syncing operations.
func (*ServiceClient) UpdateGroup ¶ added in v0.10.0
func (c *ServiceClient) UpdateGroup(oldAlloc, newAlloc *structs.Allocation) error
UpdateGroup services with Consul. Updates all task group-level service entries and checks to Consul.
func (*ServiceClient) UpdateTTL ¶ added in v0.10.0
func (c *ServiceClient) UpdateTTL(id, output, status string) error
UpdateTTL is used to update the TTL of a check. Typically this will only be called to heartbeat script checks.
func (*ServiceClient) UpdateTask ¶ added in v0.6.0
func (c *ServiceClient) UpdateTask(old, newTask *TaskServices) error
UpdateTask in Consul. Does not alter the service if only checks have changed.
DriverNetwork must not change between invocations for the same allocation.
type ServiceRegistration ¶ added in v0.6.1
type ServiceRegistration struct { // Service is the AgentService registered in Consul. Service *api.AgentService // Checks is the status of the registered checks. Checks []*api.AgentCheck // contains filtered or unexported fields }
ServiceRegistration holds the status of a registered Consul Service and its Checks.
type TaskRegistration ¶ added in v0.6.1
type TaskRegistration struct {
Services map[string]*ServiceRegistration
}
TaskRegistration holds the status of services registered for a particular task.
type TaskRestarter ¶ added in v0.7.0
type TaskRestarter interface {
Restart(ctx context.Context, event *structs.TaskEvent, failure bool) error
}
TaskRestarter allows the checkWatcher to restart tasks.
type TaskServices ¶ added in v0.8.4
type TaskServices struct { AllocID string // Name of the task Name string // Canary indicates whether or not the allocation is a canary Canary bool // Restarter allows restarting the task depending on the task's // check_restart stanzas. Restarter TaskRestarter // Services and checks to register for the task. Services []*structs.Service // Networks from the task's resources stanza. Networks structs.Networks // DriverExec is the script executor for the task's driver. DriverExec interfaces.ScriptExecutor // DriverNetwork is the network specified by the driver and may be nil. DriverNetwork *drivers.DriverNetwork }
func NewTaskServices ¶ added in v0.8.4
func NewTaskServices(alloc *structs.Allocation, task *structs.Task, restarter TaskRestarter, exec interfaces.ScriptExecutor, net *drivers.DriverNetwork) *TaskServices
func (*TaskServices) Copy ¶ added in v0.8.4
func (t *TaskServices) Copy() *TaskServices
Copy method for easing tests