loadbalancers

package
v0.0.0-...-7ce7f99 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2016 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// DefaultHost is the host used if none is specified. It is a valid value
	// for the "Host" field recognized by GCE.
	DefaultHost = "*"

	// DefaultPath is the path used if none is specified. It is a valid path
	// recognized by GCE.
	DefaultPath = "/*"
)

Variables

This section is empty.

Functions

func GetLBAnnotations

func GetLBAnnotations(l7 *L7, existing map[string]string, backendPool backends.BackendPool) map[string]string

GetLBAnnotations returns the annotations of an l7. This includes it's current status.

Types

type FakeLoadBalancers

type FakeLoadBalancers struct {
	Fw []*compute.ForwardingRule
	Um []*compute.UrlMap
	Tp []*compute.TargetHttpProxy
	// contains filtered or unexported fields
}

FakeLoadBalancers is a type that fakes out the loadbalancer interface.

func NewFakeLoadBalancers

func NewFakeLoadBalancers(name string) *FakeLoadBalancers

NewFakeLoadBalancers creates a fake cloud client. Name is the name inserted into the selfLink of the associated resources for testing. eg: forwardingRule.SelfLink == k8-fw-name.

func (*FakeLoadBalancers) CheckURLMap

func (f *FakeLoadBalancers) CheckURLMap(t *testing.T, l7 *L7, expectedMap map[string]utils.FakeIngressRuleValueMap)

CheckURLMap check a url-map for the expected rules.

func (*FakeLoadBalancers) CreateGlobalForwardingRule

func (f *FakeLoadBalancers) CreateGlobalForwardingRule(proxy *compute.TargetHttpProxy, name string, portRange string) (*compute.ForwardingRule, error)

CreateGlobalForwardingRule fakes forwarding rule creation.

func (*FakeLoadBalancers) CreateTargetHttpProxy

func (f *FakeLoadBalancers) CreateTargetHttpProxy(urlMap *compute.UrlMap, name string) (*compute.TargetHttpProxy, error)

CreateTargetHttpProxy fakes creating a target http proxy.

func (*FakeLoadBalancers) CreateUrlMap

func (f *FakeLoadBalancers) CreateUrlMap(backend *compute.BackendService, name string) (*compute.UrlMap, error)

CreateUrlMap fakes url-map creation.

func (*FakeLoadBalancers) DeleteGlobalForwardingRule

func (f *FakeLoadBalancers) DeleteGlobalForwardingRule(name string) error

DeleteGlobalForwardingRule fakes deleting a global forwarding rule.

func (*FakeLoadBalancers) DeleteTargetHttpProxy

func (f *FakeLoadBalancers) DeleteTargetHttpProxy(name string) error

DeleteTargetHttpProxy fakes deleting a target http proxy.

func (*FakeLoadBalancers) DeleteUrlMap

func (f *FakeLoadBalancers) DeleteUrlMap(name string) error

DeleteUrlMap fakes url-map deletion.

func (*FakeLoadBalancers) GetGlobalForwardingRule

func (f *FakeLoadBalancers) GetGlobalForwardingRule(name string) (*compute.ForwardingRule, error)

GetGlobalForwardingRule returns a fake forwarding rule.

func (*FakeLoadBalancers) GetTargetHttpProxy

func (f *FakeLoadBalancers) GetTargetHttpProxy(name string) (*compute.TargetHttpProxy, error)

GetTargetHttpProxy fakes getting target http proxies from the cloud.

func (*FakeLoadBalancers) GetUrlMap

func (f *FakeLoadBalancers) GetUrlMap(name string) (*compute.UrlMap, error)

GetUrlMap fakes getting url maps from the cloud.

func (*FakeLoadBalancers) SetProxyForGlobalForwardingRule

func (f *FakeLoadBalancers) SetProxyForGlobalForwardingRule(fw *compute.ForwardingRule, proxy *compute.TargetHttpProxy) error

SetProxyForGlobalForwardingRule fakes setting a global forwarding rule.

func (*FakeLoadBalancers) SetUrlMapForTargetHttpProxy

func (f *FakeLoadBalancers) SetUrlMapForTargetHttpProxy(proxy *compute.TargetHttpProxy, urlMap *compute.UrlMap) error

SetUrlMapForTargetHttpProxy fakes setting an url-map for a target http proxy.

func (*FakeLoadBalancers) String

func (f *FakeLoadBalancers) String() string

String is the string method for FakeLoadBalancers.

func (*FakeLoadBalancers) UpdateUrlMap

func (f *FakeLoadBalancers) UpdateUrlMap(urlMap *compute.UrlMap) (*compute.UrlMap, error)

UpdateUrlMap fakes updating url-maps.

type L7

type L7 struct {
	Name string
	// contains filtered or unexported fields
}

L7 represents a single L7 loadbalancer.

func (*L7) Cleanup

func (l *L7) Cleanup() error

Cleanup deletes resources specific to this l7 in the right order. forwarding rule -> target proxy -> url map This leaves backends and health checks, which are shared across loadbalancers.

func (*L7) GetIP

func (l *L7) GetIP() string

GetIP returns the ip associated with the forwarding rule for this l7.

func (*L7) UpdateUrlMap

func (l *L7) UpdateUrlMap(ingressRules utils.GCEURLMap) error

UpdateUrlMap translates the given hostname: endpoint->port mapping into a gce url map.

HostRule: Conceptually contains all PathRules for a given host. PathMatcher: Associates a path rule with a host rule. Mostly an optimization. PathRule: Maps a single path regex to a backend.

The GCE url map allows multiple hosts to share url->backend mappings without duplication, eg:

Host: foo(PathMatcher1), bar(PathMatcher1,2)
PathMatcher1:
  /a -> b1
  /b -> b2
PathMatcher2:
  /c -> b1

This leads to a lot of complexity in the common case, where all we want is a mapping of host->{/path: backend}.

Consider some alternatives:

  1. Using a single backend per PathMatcher: Host: foo(PathMatcher1,3) bar(PathMatcher1,2,3) PathMatcher1: /a -> b1 PathMatcher2: /c -> b1 PathMatcher3: /b -> b2
  2. Using a single host per PathMatcher: Host: foo(PathMatcher1) PathMatcher1: /a -> b1 /b -> b2 Host: bar(PathMatcher2) PathMatcher2: /a -> b1 /b -> b2 /c -> b1

In the context of kubernetes services, 2 makes more sense, because we rarely want to lookup backends (service:nodeport). When a service is deleted, we need to find all host PathMatchers that have the backend and remove the mapping. When a new path is added to a host (happens more frequently than service deletion) we just need to lookup the 1 pathmatcher of the host.

type L7s

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

L7s implements LoadBalancerPool.

func (*L7s) Add

func (l *L7s) Add(name string) (err error)

Add gets or creates a loadbalancer. If the loadbalancer already exists, it checks that its edges are valid.

func (*L7s) Delete

func (l *L7s) Delete(name string) error

Delete deletes a loadbalancer by name.

func (*L7s) GC

func (l *L7s) GC(names []string) error

GC garbage collects loadbalancers not in the input list.

func (*L7s) Get

func (l *L7s) Get(name string) (*L7, error)

Get returns the loadbalancer by name.

func (*L7s) Shutdown

func (l *L7s) Shutdown() error

Shutdown logs whether or not the pool is empty.

func (*L7s) Sync

func (l *L7s) Sync(names []string) error

Sync loadbalancers with the given names.

type LoadBalancerPool

type LoadBalancerPool interface {
	Get(name string) (*L7, error)
	Add(name string) error
	Delete(name string) error
	Sync(names []string) error
	GC(names []string) error
	Shutdown() error
}

LoadBalancerPool is an interface to manage the cloud resources associated with a gce loadbalancer.

func NewLoadBalancerPool

func NewLoadBalancerPool(
	cloud LoadBalancers,
	defaultBackendPool backends.BackendPool,
	defaultBackendNodePort int64, namer utils.Namer) LoadBalancerPool

NewLoadBalancerPool returns a new loadbalancer pool.

  • cloud: implements LoadBalancers. Used to sync L7 loadbalancer resources with the cloud.
  • defaultBackendPool: a BackendPool used to manage the GCE BackendService for the default backend.
  • defaultBackendNodePort: The nodePort of the Kubernetes service representing the default backend.

type LoadBalancers

type LoadBalancers interface {
	// Forwarding Rules
	GetGlobalForwardingRule(name string) (*compute.ForwardingRule, error)
	CreateGlobalForwardingRule(proxy *compute.TargetHttpProxy, name string, portRange string) (*compute.ForwardingRule, error)
	DeleteGlobalForwardingRule(name string) error
	SetProxyForGlobalForwardingRule(fw *compute.ForwardingRule, proxy *compute.TargetHttpProxy) error

	// UrlMaps
	GetUrlMap(name string) (*compute.UrlMap, error)
	CreateUrlMap(backend *compute.BackendService, name string) (*compute.UrlMap, error)
	UpdateUrlMap(urlMap *compute.UrlMap) (*compute.UrlMap, error)
	DeleteUrlMap(name string) error

	// TargetProxies
	GetTargetHttpProxy(name string) (*compute.TargetHttpProxy, error)
	CreateTargetHttpProxy(urlMap *compute.UrlMap, name string) (*compute.TargetHttpProxy, error)
	DeleteTargetHttpProxy(name string) error
	SetUrlMapForTargetHttpProxy(proxy *compute.TargetHttpProxy, urlMap *compute.UrlMap) error
}

LoadBalancers is an interface for managing all the gce resources needed by L7 loadbalancers. We don't have individual pools for each of these resources because none of them are usable (or acquirable) stand-alone, unlinke backends and instance groups. The dependency graph: ForwardingRule -> UrlMaps -> TargetProxies

Jump to

Keyboard shortcuts

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