plan

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package plan contains the logic for creating a plan to reassign floating IPs to servers to keep things balanced and healthy.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Plan

type Plan struct {
	// ID is a random UUID to identify the plan.
	ID      uuid.UUID
	Actions []ReassignFloatingIPAction
}

Plan describes the changeset to be applied to the cloud resources.

func New

func New(s State) Plan

New takes the current state of the cloud resources and returns a plan for reassigning floating IPs.

func (*Plan) AddAction

func (p *Plan) AddAction(action ReassignFloatingIPAction)

AddAction adds an action to the plan.

func (Plan) Empty

func (p Plan) Empty() bool

Empty returns true if the plan is empty.

func (Plan) String

func (p Plan) String() string

String returns a string representation of the plan.

func (Plan) ToBeReassignedMap

func (p Plan) ToBeReassignedMap() map[string]bool

ToBeReassignedMap returns the floating IP IDs that will be reassigned.

type ReassignFloatingIPAction

type ReassignFloatingIPAction struct {
	// FloatingIPID is the ID of the floating IP to be reassigned.
	FloatingIPID string

	// ServerID string is the ID of the server to which the floating IP should be reassigned.
	ServerID string
}

ReassignFloatingIPAction is a plan to reassign a floating IP to a different server.

func (ReassignFloatingIPAction) String

func (a ReassignFloatingIPAction) String() string

String returns a string representation of the action.

type State

type State struct {
	FloatingIPs map[string]resource.FloatingIP
	Servers     map[string]*resource.WithStatus[resource.Server]
}

State represents the current state of the cloud resources.

func NewState

func NewState(floatingIPs []resource.FloatingIP, servers []*resource.WithStatus[resource.Server]) State

NewState creates a new state.

func NewStateFromGroup

func NewStateFromGroup(group resource.Group) State

NewStateFromGroup creates a new state from a group of resources. The resources will start with an unknown status.

func (State) CandidateFloatingIPs

func (s State) CandidateFloatingIPs() []resource.FloatingIP

CandidateFloatingIPs returns all floating IPs that we should me managing the targets of.

func (State) CandidateServers

func (s State) CandidateServers() []*resource.WithStatus[resource.Server]

CandidateServers returns all healthy servers, or all servers if there are no healthy ones. It returns them in a fixed order.

func (State) FloatingIPsAsSlice added in v0.2.0

func (s State) FloatingIPsAsSlice() resource.FloatingIPs

FloatingIPsAsSlice returns the floating IPs as a slice in a fixed order.

func (State) FloatingIPsByServer

func (s State) FloatingIPsByServer() map[string]resource.FloatingIPs

FloatingIPsByServer returns a map of server IDs to floating IPs.

func (State) FloatingIPsTargetedOutsideGroup

func (s State) FloatingIPsTargetedOutsideGroup() resource.FloatingIPs

FloatingIPsTargetedOutsideGroup returns the floating IPs that are targeted at unknown servers.

func (State) HasServersWithUnknownStatus

func (s State) HasServersWithUnknownStatus() bool

HasServersWithUnknownStatus returns true if there are servers with an unknown status.

func (State) NumUnhealthyServers

func (s State) NumUnhealthyServers() int

NumUnhealthyServers returns the number of unhealthy servers.

func (State) ServersAsSlice added in v0.2.0

func (s State) ServersAsSlice() resource.WithStatusSlice[resource.Server]

ServersAsSlice returns the servers as a slice in a fixed order.

func (State) UnassignedFloatingIPs

func (s State) UnassignedFloatingIPs() []resource.FloatingIP

UnassignedFloatingIPs returns all floating IPs that are not assigned to a server.

func (State) UnhealthyFloatingIPs

func (s State) UnhealthyFloatingIPs() []resource.FloatingIP

UnhealthyFloatingIPs returns all floating IPs that are assigned to an unhealthy server.

Jump to

Keyboard shortcuts

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