lb

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2016 License: BSD-2-Clause Imports: 11 Imported by: 0

Documentation

Overview

package lb provides an abstraction around creating load balancers.

Index

Constants

View Source
const AppTag = "App"

Variables

This section is empty.

Functions

This section is empty.

Types

type CNAMEManager

type CNAMEManager struct {
	Manager
	Nameserver
}

CNAMEManager is an implementation of the Manager interface that creates CNAME records for the LoadBalancer after its created.

func WithCNAME

func WithCNAME(m Manager, n Nameserver) *CNAMEManager

WithCNAME wraps a Manager to create CNAME records for the LoadBalancer using a Nameserver.

func (*CNAMEManager) CreateLoadBalancer

func (m *CNAMEManager) CreateLoadBalancer(ctx context.Context, opts CreateLoadBalancerOpts) (*LoadBalancer, error)

CreateLoadBalancer will create the LoadBalancer using the underlying manager, then create a CNAME record pointed at the LoadBalancers DNSName. The CNAME will be pulled from the `Service` tag if provided.

func (*CNAMEManager) DestroyLoadBalancer

func (m *CNAMEManager) DestroyLoadBalancer(ctx context.Context, lb *LoadBalancer) error

DestroyLoadBalancer destroys an ELB, then removes any CNAMEs that were pointed at that ELB.

func (*CNAMEManager) RemoveCNAME

func (m *CNAMEManager) RemoveCNAME(ctx context.Context, lb *LoadBalancer) error

func (*CNAMEManager) RemoveCNAMEs

func (m *CNAMEManager) RemoveCNAMEs(ctx context.Context, tags map[string]string) error

type CreateLoadBalancerOpts

type CreateLoadBalancerOpts struct {
	// An arbitrary list of tags to assign to the load balancer.
	Tags map[string]string

	// True if the load balancer should be publicy exposed.
	External bool

	// The SSL Certificate
	SSLCert string
}

CreateLoadBalancerOpts are options that can be provided when creating a LoadBalancer.

type DBPortAllocator

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

DBPortAllocator implements the portAllocator interface backed by database/sql.

func NewDBPortAllocator

func NewDBPortAllocator(db *sql.DB) *DBPortAllocator

NewDBPortAllocator returns a new DBPortAllocator uses the given database connection to perform queries.

func (*DBPortAllocator) Get

func (a *DBPortAllocator) Get() (int64, error)

Get finds an existing allocated port from the `ports` table. If one is not allocated for the process, it allocates one and returns it.

func (*DBPortAllocator) Put

func (a *DBPortAllocator) Put(port int64) error

Put releases any allocated port for the process, returning it back to the pool.

type ELBManager

type ELBManager struct {
	// The ID of the security group to assign to internal load balancers.
	InternalSecurityGroupID string

	// The ID of the security group to assign to external load balancers.
	ExternalSecurityGroupID string

	// The Subnet IDs to assign when creating internal load balancers.
	InternalSubnetIDs []string

	// The Subnet IDs to assign when creating external load balancers.
	ExternalSubnetIDs []string

	// Ports is the PortAllocator used to allocate ports to new load
	// balancers.
	Ports PortAllocator
	// contains filtered or unexported fields
}

ELBManager is an implementation of the Manager interface that creates Elastic Load Balancers.

func NewELBManager

func NewELBManager(p client.ConfigProvider) *ELBManager

NewELBManager returns a new ELBManager backed by the aws config.

func (*ELBManager) CreateLoadBalancer

func (m *ELBManager) CreateLoadBalancer(ctx context.Context, o CreateLoadBalancerOpts) (*LoadBalancer, error)

CreateLoadBalancer creates a new ELB:

* The ELB is created and connection draining is enabled. * An internal DNS CNAME record is created, pointing the the DNSName of the ELB.

func (*ELBManager) DestroyLoadBalancer

func (m *ELBManager) DestroyLoadBalancer(ctx context.Context, lb *LoadBalancer) error

DestroyLoadBalancer destroys an ELB.

func (*ELBManager) LoadBalancers

func (m *ELBManager) LoadBalancers(ctx context.Context, tags map[string]string) ([]*LoadBalancer, error)

LoadBalancers returns all load balancers. If tags are provided, then the resulting load balancers will be filtered to only those containing the provided tags.

func (*ELBManager) UpdateLoadBalancer

func (m *ELBManager) UpdateLoadBalancer(ctx context.Context, opts UpdateLoadBalancerOpts) error

type LoadBalancer

type LoadBalancer struct {
	// The name of the load balancer.
	Name string

	// DNSName is the DNS name for the load balancer. CNAME records can be
	// created that point to this location.
	DNSName string

	// True if the load balancer is exposed externally.
	External bool

	// The SSL Certificate to associate with the load balancer.
	SSLCert string

	// InstancePort is the port that this load balancer forwards requests to
	// on the host.
	InstancePort int64

	// Tags contain the tags attached to the LoadBalancer
	Tags map[string]string
}

LoadBalancer represents a load balancer.

type LoggedManager

type LoggedManager struct {
	Manager
}

LoggedManager is an implementation of the Manager interface that logs when LoadBalancers are created and destroyed.

func WithLogging

func WithLogging(m Manager) *LoggedManager

WithLogging wraps the manager with logging.

func (*LoggedManager) CreateLoadBalancer

func (m *LoggedManager) CreateLoadBalancer(ctx context.Context, o CreateLoadBalancerOpts) (*LoadBalancer, error)

func (*LoggedManager) DestroyLoadBalancer

func (m *LoggedManager) DestroyLoadBalancer(ctx context.Context, lb *LoadBalancer) error

type Manager

type Manager interface {
	// CreateLoadBalancer creates a new LoadBalancer with the given options.
	CreateLoadBalancer(context.Context, CreateLoadBalancerOpts) (*LoadBalancer, error)

	// UpdateLoadBalancer updates an existing load balancer.
	UpdateLoadBalancer(context.Context, UpdateLoadBalancerOpts) error

	// DestroyLoadBalancer destroys a load balancer by name.
	DestroyLoadBalancer(ctx context.Context, lb *LoadBalancer) error

	// LoadBalancers returns a list of LoadBalancers, optionally provide
	// tags to filter by.
	LoadBalancers(ctx context.Context, tags map[string]string) ([]*LoadBalancer, error)
}

Manager is our API interface for interacting with LoadBalancers.

type Nameserver

type Nameserver interface {
	// CNAME creates a cname record pointed at record.
	CreateCNAME(cname, record string) error
	DeleteCNAME(cname, record string) error
}

Nameserver represents a service for creating dns records.

type PortAllocator

type PortAllocator interface {
	// Get allocates a port from the pool.
	Get() (int64, error)
	// Put releases the allocated port back to the pool.
	Put(port int64) error
}

PortAllocator is an interface that allows us to allocate a port for an ELB.

Because ELB can only forward to a single host port, we have to manage a list of host ports that we allocate to load balacers, to avoid any collisions.

type Route53Nameserver

type Route53Nameserver struct {
	// The Hosted Zone ID that records will be created under.
	ZoneID string
	// contains filtered or unexported fields
}

Route53Nameserver is an implementation of the nameserver interface backed by route53.

func NewRoute53Nameserver

func NewRoute53Nameserver(p client.ConfigProvider) *Route53Nameserver

NewRoute53Nameserver returns a Route53Nameserver instance with a configured route53 client.

func (*Route53Nameserver) CreateCNAME

func (n *Route53Nameserver) CreateCNAME(cname, record string) error

CreateCNAME creates a CNAME record under the HostedZone specified by ZoneID.

func (*Route53Nameserver) DeleteCNAME

func (n *Route53Nameserver) DeleteCNAME(cname, record string) error

DeleteCNAME deletes the CNAME of an ELB from the internal zone

type UpdateLoadBalancerOpts

type UpdateLoadBalancerOpts struct {
	// The name of the load balancer.
	Name string

	// The SSL Certificate
	SSLCert *string
}

UpdateLoadBalancerOpts are options that can be provided when updating an existing load balancer.

Jump to

Keyboard shortcuts

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