Documentation
¶
Overview ¶
Package resource provides the common interfaces and types for cloud resources, regardless of the cloud provider.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNilFloatingIP = errors.New("floating IP is nil")
ErrNilFloatingIP is returned when a nil floating IP is used.
var ErrNilResource = errors.New("resource is nil")
ErrNilResource is returned when a nil resource is unexpectedly used.
var ErrWrongProvider = errors.New("resource is from the wrong provider")
ErrWrongProvider is returned when a resource is used with the wrong provider.
Functions ¶
This section is empty.
Types ¶
type Changeset ¶
type Changeset[ResourceType Resource] struct { // Added is a list of resources that were added. The order of the list is not guaranteed. Added []ResourceType // Removed is a list of resources that were removed. The order of the list is not guaranteed. Removed []ResourceType // Updated is a list of resources that were updated. The order of the list is not guaranteed. Updated []ResourceType }
Changeset represents a set of changes between two slices of resources.
func NewChangeset ¶
NewChangeset creates a new changeset, comparing two slices of resources. The changeset will contain the resources that were added, removed, or updated.
type FloatingIP ¶
type FloatingIP struct { // Provider is the name of the cloud provider that the floating IP is from. Provider ProviderName // HetznerID is the unique identifier of the floating IP in Hetzner. HetznerID int64 // FloatingIPName is the name of the floating IP. FloatingIPName string // Location is the datacenter where the floating IP is located. // This is generally `fsn1` or `nbg1`. Location string // NetworkZone is the network zone where the floating IP is located. NetworkZone string // IP is the IP address of the floating IP. IP netip.Addr // CurrentTarget is the ID of the server that the floating IP is currently assigned to. // Empty if the floating IP is not currently assigned to a server. CurrentTarget string // ResourceIndex is more or less the number of a server within a deployment // within a zone with the same role. // // In other words: if there are say 3 API servers, they would probably have // index 0 through 2. This is used to somewhat consistently map // load balancers to servers. // // This should be `-1` if unknown (or invalid). ResourceIndex int // URL is the URL of the floating IP in the cloud provider's web interface. URL string }
FloatingIP is a reassignable IP that can be moved between servers.
func (FloatingIP) Equal ¶
func (f FloatingIP) Equal(other Resource) bool
Equal returns true if the two floating IPs are equal.
func (FloatingIP) ID ¶
func (f FloatingIP) ID() string
ID returns the unique identifier of the floating IP.
func (FloatingIP) Name ¶
func (f FloatingIP) Name() string
Name returns the name of the floating IP.
func (FloatingIP) String ¶
func (f FloatingIP) String() string
String returns a string representation of the floating IP.
type FloatingIPPair ¶
type FloatingIPPair struct {
// contains filtered or unexported fields
}
FloatingIPPair is a pair of floating IPs, one IPv4 and one IPv6.
func NewFloatingIPPair ¶
func NewFloatingIPPair(v4, v6 FloatingIP) (FloatingIPPair, error)
NewFloatingIPPair creates a new FloatingIPPair.
type FloatingIPs ¶
type FloatingIPs []FloatingIP
FloatingIPs is a list of floating IPs.
func (FloatingIPs) SortByName ¶
func (flips FloatingIPs) SortByName()
SortByName sorts the floating IPs by name.
type Group ¶
type Group struct { FloatingIPs []FloatingIP Servers []Server }
Group is a set of resources. It generally created as the result of a Provider's poll call.
func (*Group) FloatingIPsByID ¶
func (g *Group) FloatingIPsByID() map[string]FloatingIP
FloatingIPsByID returns a map of FloatingIPs by their ID.
func (*Group) ServersByID ¶
ServersByID returns a map of Servers by their ID.
type GroupChangeset ¶
type GroupChangeset struct { Servers Changeset[Server] FloatingIPs Changeset[FloatingIP] }
GroupChangeset represents the changes between two groups.
func NewGroupChangeset ¶
func NewGroupChangeset(oldGroup, newGroup Group) GroupChangeset
NewGroupChangeset creates a new group changeset, comparing two groups.
func (*GroupChangeset) Empty ¶
func (c *GroupChangeset) Empty() bool
Empty returns true if the changeset is empty.
func (*GroupChangeset) IsUpdatesOnly ¶
func (c *GroupChangeset) IsUpdatesOnly() bool
IsUpdatesOnly returns true if the changeset only contains updated resources.
func (*GroupChangeset) String ¶
func (c *GroupChangeset) String() string
String returns a string representation of the group changeset.
type Provider ¶
type Provider interface { // Name uniquely identifies the provider. Name() ProviderName // Poll returns the current resources in the provider. Poll(ctx context.Context) (Group, error) // AssignFloatingIP targets a floating IP at a server. AssignFloatingIP(ctx context.Context, flip FloatingIP, srv Server) error }
Provider is a cloud provider that can provide resources.
type ProviderName ¶
type ProviderName string
ProviderName is the name of a cloud provider.
const ( // ProviderNameHetzner is the name of the Hetzner cloud provider. ProviderNameHetzner ProviderName = "hetzner" // ProviderNameMock is the name of the mock cloud provider used for testing. ProviderNameMock ProviderName = "mock" )
type Resource ¶
type Resource interface { // ID returns the unique identifier of the resource. // Currently as we only support Hetzner, this is the Hetzner ID converted to a string. ID() string // Equal returns true if the two resources are equal. Equal(Resource) bool // Name returns the name of the resource. Name() string }
Resource is a common interface for cloud/infra resources.
type Resources ¶
type Resources []Resource
Resources is a list of resources.
func (Resources) SortByName ¶
func (r Resources) SortByName()
SortByName sorts the resources by name.
type Server ¶
type Server struct { // Provider is name of the cloud provider where the server is located. Provider ProviderName // HetznerID is the unique ID of the server in Hetzner. HetznerID int64 // ServerName is the name of the server. ServerName string // Location is the datacenter where the server is located. // This is generally `fsn1` or `nbg1`. Location string // NetworkZone is the network zone where the server is located. // This is generally `eu-central`. NetworkZone string // ResourceIndex is more or less the number of a server within a deployment // within a zone with the same role. // // In other words: if there are say 3 API servers, they would probably have // index 0 through 2. This is used to somewhat consistently map // load balancers to servers. // // This should be `-1` if unknown (or invalid). ResourceIndex int // PublicIPv4 is the public IPv4 address of the server. PublicIPv4 netip.Addr // PublicIPv6 is the public IPv6 address of the server. PublicIPv6 netip.Addr // URL is the URL to the server in the Cloud Provider's console. URL string }
Server is a physical or virtual server that can be assigned a floating IP.
type State ¶
type State struct { // LastUpdated is the time when the status was last updated. LastUpdated time.Time // Status is the status code of the resource, e.g. healthy, unhealthy, unknown. Status Status }
State is the health state of a resource.
type Status ¶
type Status string
Status is the status code of a resource.
const ( // StatusHealthy is used when the resource is known to be healthy. StatusHealthy Status = "healthy" // StatusUnhealthy is used when the resource is known to be unhealthy. StatusUnhealthy Status = "unhealthy" // StatusUnknown is used when the resource status is not known, e.g. when the resource is not yet checked. StatusUnknown Status = "unknown" )
type WithStatus ¶
type WithStatus[R Resource] struct { Resource R // contains filtered or unexported fields }
WithStatus is a resource with an associated status, which can be updated atomically.
func NewWithStatus ¶
func NewWithStatus[R Resource](s R, status State) *WithStatus[R]
NewWithStatus creates a new server with a given (initial) status.
func (*WithStatus[R]) IsHealthy ¶
func (s *WithStatus[R]) IsHealthy() bool
IsHealthy returns true if the resource is known to be healthy.
func (*WithStatus[R]) IsUnhealthy ¶
func (s *WithStatus[R]) IsUnhealthy() bool
IsUnhealthy returns true if the resource is known to be unhealthy.
func (*WithStatus[R]) SetState ¶
func (s *WithStatus[R]) SetState(state State) State
SetState sets the state of the resource and returns the previous status.
func (*WithStatus[R]) State ¶
func (s *WithStatus[R]) State() State
State returns the current health state of the resource.
func (*WithStatus[R]) Status ¶
func (s *WithStatus[R]) Status() Status
Status returns the current status code of the resource.
type WithStatusSlice ¶
type WithStatusSlice[R Resource] []*WithStatus[R]
WithStatusSlice is a list of resources with associated statuses.
func (WithStatusSlice[R]) SortByName ¶
func (servs WithStatusSlice[R]) SortByName()
SortByName sorts the resources by name.