Documentation ¶
Index ¶
- func GetAddress(address, addressMode, portLabel string, networks structs.Networks, ...) (string, int, error)
- func MakeAllocServiceID(allocID, taskName string, service *structs.Service) string
- type AllocRegistration
- type Handler
- type ServiceRegistration
- type ServiceRegistrations
- type WorkloadRestarter
- type WorkloadServices
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetAddress ¶
func GetAddress( address, addressMode, portLabel string, networks structs.Networks, driverNet *drivers.DriverNetwork, ports structs.AllocatedPorts, netStatus *structs.AllocNetworkStatus, ) (string, int, error)
GetAddress returns the IP (or custom advertise address) and port to use for a service or check registration. If no port label is specified (an empty value) and no custom address is specified, zero values are returned because no address could be resolved.
func MakeAllocServiceID ¶
MakeAllocServiceID creates a unique ID for identifying an alloc service in a service registration provider. Both Nomad and Consul solutions use the same ID format to provide consistency.
Example Service ID: _nomad-task-b4e61df9-b095-d64e-f241-23860da1375f-redis-http-http
Types ¶
type AllocRegistration ¶
type AllocRegistration struct { // Tasks maps the name of a task to its registered services and checks. Tasks map[string]*ServiceRegistrations }
AllocRegistration holds the status of services registered for a particular allocations by task.
func (*AllocRegistration) Copy ¶
func (a *AllocRegistration) Copy() *AllocRegistration
Copy performs a deep copy of the AllocRegistration object.
func (*AllocRegistration) NumChecks ¶
func (a *AllocRegistration) NumChecks() int
NumChecks returns the number of registered checks.
func (*AllocRegistration) NumServices ¶
func (a *AllocRegistration) NumServices() int
NumServices returns the number of registered services.
type Handler ¶
type Handler interface { // RegisterWorkload adds all service entries and checks to the backend // provider. Whilst callers attempt to ensure WorkloadServices.Services is // not empty before calling this function, implementations should also // perform this. RegisterWorkload(workload *WorkloadServices) error // RemoveWorkload all service entries and checks from the backend provider // that are found within the passed WorkloadServices object. Whilst callers // attempt to ensure WorkloadServices.Services is not empty before calling // this function, implementations should also perform this. RemoveWorkload(workload *WorkloadServices) // UpdateWorkload removes workload as specified by the old parameter, and // adds workload as specified by the new parameter. Callers do not perform // any deduplication on both objects, it is therefore the responsibility of // the implementation. UpdateWorkload(old, newTask *WorkloadServices) error // AllocRegistrations returns the registrations for the given allocation. AllocRegistrations(allocID string) (*AllocRegistration, error) // UpdateTTL is used to update the TTL of an individual service // registration check. UpdateTTL(id, namespace, output, status string) error }
Handler is the interface the Nomad Client uses to register, update and remove services and checks from service registration providers. Currently, Consul and Nomad are supported providers.
When utilising Consul, the ACL "service:write" is required. It supports all functionality and is the OG/GOAT.
When utilising Nomad, the client secret ID is used for authorisation. It currently supports service registrations only.
type ServiceRegistration ¶
type ServiceRegistration struct { // serviceID and checkIDs are internal fields that track just the IDs of the // services/checks registered in Consul. It is used to materialize the other // fields when queried. ServiceID string CheckIDs map[string]struct{} // todo: use a Set? // CheckOnUpdate is a map of checkIDs and the associated OnUpdate value // from the ServiceCheck It is used to determine how a reported checks // status should be evaluated. CheckOnUpdate map[string]string // Service is the AgentService registered in Consul. Service *api.AgentService // Checks is the status of the registered checks. Checks []*api.AgentCheck }
ServiceRegistration holds the status of a registered Consul Service and its Checks.
type ServiceRegistrations ¶
type ServiceRegistrations struct {
Services map[string]*ServiceRegistration
}
ServiceRegistrations holds the status of services registered for a particular task or task group.
type WorkloadRestarter ¶
type WorkloadRestarter interface {
Restart(ctx context.Context, event *structs.TaskEvent, failure bool) error
}
WorkloadRestarter allows the checkWatcher to restart tasks or entire task groups.
type WorkloadServices ¶
type WorkloadServices struct { AllocID string // Group in which the service belongs for a group-level service, or the // group in which task belongs for a task-level service. Group string // Task in which the service belongs for task-level service. Will be empty // for a group-level service. Task string // JobID provides additional context for providers regarding which job // caused this registration. JobID string // Canary indicates whether, or not the allocation is a canary. This is // used to build the correct tags mapping. Canary bool // Namespace is the provider namespace in which services will be // registered, if the provider supports this functionality. Namespace string // Restarter allows restarting the task or task group depending on the // check_restart stanzas. Restarter WorkloadRestarter // Services and checks to register for the task. Services []*structs.Service // Networks from the task's resources stanza. // TODO: remove and use Ports Networks structs.Networks // NetworkStatus from alloc if network namespace is created. // Can be nil. NetworkStatus *structs.AllocNetworkStatus // AllocatedPorts is the list of port mappings. Ports structs.AllocatedPorts // DriverExec is the script executor for the task's driver. For group // services this is nil and script execution is managed by a tasklet in the // taskrunner script_check_hook. DriverExec interfaces.ScriptExecutor // DriverNetwork is the network specified by the driver and may be nil. DriverNetwork *drivers.DriverNetwork }
WorkloadServices describes services defined in either a Task or TaskGroup that need to be syncronized with a service registration provider.
func (*WorkloadServices) Copy ¶
func (ws *WorkloadServices) Copy() *WorkloadServices
Copy method for easing tests.
func (*WorkloadServices) Name ¶
func (ws *WorkloadServices) Name() string
func (*WorkloadServices) RegistrationProvider ¶
func (ws *WorkloadServices) RegistrationProvider() string
RegistrationProvider identifies the service registration provider for the WorkloadServices.