helper

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2024 License: Apache-2.0 Imports: 60 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OpenstackReconcileTime    = 5 * time.Minute
	DefaultRequeueTime        = 10 * time.Millisecond
	RevisionAnnotation        = "loadbalancer.yawol.stackit.cloud/revision"
	YawolLibDir               = "/var/lib/yawol/"
	YawolletHealthCheckScript = YawolLibDir + "check_yawollet_health.sh"
	HashLabel                 = "lbm-template-hash"
	LoadBalancerKind          = "LoadBalancer"
	VRRPInstanceName          = "ENVOY"
	HasKeepalivedMaster       = "HasKeepalivedMaster"
	DefaultLoadbalancerClass  = "stackit.cloud/yawol"
)
View Source
const (
	FilterUDPProxy string = "envoy.filters.udp_listener.udp_proxy"
)

TODO: replace with constants from envoywellknown when available

Variables

View Source
var (
	ErrFailToReadRevisionFromAnnotation      = errors.New("failed to read revision from annotation")
	ErrNotAValidIP                           = errors.New("not a valid IP address")
	ErrNoFixedIPForLBPort                    = errors.New("no fixed ip for loadbalancer port")
	ErrCouldNotReadSvcNameSpacedNameFromAnno = errors.New("could not read service namespacedname from annotation")
	ErrNoEventFound                          = errors.New("no event found")
	ErrMaxTriesExceeded                      = errors.New("max tries exceeded")
	ErrSourceRangesAreWrong                  = errors.New("source ranges are wrong")
	ErrEndpointValuesWrong                   = errors.New("endpoint values wrong")
	ErrPortValuesWrong                       = errors.New("port values wrong")
	ErrLBMustNotBeNil                        = errors.New("LoadBalancer must no be nil")
	ErrLBUIDMustNotBeNil                     = errors.New("LoadBalancer.UID must not be nil")
	ErrFailedToCreatePortForLBM              = errors.New("failed to create port for lbm")
	ErrLBOrLBMPortsAreNil                    = errors.New("lb or lbm ports are nil")
	ErrLBMPortNotSet                         = errors.New("load balancer machine port not set")
	ErrLBPortNotSet                          = errors.New("load balancer port not set")
	ErrFIPIDEmpty                            = errors.New("fip was successfully created but fip id is empty")
	ErrPortIDEmpty                           = errors.New("port was successfully created but port id is empty")
	ErrPortNameEmpty                         = errors.New("port name is empty")
	ErrServerGroupIDEmpty                    = errors.New("server group was successfully created but server group id is empty")
	ErrSecGroupIDEmpty                       = errors.New("secGroup was successfully created but secGroup id is empty")
	ErrSecGroupNil                           = errors.New("SecGroup is nil, cannot create rules")
	ErrIPNotInStatus                         = errors.New("ip not in status")
	ErrIPSetInStatusLBNotReady               = errors.New("ip is set in status but lb is not ready")
	ErrIncorrectEvent                        = errors.New("event not correct")
	ErrSvcEventNotFound                      = errors.New("event on service not found")
	ErrLBOnlyOneIPFamily                     = errors.New("LB only has one IP family type")
	ErrNoExistingFIP                         = errors.New("no existingFloatingIP set")
	ErrFIPNotFound                           = errors.New("FIP not found")
	ErrInvalidClassname                      = errors.New("invalid classname LB created")
	ErrInvalidProtocol                       = errors.New("invalid protocol LB created")
	ErrLBNotCleanedUp                        = errors.New("load balancer didn't clean up")
	ErrSourceRangesWrongLength               = errors.New("source ranges update length does not match")
	ErrNoSourceRangesEvent                   = errors.New("no source ranges event found")
	ErrZeroOrMoreThanOnePortFoundInLB        = errors.New("zero or more than one port found in LB")
	ErrZeroOrMoreThanOneSRFoundInLB          = errors.New("zero or more than one source range in LB found")
	ErrEndpointDoesNotMatchingNodeCount      = errors.New("less or more than two endpoint in LB found")
	ErrWaitingForPortsAndEndpoints           = errors.New("wait for ports and endpoints")
	ErrEndpointsFound                        = errors.New("endpoints found")
	ErrNoEndpointFound                       = errors.New("no endpoint in LB found")
	ErrNotAllConditionsSet                   = errors.New("no or not all conditions are set")
	ErrConditionsLastHeartbeatTimeToOld      = errors.New("lastHeartbeatTime in condition to old")
	ErrConditionsNotInCorrectState           = errors.New("condition is in wrong state")
	ErrConfigNotReady                        = errors.New("config not ready")
	ErrEnvoyNotReady                         = errors.New("envoy not ready")
	ErrEnvoyNotUpToDate                      = errors.New("envoy not upToDate")
	ErrEnvoyListenerNotFound                 = errors.New("envoy listener not found")
	ErrPortProtocolNotSupported              = errors.New("port is not of supported protocol")
	ErrPortInvalidRange                      = errors.New("port is not between 1 and 65535")
	ErrNodePortInvalidRange                  = errors.New("NodePort is not between 1 and 65535")
	ErrEndpointAddressesNil                  = errors.New("endpoint addresses are nil")
	ErrEndpointAddressWrongFormat            = errors.New("endpoint address wrong address format (DNS name) not correct")
	ErrInvalidRevision                       = errors.New("revision number for lb must be >0")
	ErrYawolletRequiredFlags                 = errors.New("namespace, loadbalancer-name and loadbalancer-machine-name are required flags")
	ErrYawolletIPNotFound                    = errors.New("listen-interface is set but no IP found")
	ErrUnexpectedOpenstackStatus             = errors.New("unexpected openstack status")
	ErrSecretNotFound                        = errors.New("secret not found")
	ErrTokenNotFoundInSecret                 = errors.New("token in secret not found")
	ErrCANotFoundInSecret                    = errors.New("ca in secret not found")
	ErrNoNetworkID                           = errors.New("cant get networkID for loadbalancer")
	ErrCouldNotParseSourceRange              = errors.New("could not parse LoadBalancerSourceRange")
	ErrListingChildLBMs                      = errors.New("unable to list child loadbalancerMachines")
	ErrUnsupportedProtocol                   = errors.New("unsupported protocol used (TCP and UDP is supported)")
	ErrUnsupportedServiceOption              = errors.New("unsupported service option is used")
	ErrProjectIsImmutable                    = errors.New("project id is immutable, cant be changed after initial creation")
	ErrNoLBMFoundForScaleDown                = errors.New("no lbm found for scale down")
)

Functions

func AreRelevantConditionsMet added in v0.20.0

func AreRelevantConditionsMet(
	machine *yawolv1beta1.LoadBalancerMachine,
	expiration metav1.Time,
	stableConditions bool,
) (ok bool, reason string)

AreRelevantConditionsMet checks if all required conditions (from the perspective of the LoadBalancerSet) are both `True` and up-to-date, according to the passed expiration time. If `stableConditions` is set, a condition is only considered `False` if it has been in that state since the expiration time.

func CheckEnvoyVersion

func CheckEnvoyVersion(
	conditions map[corev1.NodeConditionType]corev1.NodeCondition,
	snapshot envoycache.ResourceSnapshot,
)

func CheckLoadBalancerClasses added in v0.17.0

func CheckLoadBalancerClasses(service *coreV1.Service, validClasses []string) bool

func CreateEnvoyConfig

func CreateEnvoyConfig(
	r record.EventRecorder,
	oldSnapshot envoycache.ResourceSnapshot,
	lb *yawolv1beta1.LoadBalancer,
	listen string,
) (bool, envoycache.Snapshot, error)

CreateEnvoyConfig create a new envoy snapshot and checks if the new snapshot has changes

func EnableAdHocDebugging added in v0.14.0

func EnableAdHocDebugging(
	lb *yawolv1beta1.LoadBalancer,
	lbm *yawolv1beta1.LoadBalancerMachine,
	recorder record.EventRecorder,
	lbmName string,
) error

EnableAdHocDebugging enables ad-hoc debugging if enabled via annotations.

func GenerateUserData

func GenerateUserData(
	kubeconfig string,
	loadbalancer *yawolv1beta1.LoadBalancer,
	loadbalancerMachine *yawolv1beta1.LoadBalancerMachine,
	vip string,
	yawolletRequeueTime int,
	ntpPools, ntpServers []string,
) (string, error)

func GetDebugSettings

GetDebugSettings return loadbalancer debug settings for a service

func GetDesiredSecGroupRulesForLoadBalancer

func GetDesiredSecGroupRulesForLoadBalancer(r record.EventRecorder, lb *yawolv1beta1.LoadBalancer, secGroupID string) []rules.SecGroupRule

GetDesiredSecGroupRules returns all SecGroupRules that are needed. Based on default rules, ports, debug settings.

func GetExistingFloatingIPFromAnnotation

func GetExistingFloatingIPFromAnnotation(svc *coreV1.Service) *string

GetExistingFloatingIPFromAnnotation return ip from the ServiceExistingFloatingIP annotation

func GetFlavorID

func GetFlavorID(spec yawolv1beta1.OpenstackFlavorRef) (string, error)

func GetHashForLoadBalancerMachineSet added in v0.9.2

func GetHashForLoadBalancerMachineSet(lb *yawolv1beta1.LoadBalancer) (string, error)

func GetIPFromStatus

func GetIPFromStatus(svc *coreV1.Service) *string

GetIPFromStatus return ip from service (Status.LoadBalancer.Ingress[0].IP)

func GetImageID

func GetImageID(spec yawolv1beta1.OpenstackImageRef) (string, error)

func GetLoadBalancerForLoadBalancerSet

func GetLoadBalancerForLoadBalancerSet(
	ctx context.Context,
	c client.Client,
	loadBalancerSet *yawolv1beta1.LoadBalancerSet,
) (*yawolv1beta1.LoadBalancer, error)

func GetLoadBalancerNameFromService

func GetLoadBalancerNameFromService(service *coreV1.Service) string

func GetLoadBalancerSetForHash

func GetLoadBalancerSetForHash(
	loadBalancerSetList *yawolv1beta1.LoadBalancerSetList,
	currentHash string,
) (*yawolv1beta1.LoadBalancerSet, error)

Returns nil if no matching exists If there are multiple: Returns one with highest RevisionAnnotation annotation

func GetLoadBalancerSetLabelsFromLoadBalancer

func GetLoadBalancerSetLabelsFromLoadBalancer(lb *yawolv1beta1.LoadBalancer) map[string]string

func GetLoadBalancerSetsForLoadBalancer

func GetLoadBalancerSetsForLoadBalancer(
	ctx context.Context,
	c client.Client,
	lb *yawolv1beta1.LoadBalancer,
) (yawolv1beta1.LoadBalancerSetList, error)

This returns all LoadBalancerSets for a given LoadBalancer Returns an error if lb is nil Returns an error if lb.UID is empty Returns an error if kube api-server problems occurred

func GetLoadBalancerSourceRanges

func GetLoadBalancerSourceRanges(lb *yawolv1beta1.LoadBalancer) []string

GetLoadBalancerSourceRanges returns the LoadBalancerSourceRanges from the spec. If not set it uses "0.0.0.0/0", "::/0" as default to enable all sources.

func GetMetrics added in v0.15.0

func GetMetrics(keepalivedStatsFile string) ([]yawolv1beta1.LoadBalancerMachineMetric, error)

GetMetrics returns the current LoadBalancerMachineMetrics

func GetNextRevisionForLoadBalancer added in v0.16.1

func GetNextRevisionForLoadBalancer(setList *yawolv1beta1.LoadBalancerSetList) (int, error)

func GetOpenStackReconcileHash

func GetOpenStackReconcileHash(lb *yawolv1beta1.LoadBalancer) (string, error)

GetOpenStackReconcileHash returns a 16 char hash for all openstack relevant data to check if an openstack reconcile is needed.

func GetOptions

GetOptions return loadbalancer option settings for a service

func GetOwnersReferenceForLB

func GetOwnersReferenceForLB(lb *yawolv1beta1.LoadBalancer) metaV1.OwnerReference

GetOwnersReferenceForLB returns OwnerReference for LoadBalancer

func GetReplicasFromService

func GetReplicasFromService(service *coreV1.Service) int

GetReplicasFromService retruns replicas from Annotation. Default is 1

func GetRoleRules

func GetRoleRules(
	loadBalancer *yawolv1beta1.LoadBalancer,
	loadBalancerMachine *yawolv1beta1.LoadBalancerMachine,
) []rbac.PolicyRule

func HashData

func HashData(data interface{}) (string, error)

HashData returns a 16 char hash for the given object.

func LBSetHasKeepalivedMaster added in v0.16.0

func LBSetHasKeepalivedMaster(set *yawolv1beta1.LoadBalancerSet) (bool, time.Duration)

LBSetHasKeepalivedMaster returns true if one of the following conditions are met: - if the keepalived condition on set is ready for more than 2 min - keepalived condition is not ready for more than 10 min (to make sure this does not block updates) - no keepalived condition is in lbs but lbs is older than 15 min (to make sure this does not block updates) When `false` is returned, the second return parameter can be used to requeue again, once the condition that caused the "false" state to be ignored.

func LoadBalancerMachineOpenstackReconcileIsNeeded

func LoadBalancerMachineOpenstackReconcileIsNeeded(lbm *yawolv1beta1.LoadBalancerMachine) bool

LoadBalancerMachineOpenstackReconcileIsNeeded returns true if an openstack reconcile is needed.

func LoadBalancerOpenstackReconcileIsNeeded

func LoadBalancerOpenstackReconcileIsNeeded(lb *yawolv1beta1.LoadBalancer) bool

LoadBalancerOpenstackReconcileIsNeeded returns true if an openstack reconcile is needed.

func NewLoadBalancerSetForLoadBalancer added in v0.16.1

func NewLoadBalancerSetForLoadBalancer(lb *yawolv1beta1.LoadBalancer, hash string, revision int) *yawolv1beta1.LoadBalancerSet

func ParseLoadBalancerMachineMetrics

func ParseLoadBalancerMachineMetrics(
	loadBalancerMachine *yawolv1beta1.LoadBalancerMachine,
	metrics *helpermetrics.LoadBalancerMachineMetricList,
)

func ParseLoadBalancerMetrics

func ParseLoadBalancerMetrics(
	lb yawolv1beta1.LoadBalancer,
	metrics *helpermetrics.LoadBalancerMetricList,
)

func ParseLoadBalancerSetMetrics

func ParseLoadBalancerSetMetrics(
	lbs yawolv1beta1.LoadBalancerSet,
	metrics *helpermetrics.LoadBalancerSetMetricList,
)

func PatchLBMStatus

PatchLBMStatus patch loadbalancermachine status

func PatchLBStatus

PatchLBStatus patch loadbalancer status

func PatchLoadBalancerRevision

func PatchLoadBalancerRevision(ctx context.Context, c client.Client, lb *yawolv1beta1.LoadBalancer, revision int) error

func PatchLoadBalancerSetReplicas

func PatchLoadBalancerSetReplicas(ctx context.Context, c client.Client, lbs *yawolv1beta1.LoadBalancerSet, replicas int) error

PatchLoadBalancerSetReplicas sets replicas in LoadBalancerSet

func PatchServiceStatus

func PatchServiceStatus(
	ctx context.Context,
	sw client.StatusWriter,
	svc *coreV1.Service,
	svcStatus *coreV1.ServiceStatus,
) error

PatchLBStatus patch loadbalancer status

func ReadCurrentRevisionFromLB

func ReadCurrentRevisionFromLB(lb *yawolv1beta1.LoadBalancer) (int, error)

func ReadRevisionFromLBS

func ReadRevisionFromLBS(lbs *yawolv1beta1.LoadBalancerSet) (int, error)

func RemoveFromLBMStatus

func RemoveFromLBMStatus(ctx context.Context, sw client.StatusWriter, lbm *yawolv1beta1.LoadBalancerMachine, key string) error

RemoveFromLBMStatus removes key from loadbalancermachine status.

func RemoveFromLBStatus

func RemoveFromLBStatus(ctx context.Context, sw client.StatusWriter, lb *yawolv1beta1.LoadBalancer, key string) error

RemoveFromLBStatus removes key from loadbalancer status.

func RemoveLoadBalancerMachineMetrics

func RemoveLoadBalancerMachineMetrics(
	loadBalancerMachine *yawolv1beta1.LoadBalancerMachine,
	metrics *helpermetrics.LoadBalancerMachineMetricList,
)

func RemoveLoadBalancerMetrics

func RemoveLoadBalancerMetrics(
	lb yawolv1beta1.LoadBalancer,
	metrics *helpermetrics.LoadBalancerMetricList,
)

func RemoveLoadBalancerSetMetrics

func RemoveLoadBalancerSetMetrics(
	lbs yawolv1beta1.LoadBalancerSet,
	metrics *helpermetrics.LoadBalancerSetMetricList,
)

func ScaleDownOldLoadBalancerSets added in v0.16.1

func ScaleDownOldLoadBalancerSets(
	ctx context.Context,
	c client.Client,
	setList *yawolv1beta1.LoadBalancerSetList,
	currentSetName string,
) error

ScaleDownOldLoadBalancerSets scales down all LoadBalancerSets in the given list except the one with the given name.

func StatusReplicasFromSetList added in v0.16.1

func StatusReplicasFromSetList(setList *yawolv1beta1.LoadBalancerSetList) (replicas, readyReplicas int)

StatusReplicasFromSetList returns the total replicas and ready replicas based on the given list of LoadBalancerSets.

func UpdateEnvoyStatus

func UpdateEnvoyStatus(conditions map[corev1.NodeConditionType]corev1.NodeCondition)

func UpdateKeepalivedPIDStatus added in v0.14.0

func UpdateKeepalivedPIDStatus(
	conditions map[corev1.NodeConditionType]corev1.NodeCondition,
)

func UpdateKeepalivedStatsStatus added in v0.14.0

func UpdateKeepalivedStatsStatus(
	conditions map[corev1.NodeConditionType]corev1.NodeCondition,
	keepalivedStatsFile string,
)

func UpdateKeepalivedStatus

func UpdateKeepalivedStatus(
	conditions map[corev1.NodeConditionType]corev1.NodeCondition,
	keepalivedStatsFile string,
)

func UpdateLBMConditions

func UpdateLBMConditions(
	conditions map[corev1.NodeConditionType]corev1.NodeCondition,
	condition LoadbalancerCondition,
	status LoadbalancerConditionStatus,
	reason string,
	message string,
)

UpdateLBMConditions update a given condition in lbm object

func ValidateService

func ValidateService(svc *coreV1.Service) error

ValidateService checks if the service is valid

Types

type LoadbalancerCondition

type LoadbalancerCondition string

LoadbalancerCondition condition name for conditions in lbm

const (
	ConfigReady         LoadbalancerCondition = "ConfigReady"
	EnvoyReady          LoadbalancerCondition = "EnvoyReady"
	EnvoyUpToDate       LoadbalancerCondition = "EnvoyUpToDate"
	KeepalivedProcess   LoadbalancerCondition = "KeepalivedProcess"
	KeepalivedStatsFile LoadbalancerCondition = "KeepalivedStatsFile"
	KeepalivedMaster    LoadbalancerCondition = "KeepalivedMaster"

	DeletionMarkerCondition corev1.NodeConditionType = "MarkedForDeletion"
)

Condition name const

type LoadbalancerConditionStatus

type LoadbalancerConditionStatus string

LoadbalancerConditionStatus condition status for conditions in lbm

const (
	ConditionTrue  LoadbalancerConditionStatus = "True"
	ConditionFalse LoadbalancerConditionStatus = "False"
)

Condition status const

type LoadbalancerMetric

type LoadbalancerMetric string

LoadbalancerMetric metric name for lbm

const (
	MetricLoad1                            LoadbalancerMetric = "load1"
	MetricLoad5                            LoadbalancerMetric = "load5"
	MetricLoad15                           LoadbalancerMetric = "load15"
	MetricUptime                           LoadbalancerMetric = "uptime"
	MetricNumCPU                           LoadbalancerMetric = "numCPU"
	MetricMemTotal                         LoadbalancerMetric = "memTotal"
	MetricMemFree                          LoadbalancerMetric = "memFree"
	MetricMemAvailable                     LoadbalancerMetric = "memAvailable"
	MetricStealTime                        LoadbalancerMetric = "stealTime"
	MetricKeepalivedIsMaster               LoadbalancerMetric = "keepalivedIsMaster"
	MetricKeepalivedBecameMaster           LoadbalancerMetric = "keepalivedBecameMaster"
	MetricKeepalivedReleasedMaster         LoadbalancerMetric = "keepalivedReleasedMaster"
	MetricKeepalivedAdvertisementsSent     LoadbalancerMetric = "keepalivedAdvertisementsSent"
	MetricKeepalivedAdvertisementsReceived LoadbalancerMetric = "keepalivedAdvertisementsReceived"
)

Metric name const

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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