loadbalance

package
v1.4.4 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ServiceAnnotationLoadBalancerEipIds is the annotation which specifies a list of eip ids.
	// The ids in list are separated by ',', e.g. "eip-j38f2h3h,eip-ornz2xq7". And this annotation should
	// NOT be used with ServiceAnnotationLoadBalancerVxnetId. Please make sure there is one and only one
	// of them being set
	ServiceAnnotationLoadBalancerEipIds = "service.beta.kubernetes.io/qingcloud-load-balancer-eip-ids"

	// ServiceAnnotationLoadBalancerVxnetId is the annotation which indicates the very vxnet where load
	// balancer resides. This annotation should NOT be used when ServiceAnnotationLoadBalancerEipIds is
	// set.
	ServiceAnnotationLoadBalancerVxnetID         = "service.beta.kubernetes.io/qingcloud-load-balancer-vxnet-id"
	ServiceAnnotationLoadBalancerInternalIP      = "service.beta.kubernetes.io/qingcloud-load-balancer-internal-ip"
	ServiceAnnotationLoadBalancerInternalReuseID = "service.beta.kubernetes.io/qingcloud-load-balancer-reuse-id"
	// ServiceAnnotationLoadBalancerType is the annotation used on the
	// service to indicate that we want a qingcloud loadBalancer type.
	// value "0" means the LB can max support 5000 concurrency connections, it's default type.
	// value "1" means the LB can max support 20000 concurrency connections.
	// value "2" means the LB can max support 40000 concurrency connections.
	// value "3" means the LB can max support 100000 concurrency connections.
	// value "4" means the LB can max support 200000 concurrency connections.
	// value "5" means the LB can max support 500000 concurrency connections.
	ServiceAnnotationLoadBalancerType = "service.beta.kubernetes.io/qingcloud-load-balancer-type"

	// 	ServiceAnnotationLoadBalancerNetworkType represents the network mode of lb, one of "public" or "internal", public is the default mode which needs at least an eip
	ServiceAnnotationLoadBalancerNetworkType = "service.beta.kubernetes.io/qingcloud-load-balancer-network-type"
	// ServiceAnnotationLoadBalancerID is needed when user want to use exsiting lb
	ServiceAnnotationLoadBalancerID = "service.beta.kubernetes.io/qingcloud-load-balancer-id"
	// ServiceAnnotationLoadBalancerPolicy is usd to specify EIP use strategy
	// reuse represent the EIP can be shared with other service which has no port conflict
	// exclusive is the default value, means every service has its own EIP
	ServiceAnnotationLoadBalancerPolicy = "service.beta.kubernetes.io/qingcloud-load-balancer-eip-strategy"

	ServiceAnnotationLoadBalancerEipSource = "service.beta.kubernetes.io/qingcloud-load-balancer-eip-source"

	//ReuseExistingLB  use existing loadbalancer on the cloud
	ReuseExistingLB Policy = "reuse-lb"
	// Shared represent the EIP can be shared with other service which has no port conflict
	Shared Policy = "reuse"
	// Exclusive is the default value, means every service has its own EIP
	Exclusive Policy = "exclusive"

	ManualSet                 EIPAllocateSource = "manual"
	UseAvailableOrAllocateOne EIPAllocateSource = "auto"
	UseAvailableOnly          EIPAllocateSource = "use-available"
	AllocateOnly              EIPAllocateSource = "allocate"

	NetworkModePublic   string = "public"
	NetworkModeInternal        = "internal"
)

Variables

View Source
var (
	ErrorListenerPortConflict = fmt.Errorf("Port has been occupied")
	ErrorSharedButNoName      = fmt.Errorf("If you want to reuse an eip , you must specify the name of each port in service")
)

Functions

func GetListenerPrefix

func GetListenerPrefix(service *corev1.Service) string

func GetLoadBalancerName

func GetLoadBalancerName(clusterName string, service *corev1.Service, lb executor.QingCloudLoadBalancerExecutor) string

GetLoadBalancerName generate lb name for each service. The name of a service is fixed and predictable

Types

type AnnotaionConfig added in v1.4.2

type AnnotaionConfig struct {
	ScaleType   int
	NetworkType string
	EipIDs      []string
	EIPAllocateSource
	Policy
	InternalIP      string
	InternalReuseID string
	VxnetID         string
	ReuseLBID       string
}

func ParseAnnotation added in v1.4.2

func ParseAnnotation(annotation map[string]string, skipCheck bool) (AnnotaionConfig, error)

type Backend

type Backend struct {
	Name   string
	Spec   BackendSpec
	Status *qcservice.LoadBalancerBackend
	// contains filtered or unexported fields
}

func (*Backend) Create added in v1.3.2

func (b *Backend) Create() error

func (*Backend) DeleteBackend

func (b *Backend) DeleteBackend() error

func (*Backend) LoadQcBackend

func (b *Backend) LoadQcBackend() error

func (*Backend) NeedUpdate

func (b *Backend) NeedUpdate() bool

func (*Backend) UpdateBackend

func (b *Backend) UpdateBackend() error

type BackendList

type BackendList struct {
	Listener *Listener
	Items    []*Backend
	// contains filtered or unexported fields
}

func NewBackendList

func NewBackendList(lb *LoadBalancer, listener *Listener) *BackendList

func (*BackendList) CreateBackends

func (b *BackendList) CreateBackends() error

func (*BackendList) LoadAndGetUselessBackends added in v1.3.2

func (b *BackendList) LoadAndGetUselessBackends() ([]string, error)

type BackendSpec

type BackendSpec struct {
	Listener   *Listener
	Weight     int
	Port       int
	InstanceID string
}

type EIPAllocateSource

type EIPAllocateSource string

type LisenerSpec

type LisenerSpec struct {
	PrefixName   string
	Name         string
	ListenerPort int
	BalanceMode  string
	Protocol     string
	NodePort     int
	// contains filtered or unexported fields
}

type Listener

type Listener struct {
	LisenerSpec
	Status *qcservice.LoadBalancerListener
	// contains filtered or unexported fields
}

Listener is

func NewListener

func NewListener(lb *LoadBalancer, port int) (*Listener, error)

func (*Listener) CheckPortConflict

func (l *Listener) CheckPortConflict() (bool, error)

func (*Listener) CreateQingCloudListener

func (l *Listener) CreateQingCloudListener() error

func (*Listener) CreateQingCloudListenerWithBackends

func (l *Listener) CreateQingCloudListenerWithBackends() error

func (*Listener) DeleteQingCloudListener

func (l *Listener) DeleteQingCloudListener() error

func (*Listener) GetBackends

func (l *Listener) GetBackends() *BackendList

func (*Listener) LoadQcListener

func (l *Listener) LoadQcListener() error

LoadQcListener get real lb in qingcloud

func (*Listener) NeedUpdate

func (l *Listener) NeedUpdate() bool

func (*Listener) UpdateBackends added in v1.3.2

func (l *Listener) UpdateBackends() error

func (*Listener) UpdateQingCloudListener

func (l *Listener) UpdateQingCloudListener() error

type LoadBalancer

type LoadBalancer struct {
	LoadBalancerSpec
	Status LoadBalancerStatus
	// contains filtered or unexported fields
}

func NewLoadBalancer

func NewLoadBalancer(opt *NewLoadBalancerOption) (*LoadBalancer, error)

NewLoadBalancer create loadbalancer in memory, not in cloud, call 'CreateQingCloudLB' to create a real loadbalancer in qingcloud

func (*LoadBalancer) ClearNoUseListener

func (l *LoadBalancer) ClearNoUseListener() error

ClearNoUseListener delete uneccassary listeners in qingcloud, used when service ports changed

func (*LoadBalancer) CreateQingCloudLB

func (l *LoadBalancer) CreateQingCloudLB() error

CreateQingCloudLB do create a lb in qingcloud

func (*LoadBalancer) DeleteQingCloudLB

func (l *LoadBalancer) DeleteQingCloudLB() error

func (*LoadBalancer) EnsureEIP

func (l *LoadBalancer) EnsureEIP() error

func (*LoadBalancer) EnsureLoadBalancerSecurityGroup

func (l *LoadBalancer) EnsureLoadBalancerSecurityGroup() error

EnsureLoadBalancerSecurityGroup will create a SecurityGroup if not exists

func (*LoadBalancer) EnsureQingCloudLB added in v1.3.2

func (l *LoadBalancer) EnsureQingCloudLB() error

func (*LoadBalancer) GenerateK8sLoadBalancer

func (l *LoadBalancer) GenerateK8sLoadBalancer() error

GenerateK8sLoadBalancer get a corev1.LoadBalancerStatus for k8s

func (*LoadBalancer) GetListeners

func (l *LoadBalancer) GetListeners() []*Listener

GetListeners return listeners of this service

func (*LoadBalancer) GetNodesInstanceIDs

func (l *LoadBalancer) GetNodesInstanceIDs() []string

GetNodesInstanceIDs return resource ids for listener to create backends

func (*LoadBalancer) GetService

func (l *LoadBalancer) GetService() *corev1.Service

GetService return service of this loadbalancer

func (*LoadBalancer) LoadListeners

func (l *LoadBalancer) LoadListeners() error

LoadListeners use should mannually load listener because sometimes we do not need load entire topology. For example, deletion

func (*LoadBalancer) LoadQcLoadBalancer

func (l *LoadBalancer) LoadQcLoadBalancer() (err error)

LoadQcLoadBalancer use qingcloud api to get lb in cloud, return err if not found

func (*LoadBalancer) LoadSecurityGroup

func (l *LoadBalancer) LoadSecurityGroup() error

LoadSecurityGroup read SecurityGroup in qingcloud related with this service

func (*LoadBalancer) NeedChangeIP

func (l *LoadBalancer) NeedChangeIP() (yes bool, toadd []string, todelete []string)

func (*LoadBalancer) NeedResize

func (l *LoadBalancer) NeedResize() bool

NeedResize tell us if we should resize the lb in qingcloud

func (*LoadBalancer) NeedUpdate

func (l *LoadBalancer) NeedUpdate() bool

NeedUpdate tell us whether an update to loadbalancer is needed

func (*LoadBalancer) UpdateQingCloudLB

func (l *LoadBalancer) UpdateQingCloudLB() error

UpdateQingCloudLB update some attrs of qingcloud lb

type LoadBalancerSpec

type LoadBalancerSpec struct {
	TCPPorts  []int
	NodePorts []int
	Nodes     []*corev1.Node
	Name      string

	AnnotaionConfig
	// contains filtered or unexported fields
}

type LoadBalancerStatus

type LoadBalancerStatus struct {
	K8sLoadBalancerStatus *corev1.LoadBalancerStatus
	QcLoadBalancer        *qcservice.LoadBalancer
	QcSecurityGroup       *qcservice.SecurityGroup
}

type NewLoadBalancerOption

type NewLoadBalancerOption struct {
	EipHelper  eip.EIPHelper
	LbExecutor executor.QingCloudLoadBalancerExecutor
	SgExecutor executor.QingCloudSecurityGroupExecutor
	NodeLister corev1lister.NodeLister

	K8sNodes     []*corev1.Node
	K8sService   *corev1.Service
	Context      context.Context
	ClusterName  string
	SkipCheck    bool
	DefaultVxnet string
}

type Policy added in v1.4.2

type Policy string

Policy is the type representing lb shared policy

Jump to

Keyboard shortcuts

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