targetsync

package module
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2019 License: MIT Imports: 19 Imported by: 0

README

targetsync Go Report Card GoDoc Build Status Docker Repository on Quay

Daemon for syncing targets from consul to AWS target groups

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AWSConfig

type AWSConfig struct {
	TargetGroupARN   string `yaml:"target_group_arn"`
	AvailabilityZone string `yaml:"availability_zone"`
}

AWSConfig holds the configuration for the aws destination

type AWSTargetGroup

type AWSTargetGroup struct {
	// contains filtered or unexported fields
}

AWSTargetGroup is a TargetDestination implementation for AWS target groups

func NewAWSTargetGroup

func NewAWSTargetGroup(cfg *AWSConfig) (*AWSTargetGroup, error)

NewAWSTargetGroup returns a new AWS target group destination

func (*AWSTargetGroup) AddTargets

func (tg *AWSTargetGroup) AddTargets(ctx context.Context, targets []*Target) error

AddTargets simply adds the targets described

func (*AWSTargetGroup) GetTargets

func (tg *AWSTargetGroup) GetTargets(ctx context.Context) ([]*Target, error)

GetTargets returns the current set of targets at the destination

func (*AWSTargetGroup) RemoveTargets

func (tg *AWSTargetGroup) RemoveTargets(ctx context.Context, targets []*Target) error

RemoveTargets simply removes the targets described

func (*AWSTargetGroup) TargetToTargetDescription

func (tg *AWSTargetGroup) TargetToTargetDescription(targets []*Target) []*elbv2.TargetDescription

TargetToTargetDescription translates the `Target` struct into an ec2 `TargetDescription`

type Config

type Config struct {
	ConsulConfig       `yaml:"consul"`
	AWSConfig          `yaml:"aws"`
	K8sEndpointsConfig `yaml:"k8s_enpoints"`

	SyncConfig `yaml:"syncer"`
}

Config for the targetsync

func ConfigFromFile

func ConfigFromFile(path string) (*Config, error)

ConfigFromFile Loads a config file from `path`

func (*Config) Validate

func (c *Config) Validate() error

type ConsulConfig

type ConsulConfig struct {
	ClientConfig *consulApi.Config `yaml:"client"`
	ServiceName  string            `yaml:"service_name"`
	Tag          string            `yaml:"tag"`
}

ConsulConfig holds the configuration for the consul source

type ConsulSource

type ConsulSource struct {
	// contains filtered or unexported fields
}

ConsulSource is an implementation for talkint to consul for both `TargetSource` and `Locker`

func NewConsulSource

func NewConsulSource(cfg *ConsulConfig) (*ConsulSource, error)

NewConsulSource returns a new ConsulSource

func (*ConsulSource) Lock

func (s *ConsulSource) Lock(ctx context.Context, opts *LockOptions) (<-chan bool, error)

Lock to implement the Locker interface

func (*ConsulSource) Subscribe

func (s *ConsulSource) Subscribe(ctx context.Context) (chan []*Target, error)

Subscribe to implement the `TargetSource` interface

type K8sConfig

type K8sConfig struct {
	InCluster      bool   `yaml:"in_cluster"`
	KubeConfigPath string `yaml:"kubeconfig_path"`
}

type K8sEndpointsConfig

type K8sEndpointsConfig struct {
	K8sConfig `yaml:"k8s"`
	Name      string `yaml:"name"`
	Namespace string `yaml:"namespace"`
	Port      int    `yaml:"port"`
}

type K8sEndpointsSource

type K8sEndpointsSource struct {
	// contains filtered or unexported fields
}

func NewK8sEndpointsSource

func NewK8sEndpointsSource(cfg *K8sEndpointsConfig) (*K8sEndpointsSource, error)

func (*K8sEndpointsSource) Lock

func (s *K8sEndpointsSource) Lock(ctx context.Context, opts *LockOptions) (<-chan bool, error)

func (*K8sEndpointsSource) Subscribe

func (s *K8sEndpointsSource) Subscribe(ctx context.Context) (chan []*Target, error)

type LockOptions

type LockOptions struct {
	Key string        `yaml:"key"`
	TTL time.Duration `yaml:"ttl"`
}

LockOptions holds the options for locking/leader-election

type Locker

type Locker interface {
	// Lock will acquire the lock defined in `LockOptions` and return a channel
	// which will respond with whether we are the leader
	Lock(context.Context, *LockOptions) (<-chan bool, error)
}

Locker is an interface for locking/leader-election

type SyncConfig

type SyncConfig struct {
	LockOptions `yaml:"lock_options"`

	RemoveDelay time.Duration `yaml:"remove_delay"`
}

SyncConfig holds options for the Syncer

func (SyncConfig) Validate

func (c SyncConfig) Validate() error

type Syncer

type Syncer struct {
	Config    *SyncConfig
	LocalAddr string
	Locker    Locker
	Src       TargetSource
	Dst       TargetDestination
	Started   bool
}

Syncer is the struct that uses the various interfaces to actually do the sync TODO: metrics

func (*Syncer) Run

func (s *Syncer) Run(ctx context.Context) error

Run is the main method for the syncer. This is responsible for calling runLeader when the lock is held

type Target

type Target struct {
	IP   string
	Port int
}

Target represents a single IP+Port pair

func (*Target) Key

func (t *Target) Key() string

Key returns a unique key identifying this specific target

type TargetDestination

type TargetDestination interface {
	// GetTargets returns the current set of targets at the destination
	GetTargets(context.Context) ([]*Target, error)
	// AddTargets simply adds the targets described
	AddTargets(context.Context, []*Target) error
	// RemoveTargets simply removes the targets described
	RemoveTargets(context.Context, []*Target) error
}

TargetDestination is a place to apply targets to (e.g. TargetGroup)

type TargetSource

type TargetSource interface {
	Subscribe(context.Context) (chan []*Target, error)
}

TargetSource is an interface for getting targets for a given config TODO: plugin etc.

type TargetSourceLocker

type TargetSourceLocker interface {
	Locker
	TargetSource
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL