Documentation
¶
Index ¶
- func ConvertMapStringStringToURLValues(params map[string]string) url.Values
- func EqualMapStringString(l map[string]string, r map[string]string) bool
- func EqualNodeIPSet(l NodeIPSet, r NodeIPSet) bool
- func GetNodeMiniCreateParameters(node NodeMini) map[string]string
- func GetNodeMiniRemoveParameters(node NodeMini) map[string]string
- func GetSwarmServiceMiniCreateParameters(ssm SwarmServiceMini) map[string]string
- func GetSwarmServiceMiniRemoveParameters(ssm SwarmServiceMini) map[string]string
- func GetTaskList(ctx context.Context, client *client.Client, serviceID string) ([]swarm.Task, error)
- func NewDockerClientFromEnv() (*client.Client, error)
- func TasksAllRunning(ctx context.Context, cli *client.Client, serviceID string) (bool, error)
- type CancelManager
- type CancelManaging
- type Event
- type EventType
- type NodeCache
- type NodeCacher
- type NodeClient
- type NodeIP
- type NodeIPSet
- type NodeInspector
- type NodeListener
- type NodeListening
- type NodeMini
- type NodePoller
- type NodePolling
- type Notification
- type NotificationSender
- type Notifier
- type NotifyDistributing
- type NotifyDistributor
- type NotifyEndpoint
- type NotifyType
- type SwarmListener
- func (l *SwarmListener) CompletelyNotifyServices()
- func (l SwarmListener) GetNodesParameters(ctx context.Context) ([]map[string]string, error)
- func (l SwarmListener) GetServicesParameters(ctx context.Context) ([]map[string]string, error)
- func (l SwarmListener) NotifyNodes(consultCache bool)
- func (l SwarmListener) NotifyServices(consultCache bool)
- func (l *SwarmListener) Run()
- type SwarmListening
- type SwarmService
- type SwarmServiceCache
- func (c *SwarmServiceCache) Delete(ID string)
- func (c *SwarmServiceCache) Get(ID string) (SwarmServiceMini, bool)
- func (c *SwarmServiceCache) InsertAndCheck(ss SwarmServiceMini) bool
- func (c *SwarmServiceCache) IsNewOrUpdated(ss SwarmServiceMini) bool
- func (c *SwarmServiceCache) Keys() map[string]struct{}
- func (c *SwarmServiceCache) Len() int
- type SwarmServiceCacher
- type SwarmServiceClient
- func (c SwarmServiceClient) GetNodeInfo(ctx context.Context, ss SwarmService) (NodeIPSet, error)
- func (c SwarmServiceClient) SwarmServiceInspect(ctx context.Context, serviceID string) (*SwarmService, error)
- func (c SwarmServiceClient) SwarmServiceList(ctx context.Context) ([]SwarmService, error)
- func (c SwarmServiceClient) SwarmServiceRunning(ctx context.Context, serviceID string) (bool, error)
- type SwarmServiceInspector
- type SwarmServiceListener
- type SwarmServiceListening
- type SwarmServiceMini
- type SwarmServicePoller
- type SwarmServicePolling
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertMapStringStringToURLValues ¶
ConvertMapStringStringToURLValues converts params to `url.Values`
func EqualMapStringString ¶
EqualMapStringString Returns true when the two maps are equal
func EqualNodeIPSet ¶
EqualNodeIPSet returns true when NodeIPSets contain the same elements
func GetNodeMiniCreateParameters ¶
GetNodeMiniCreateParameters converts `NodeMini` into parameters
func GetNodeMiniRemoveParameters ¶
GetNodeMiniRemoveParameters converts `NodeMini` into remove parameters
func GetSwarmServiceMiniCreateParameters ¶
func GetSwarmServiceMiniCreateParameters(ssm SwarmServiceMini) map[string]string
GetSwarmServiceMiniCreateParameters converts `SwarmServiceMini` into parameters
func GetSwarmServiceMiniRemoveParameters ¶
func GetSwarmServiceMiniRemoveParameters(ssm SwarmServiceMini) map[string]string
GetSwarmServiceMiniRemoveParameters converts `SwarmServiceMini` into remove parameters
func GetTaskList ¶
func GetTaskList(ctx context.Context, client *client.Client, serviceID string) ([]swarm.Task, error)
GetTaskList returns tasks when it is the service is converged
func NewDockerClientFromEnv ¶
NewDockerClientFromEnv returns a `*client.Client` struct using environment variable `DF_DOCKER_HOST` for the host
Types ¶
type CancelManager ¶
type CancelManager struct {
// contains filtered or unexported fields
}
CancelManager implements the `CancelManaging` interface that is thread safe
func NewCancelManager ¶
func NewCancelManager() *CancelManager
NewCancelManager creates a new `CancelManager`
func (*CancelManager) Add ¶
Add creates an context for `id` and `reqID` and returns that context. If `id` exists in memory, the task with that `id` will be canceled.
func (*CancelManager) Delete ¶
func (m *CancelManager) Delete(id string, reqID int64) bool
Delete calls cancel context with the corresponding `id` and `reqID` and removes 'id' from map If the corresponding `id` and `reqID` are not present, Delete does nothing. In all cases, Delete returns true if an item was deleted
type CancelManaging ¶
type CancelManaging interface { Add(rootCtx context.Context, id string, reqID int64) context.Context Delete(id string, reqID int64) bool }
CancelManaging manages canceling of contexts
type NodeCache ¶
type NodeCache struct {
// contains filtered or unexported fields
}
NodeCache implements `NodeCacher` Not threadsafe!
func (*NodeCache) InsertAndCheck ¶
InsertAndCheck inserts `NodeMini` into cache If the node is new or updated `InsertAndCheck` returns true.
func (*NodeCache) IsNewOrUpdated ¶
IsNewOrUpdated returns true if node is new or updated
type NodeCacher ¶
type NodeCacher interface { InsertAndCheck(n NodeMini) bool IsNewOrUpdated(n NodeMini) bool Delete(ID string) Get(ID string) (NodeMini, bool) Keys() map[string]struct{} }
NodeCacher caches sevices
type NodeClient ¶
NodeClient implementes `NodeInspector` for docker
func NewNodeClient ¶
func NewNodeClient(c *client.Client) *NodeClient
NewNodeClient creates a `NodeClient`
func (NodeClient) NodeInspect ¶
func (c NodeClient) NodeInspect(nodeID string) (swarm.Node, error)
NodeInspect returns `swarm.Node` from its ID
type NodeIPSet ¶
type NodeIPSet map[NodeIP]struct{}
NodeIPSet is a set of NodeIPs
func (NodeIPSet) Cardinality ¶
Cardinality returns the size of set
func (NodeIPSet) MarshalJSON ¶
MarshalJSON creates JSON array from NodeIPSet
func (*NodeIPSet) UnmarshalJSON ¶
UnmarshalJSON recreates NodeIPSet from a JSON array
type NodeInspector ¶
type NodeInspector interface { NodeInspect(nodeID string) (swarm.Node, error) NodeList(ctx context.Context) ([]swarm.Node, error) }
NodeInspector is able to inspect a swarm node
type NodeListener ¶
type NodeListener struct {
// contains filtered or unexported fields
}
NodeListener listens for docker node events
func NewNodeListener ¶
func NewNodeListener(c *client.Client, logger *log.Logger) *NodeListener
NewNodeListener creates a `NodeListener“
func (NodeListener) ListenForNodeEvents ¶
func (s NodeListener) ListenForNodeEvents( eventChan chan<- Event)
ListenForNodeEvents listens for events and places them on channels
type NodeListening ¶
type NodeListening interface {
ListenForNodeEvents(eventChan chan<- Event)
}
NodeListening listens to node events
type NodeMini ¶
type NodeMini struct { ID string Hostname string VersionIndex uint64 State swarm.NodeState Addr string NodeLabels map[string]string EngineLabels map[string]string Role swarm.NodeRole Availability swarm.NodeAvailability }
NodeMini is a optimized version of `swarm.Node` for caching purposes
func MinifyNode ¶
MinifyNode minifies `swarm.Node` only labels prefixed with `com.df.` will be used
type NodePoller ¶
type NodePoller struct { Client NodeInspector Cache NodeCacher PollingInterval int MinifyFunc func(swarm.Node) NodeMini Log *log.Logger }
NodePoller implements `NodePolling`
func NewNodePoller ¶
func NewNodePoller( client NodeInspector, cache NodeCacher, pollingInterval int, minifyFunc func(swarm.Node) NodeMini, log *log.Logger, ) *NodePoller
NewNodePoller creates a new `NodePoller`
func (NodePoller) Run ¶
func (n NodePoller) Run(eventChan chan<- Event)
Run starts poller and places events onto `eventChan`
type NodePolling ¶
type NodePolling interface {
Run(eventChan chan<- Event)
}
NodePolling provides an interface for polling node changes
type Notification ¶
type Notification struct { EventType EventType ID string Parameters string TimeNano int64 Context context.Context ErrorChan chan error }
Notification is a node notification
type NotificationSender ¶
type NotificationSender interface { Create(ctx context.Context, params string) error Remove(ctx context.Context, params string) error GetCreateAddr() string GetRemoveAddr() string }
NotificationSender sends notifications to listeners
type Notifier ¶
type Notifier struct {
// contains filtered or unexported fields
}
Notifier implements `NotificationSender`
func NewNotifier ¶
func NewNotifier( createAddr, removeAddr, createHTTPMethod, removeHTTPMethod, notifyType string, retries int, interval int, logger *log.Logger) *Notifier
NewNotifier returns a `Notifier`
func (Notifier) GetCreateAddr ¶
GetCreateAddr returns create addresses
func (Notifier) GetRemoveAddr ¶
GetRemoveAddr returns create addresses
type NotifyDistributing ¶
type NotifyDistributing interface { Run(serviceChan <-chan Notification, nodeChan <-chan Notification) HasServiceListeners() bool HasNodeListeners() bool }
NotifyDistributing takes a stream of `Notification` and NodeNotifiction and distributes it listeners
type NotifyDistributor ¶
type NotifyDistributor struct { NotifyEndpoints map[string]NotifyEndpoint ServiceCancelManager CancelManaging NodeCancelManager CancelManaging // contains filtered or unexported fields }
NotifyDistributor distributes service and node notifications to `NotifyEndpoints` `NotifyEndpoints` are keyed by hostname to send notifications to
func NewNotifyDistributorFromEnv ¶
func NewNotifyDistributorFromEnv(retries, interval int, extraCreateServiceAddr, extraRemoveServiceAddr, extraCreateNodeAddr, extraRemoveNodeAddr string, logger *log.Logger) *NotifyDistributor
NewNotifyDistributorFromEnv creates `NotifyDistributor` from environment variables
func (NotifyDistributor) HasNodeListeners ¶
func (d NotifyDistributor) HasNodeListeners() bool
HasNodeListeners when there exists node listeners
func (NotifyDistributor) HasServiceListeners ¶
func (d NotifyDistributor) HasServiceListeners() bool
HasServiceListeners when there exists service listeners
func (NotifyDistributor) Run ¶
func (d NotifyDistributor) Run(serviceChan <-chan Notification, nodeChan <-chan Notification)
Run starts the distributor
type NotifyEndpoint ¶
type NotifyEndpoint struct { ServiceNotifier NotificationSender NodeNotifier NotificationSender }
NotifyEndpoint holds Notifiers and channels to watch
type SwarmListener ¶
type SwarmListener struct { SSListener SwarmServiceListening SSClient SwarmServiceInspector SSCache SwarmServiceCacher SSPoller SwarmServicePolling SSEventChan chan Event SSNotificationChan chan Notification SSInternalEventChan chan Event NodeListener NodeListening NodeClient NodeInspector NodeCache NodeCacher NodePoller NodePolling NodeEventChan chan Event NodeNotificationChan chan Notification NodeInteralEventChan chan Event NotifyDistributor NotifyDistributing ServiceCancelManager CancelManaging NodeCancelManager CancelManaging IncludeNodeInfo bool UseDockerServiceEvents bool UseDockerNodeEvents bool NotifyCreateServiceImmediately bool IgnoreKey string IncludeKey string HasServiceListeners bool HasNodeListeners bool Log *log.Logger StopServiceEventChan chan struct{} StopNodeEventChan chan struct{} }
SwarmListener provides public api
func NewSwarmListenerFromEnv ¶
func NewSwarmListenerFromEnv( retries, interval, servicePollingInterval, nodePollingInterval int, logger *log.Logger) (*SwarmListener, error)
NewSwarmListenerFromEnv creats `SwarmListener` from environment variables
func (*SwarmListener) CompletelyNotifyServices ¶
func (l *SwarmListener) CompletelyNotifyServices()
CompletelyNotifyServices stops event processing and sends out create AND remove notifications based on if the service is up, down. If the service is starting up and not up get, a remove notification is send, and a create service event is place on the event queue.
func (SwarmListener) GetNodesParameters ¶
GetNodesParameters get all nodes
func (SwarmListener) GetServicesParameters ¶
GetServicesParameters get all services
func (SwarmListener) NotifyNodes ¶
func (l SwarmListener) NotifyNodes(consultCache bool)
NotifyNodes places all services on queue to notify serivces on node events
func (SwarmListener) NotifyServices ¶
func (l SwarmListener) NotifyServices(consultCache bool)
NotifyServices places all services on queue to notify services on service events
type SwarmListening ¶
type SwarmListening interface { Run() NotifyServices(consultCache bool) NotifyNodes(consultCache bool) GetServicesParameters(ctx context.Context) ([]map[string]string, error) GetNodesParameters(ctx context.Context) ([]map[string]string, error) }
SwarmListening provides public api for interacting with swarm listener
type SwarmService ¶
SwarmService defines internal structure with service information
type SwarmServiceCache ¶
type SwarmServiceCache struct {
// contains filtered or unexported fields
}
SwarmServiceCache implements `SwarmServiceCacher`
func NewSwarmServiceCache ¶
func NewSwarmServiceCache() *SwarmServiceCache
NewSwarmServiceCache creates a new `NewSwarmServiceCache`
func (*SwarmServiceCache) Delete ¶
func (c *SwarmServiceCache) Delete(ID string)
Delete delets service from cache
func (*SwarmServiceCache) Get ¶
func (c *SwarmServiceCache) Get(ID string) (SwarmServiceMini, bool)
Get gets service from cache
func (*SwarmServiceCache) InsertAndCheck ¶
func (c *SwarmServiceCache) InsertAndCheck(ss SwarmServiceMini) bool
InsertAndCheck inserts `SwarmServiceMini` into cache If the service is new or updated `InsertAndCheck` returns true.
func (*SwarmServiceCache) IsNewOrUpdated ¶
func (c *SwarmServiceCache) IsNewOrUpdated(ss SwarmServiceMini) bool
IsNewOrUpdated returns true if service is new or updated
func (*SwarmServiceCache) Keys ¶
func (c *SwarmServiceCache) Keys() map[string]struct{}
Keys returns the keys of the cache
func (*SwarmServiceCache) Len ¶
func (c *SwarmServiceCache) Len() int
Len returns the number of items in cache
type SwarmServiceCacher ¶
type SwarmServiceCacher interface { InsertAndCheck(ss SwarmServiceMini) bool IsNewOrUpdated(ss SwarmServiceMini) bool Delete(ID string) Get(ID string) (SwarmServiceMini, bool) Len() int Keys() map[string]struct{} }
SwarmServiceCacher caches sevices
type SwarmServiceClient ¶
type SwarmServiceClient struct { DockerClient *client.Client FilterLabel string FilterKey string ScrapeNetLabel string ServiceNamePrefix string IncludeTaskAddressInNodeInfo bool Log *log.Logger }
SwarmServiceClient implements `SwarmServiceInspector` for docker
func NewSwarmServiceClient ¶
func NewSwarmServiceClient( c *client.Client, filterLabel, scrapNetLabel string, serviceNamePrefix string, includeAddressInNodeInfo bool, logger *log.Logger) *SwarmServiceClient
NewSwarmServiceClient creates a `SwarmServiceClient`
func (SwarmServiceClient) GetNodeInfo ¶
func (c SwarmServiceClient) GetNodeInfo(ctx context.Context, ss SwarmService) (NodeIPSet, error)
GetNodeInfo returns node info for swarm service
func (SwarmServiceClient) SwarmServiceInspect ¶
func (c SwarmServiceClient) SwarmServiceInspect(ctx context.Context, serviceID string) (*SwarmService, error)
SwarmServiceInspect returns `SwarmService` from its ID Returns nil when service doesnt not have the `FilterLabel` When `includeNodeIPInfo` is true, return node info as well
func (SwarmServiceClient) SwarmServiceList ¶
func (c SwarmServiceClient) SwarmServiceList(ctx context.Context) ([]SwarmService, error)
SwarmServiceList returns a list of services
func (SwarmServiceClient) SwarmServiceRunning ¶
func (c SwarmServiceClient) SwarmServiceRunning(ctx context.Context, serviceID string) (bool, error)
SwarmServiceRunning returns true if service is running
type SwarmServiceInspector ¶
type SwarmServiceInspector interface { SwarmServiceInspect(ctx context.Context, serviceID string) (*SwarmService, error) SwarmServiceList(ctx context.Context) ([]SwarmService, error) GetNodeInfo(ctx context.Context, ss SwarmService) (NodeIPSet, error) SwarmServiceRunning(ctx context.Context, serviceID string) (bool, error) }
SwarmServiceInspector is able to inspect services
type SwarmServiceListener ¶
type SwarmServiceListener struct {
// contains filtered or unexported fields
}
SwarmServiceListener listens for docker service events
func NewSwarmServiceListener ¶
func NewSwarmServiceListener(c *client.Client, logger *log.Logger) *SwarmServiceListener
NewSwarmServiceListener creates a `SwarmServiceListener`
func (SwarmServiceListener) ListenForServiceEvents ¶
func (s SwarmServiceListener) ListenForServiceEvents(eventChan chan<- Event)
ListenForServiceEvents listens for events and places them on channels
type SwarmServiceListening ¶
type SwarmServiceListening interface {
ListenForServiceEvents(chan<- Event)
}
SwarmServiceListening listens for service events
type SwarmServiceMini ¶
type SwarmServiceMini struct { ID string Name string Labels map[string]string Global bool Replicas uint64 ContainerImage string NodeInfo NodeIPSet }
SwarmServiceMini is a optimized version of `SwarmService` for caching purposes
func MinifySwarmService ¶
func MinifySwarmService(ss SwarmService, ignoreKey string, includeKey string) SwarmServiceMini
MinifySwarmService minifies `SwarmService` only labels prefixed with `com.df.` will be used `ignoreKey` wll be ignored from labels `includeKey` will be included
func (SwarmServiceMini) Equal ¶
func (ssm SwarmServiceMini) Equal(other SwarmServiceMini) bool
Equal returns when SwarmServiceMini is equal to `other`
type SwarmServicePoller ¶
type SwarmServicePoller struct { SSClient SwarmServiceInspector SSCache SwarmServiceCacher PollingInterval int IncludeNodeInfo bool MinifyFunc func(SwarmService) SwarmServiceMini Log *log.Logger }
SwarmServicePoller implements `SwarmServicePoller`
func NewSwarmServicePoller ¶
func NewSwarmServicePoller( ssClient SwarmServiceInspector, ssCache SwarmServiceCacher, pollingInterval int, includeNodeInfo bool, minifyFunc func(SwarmService) SwarmServiceMini, log *log.Logger, ) *SwarmServicePoller
NewSwarmServicePoller creates a new `SwarmServicePoller`
func (SwarmServicePoller) Run ¶
func (s SwarmServicePoller) Run( eventChan chan<- Event)
Run starts poller and places events onto `eventChan`
type SwarmServicePolling ¶
type SwarmServicePolling interface {
Run(eventChan chan<- Event)
}
SwarmServicePolling provides an interface for polling service changes