util

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2020 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 8 more Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultRetryInterval is the default minimum delay for retries
	DefaultRetryInterval = 10 * time.Second

	// DefaultEnsurePeriod is the default minimum interval for ensureLoadBalancer and ensureBackendRecord
	DefaultEnsurePeriod = 1 * time.Minute
)

Variables

This section is empty.

Functions

func AddBackendCondition

func AddBackendCondition(beStatus *lbcfapi.BackendRecordStatus, expectCondition lbcfapi.BackendRecordCondition)

AddBackendCondition is an helper function to add specific BackendRecord condition into BackendRecord.status. If a condition with same type exists, the existing one will be overwritten, otherwise, a new condition will be inserted.

func AddLBCondition

func AddLBCondition(lbStatus *lbcfapi.LoadBalancerStatus, expectCondition lbcfapi.LoadBalancerCondition)

AddLBCondition is an helper function to add specific LoadBalancer condition into LoadBalancer.status. If a condition with same type exists, the existing one will be overwritten, otherwise, a new condition will be inserted.

func BackendRegistered

func BackendRegistered(backend *lbcfapi.BackendRecord) bool

BackendRegistered returns true if backend has been successfully registered

func CalculateRetryInterval

func CalculateRetryInterval(userValueInSeconds int32) time.Duration

CalculateRetryInterval converts userValueInSeconds to time.Duration, it returns DefaultRetryInterval if userValueInSeconds is not specified

func CompareBackendRecords

func CompareBackendRecords(
	expect []*lbcfapi.BackendRecord,
	have []*lbcfapi.BackendRecord,
	doNotDelete []*lbcfapi.BackendRecord) (needCreate, needUpdate, needDelete []*lbcfapi.BackendRecord)

CompareBackendRecords compares expect with have and returns actions should be taken to meet the expect.

The actions are return in 3 BackendRecord slices:

needCreate: BackendsRecords in this slice doesn't exist in K8S and should be created

needUpdate: BackendsReocrds in this slice already exist in K8S and should be update to k8s

needDelete: BackendsRecords in this slice should be deleted from k8s

func ConstructPodBackendRecord

func ConstructPodBackendRecord(lb *lbcfapi.LoadBalancer, group *lbcfapi.BackendGroup, pod *v1.Pod) []*lbcfapi.BackendRecord

ConstructPodBackendRecord constructs a new BackendRecord

func ConstructServiceBackendRecord

func ConstructServiceBackendRecord(lb *lbcfapi.LoadBalancer, group *lbcfapi.BackendGroup, svc *v1.Service, node *v1.Node) *lbcfapi.BackendRecord

ConstructServiceBackendRecord constructs a new BackendRecord of type service

func ConstructStaticBackend

func ConstructStaticBackend(lb *lbcfapi.LoadBalancer, group *lbcfapi.BackendGroup, staticAddr string) *lbcfapi.BackendRecord

ConstructStaticBackend constructs BackendRecords of type service

func DeregByWebhook added in v1.3.0

func DeregByWebhook(bg *lbcfapi.BackendGroup) bool

func DeregIfNotRunning added in v1.3.0

func DeregIfNotRunning(bg *lbcfapi.BackendGroup) bool

DeregIfNotRunning returns true if backend should be deregistered when not running, instead of not ready

func DetermineNeededBackendGroupUpdates

func DetermineNeededBackendGroupUpdates(oldGroups, groups sets.String, podStatusChanged bool) sets.String

DetermineNeededBackendGroupUpdates compares oldGroups with groups, and returns BackendGroups that should be

func FilterBackendGroup

func FilterBackendGroup(all []*lbcfapi.BackendGroup, filter func(*lbcfapi.BackendGroup) bool) []*lbcfapi.BackendGroup

FilterBackendGroup runs filter on every BackendGroup in all and collects the BackendGroup if filter returns true

func FilterPods

func FilterPods(all []*v1.Pod, filter func(pod *v1.Pod) bool) []*v1.Pod

FilterPods runs filter on every Pod in all and collects the Pod if filter returns true

func GetBackendRecordCondition

func GetBackendRecordCondition(status *lbcfapi.BackendRecordStatus, conditionType lbcfapi.BackendRecordConditionType) *lbcfapi.BackendRecordCondition

GetBackendRecordCondition is an helper function to get specific BackendRecord condition

func GetDuration

func GetDuration(cfg *lbcfapi.Duration, defaultValue time.Duration) time.Duration

GetDuration converts cfg to time.Duration, defaultValue is returned if cfg is nil

func GetLBCondition

GetLBCondition is an helper function to get specific LoadBalancer condition

func GetPodCondition added in v1.1.2

func GetPodCondition(status *v1.PodStatus, conditionType v1.PodConditionType) (int, *v1.PodCondition)

GetPodCondition extracts the provided condition from the given status and returns that. Returns nil and -1 if the condition is not present, and the index of the located condition.

func GetPodConditionFromList added in v1.1.2

func GetPodConditionFromList(conditions []v1.PodCondition, conditionType v1.PodConditionType) (int, *v1.PodCondition)

GetPodConditionFromList extracts the provided condition from the given list of condition and returns the index of the condition and the condition. Returns -1 and nil if the condition is not present.

func GetPodReadyCondition added in v1.1.2

func GetPodReadyCondition(status v1.PodStatus) *v1.PodCondition

Extracts the pod ready condition from the given status and returns that. Returns nil if the condition is not present.

func HasFinalizer

func HasFinalizer(all []string, expect string) bool

HasFinalizer is an helper function to look for expect in all

func IsDriverDraining

func IsDriverDraining(driver *lbcfapi.LoadBalancerDriver) bool

IsDriverDraining indicates whether driver is draining

func IsLBMatchBackendGroup

func IsLBMatchBackendGroup(group *lbcfapi.BackendGroup, lb *lbcfapi.LoadBalancer) bool

IsLBMatchBackendGroup returns true if group is connected to lb

func IsLoadBalancerAllowedForBackendGroup added in v1.3.0

func IsLoadBalancerAllowedForBackendGroup(lb *lbcfapi.LoadBalancer, bgNamespace string) bool

IsLoadBalancerAllowedForBackendGroup returns true if lb is allowed to be used in bgNamespace.

Note: If a LoadBalancer has non empty scope, namespace of the LoadBalancer must be included in order to use it in its own namespace

func IsPodMatchBackendGroup

func IsPodMatchBackendGroup(group *lbcfapi.BackendGroup, pod *v1.Pod) bool

IsPodMatchBackendGroup returns true if pod is included in group

func IsPodReady added in v1.1.2

func IsPodReady(pod *v1.Pod) bool

IsPodReady returns true if a pod is ready; false otherwise.

func IsPodReadyConditionTrue added in v1.1.2

func IsPodReadyConditionTrue(status v1.PodStatus) bool

IsPodReady returns true if a pod is ready; false otherwise.

func IsSvcMatchBackendGroup

func IsSvcMatchBackendGroup(group *lbcfapi.BackendGroup, svc *v1.Service) bool

IsSvcMatchBackendGroup returns true if group is connected to lb

func IterateBackends

func IterateBackends(all []*lbcfapi.BackendRecord, handler func(*lbcfapi.BackendRecord) error) error

IterateBackends runs handler on every BackendRecord in all and returns error if any error occurs

func LBCreated

func LBCreated(lb *lbcfapi.LoadBalancer) bool

LBCreated indicates the given LoadBalancer is successfully created by webhook createLoadBalancer

func LBEnsured

func LBEnsured(lb *lbcfapi.LoadBalancer) bool

LBEnsured indicates the given LoadBalancer is successfully ensured by webhook ensureLoadBalancer

func MakeBackendLabels

func MakeBackendLabels(driverName, lbName, groupName, svcName, podName string) map[string]string

MakeBackendLabels generates labels for BackendRecord

func MakePodBackendName

func MakePodBackendName(lbName, groupName string, podUID types.UID, port lbcfapi.PortSelector) string

MakePodBackendName generates a name for BackendRecord

func MakeServiceBackendName

func MakeServiceBackendName(lbName, groupName, svcName string, nodePort int32, nodePortProtocol string, nodeName string) string

MakeServiceBackendName generates a name for BackendRecord of service type

func MakeStaticBackendName

func MakeStaticBackendName(lbName, groupName, staticAddr string) string

MakeStaticBackendName generates a name for BackendRecord of service type

func NamespaceOfSharedObj added in v1.3.0

func NamespaceOfSharedObj(name string, defaultNamespace string) string

NamespaceOfSharedObj returns the namespace of shared LBCF objects, including LoadBalancerDriver and LoadBalancer, by name. It returns "kube-system" if the name starts with "lbcf-", otherwise the defaultNamespace is returned

func NamespacedNameKeyFunc

func NamespacedNameKeyFunc(namespace, name string) string

NamespacedNameKeyFunc generates a name that can be handled by cache.DeletionHandlingMetaNamespaceKeyFunc

func NeedEnqueueBackend

func NeedEnqueueBackend(old *lbcfapi.BackendRecord, cur *lbcfapi.BackendRecord) bool

NeedEnqueueBackend determines if the given BackendRecord should be enqueue

func NeedEnqueueLB

func NeedEnqueueLB(old *lbcfapi.LoadBalancer, cur *lbcfapi.LoadBalancer) bool

NeedEnqueueLB determines if the given LoadBalancer should be enqueue

func NeedPeriodicEnsure

func NeedPeriodicEnsure(cfg *lbcfapi.EnsurePolicyConfig, deleting bool) bool

NeedPeriodicEnsure tests if ensurePolicy is on

func PodAvailable

func PodAvailable(obj *v1.Pod) bool

PodAvailable indicates the given pod is ready to bind to load balancers

func PodAvailableByRunning added in v1.3.0

func PodAvailableByRunning(obj *v1.Pod) bool

PodAvailableByRunning indicates the given pod is ready to bind to load balancers, by checking pod.status.phase

func RemoveFinalizer

func RemoveFinalizer(all []string, toDelete string) []string

RemoveFinalizer removes toDelete from all and returns a new slice

Types

type BackendType

type BackendType string

BackendType indicates the elements that form a BackendGroup

const (
	// TypeService indicates the BackendGroup consists of services
	TypeService BackendType = "Service"

	// TypePod indicates the BackendGroup consists of pods
	TypePod BackendType = "Pod"

	// TypeStatic indicates the BackendGroup consists of static addresses
	TypeStatic BackendType = "Static"

	// TypeUnknown indicates the BackendGroup consists of unknown backends
	TypeUnknown BackendType = "Unknown"
)

func GetBackendType

func GetBackendType(bg *lbcfapi.BackendGroup) BackendType

GetBackendType returns the BackendType of bg

type ConditionalRateLimitingInterface

type ConditionalRateLimitingInterface interface {
	workqueue.DelayingInterface
	AddAfterMinimumDelay(item interface{}, duration time.Duration)
	Forget(item interface{})
	AddAfterFiltered(item interface{}, duration time.Duration)
	LenWaitingForFilter() int
	GetName() string
}

ConditionalRateLimitingInterface is an workqueue.RateLimitingInterface that can Add item with a filter

func NewConditionalDelayingQueue

func NewConditionalDelayingQueue(name string, filter QueueFilter, minDelay time.Duration, step time.Duration, maxDelay time.Duration) ConditionalRateLimitingInterface

NewConditionalDelayingQueue returns a new instance of ConditionalRateLimitingInterface. If minDelay is less than step, the real minimum delay is step.

type ErrorList

type ErrorList []error

ErrorList is an helper that collects errors

func (ErrorList) Error

func (e ErrorList) Error() string

Error returns formats all errors into one error

type QueueFilter

type QueueFilter func(item interface{}) (bool, error)

QueueFilter is a function that filter queue elements

func QueueFilterForBackend

func QueueFilterForBackend(backendLister v1beta1.BackendRecordLister) QueueFilter

QueueFilterForBackend returns a PeriodicFilter for BackendRecord

func QueueFilterForLB

func QueueFilterForLB(lbLister v1beta1.LoadBalancerLister) QueueFilter

QueueFilterForLB returns aPeriodicFilter for LoadBalancer

type SyncResult

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

SyncResult stores result for sync method of controllers

func AsyncResult

func AsyncResult(period time.Duration) *SyncResult

AsyncResult returns a new SyncResult that call IsPeriodic() on it will return true

func ErrorResult

func ErrorResult(err error) *SyncResult

ErrorResult returns a new SyncResult that call IsError() on it will return true

func FailResult

func FailResult(delay time.Duration, msg string) *SyncResult

FailResult returns a new SyncResult that call IsFailed() on it will return true

func FinishedResult

func FinishedResult() *SyncResult

FinishedResult returns a new SyncResult that call IsFinished() on it will return true

func PeriodicResult

func PeriodicResult(period time.Duration) *SyncResult

PeriodicResult returns a new SyncResult that call IsPeriodic() on it will return true

func (*SyncResult) GetFailReason

func (s *SyncResult) GetFailReason() string

GetFailReason returns the error stored in SyncResult

func (*SyncResult) GetNextRun

func (s *SyncResult) GetNextRun() time.Duration

GetNextRun returns in how long time the operation should be retried

func (*SyncResult) IsFailed

func (s *SyncResult) IsFailed() bool

IsFailed indicates no error occured during operation, but the operation failed

func (*SyncResult) IsFinished

func (s *SyncResult) IsFinished() bool

IsFinished indicates the operation is successfully finished

func (*SyncResult) IsPeriodic

func (s *SyncResult) IsPeriodic() bool

IsPeriodic indicates the operation successfully finished and should be called periodically

func (*SyncResult) IsRunning

func (s *SyncResult) IsRunning() bool

IsRunning indicates the operation is still in progress

type WebhookInvoker

WebhookInvoker is an abstract interface for testability

func NewWebhookInvoker

func NewWebhookInvoker() WebhookInvoker

NewWebhookInvoker creates a new instance of WebhookInvoker

type WebhookInvokerImpl

type WebhookInvokerImpl struct{}

WebhookInvokerImpl is an implementation of WebhookInvoker

func (*WebhookInvokerImpl) CallCreateLoadBalancer

CallCreateLoadBalancer calls webhook createLoadBalancer on driver

func (*WebhookInvokerImpl) CallDeleteLoadBalancer

CallDeleteLoadBalancer calls webhook deleteLoadBalancer on driver

func (*WebhookInvokerImpl) CallDeregisterBackend

CallDeregisterBackend calls webhook deregisterBackend on driver

func (*WebhookInvokerImpl) CallEnsureBackend

CallEnsureBackend calls webhook ensureBackend on driver

func (*WebhookInvokerImpl) CallEnsureLoadBalancer

CallEnsureLoadBalancer calls webhook ensureLoadBalancer on driver

func (*WebhookInvokerImpl) CallGenerateBackendAddr

CallGenerateBackendAddr calls webhook generateBackendAddr on driver

func (*WebhookInvokerImpl) CallJudgePodDeregister added in v1.3.0

func (*WebhookInvokerImpl) CallValidateBackend

CallValidateBackend calls webhook validateBackend on driver

func (*WebhookInvokerImpl) CallValidateLoadBalancer

CallValidateLoadBalancer calls webhook validateLoadBalancer on driver

Jump to

Keyboard shortcuts

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