Documentation
¶
Overview ¶
Package lbspec resolves the desired state of a Hetzner Cloud Load Balancer from the annotations of a Kubernetes Service and the cluster-wide configuration.
Resolution is pure: it makes no API calls, emits no events and reads no clock. Anything that needs the Hetzner Cloud API - looking up a Load Balancer type by name, turning certificate names into IDs - is left to the caller, which receives the parsed intent and nothing else.
Every invalid annotation is reported, not just the first one, so a user with two typos does not need two reconciles to learn about both.
Index ¶
- Constants
- func Name(svc *corev1.Service) string
- type HTTPSpec
- type HealthCheckHTTPSpec
- type HealthCheckSpec
- type OwnedCertificate
- type ServiceSpec
- type Spec
- func (s Spec) AddServerTargetOpts(serverID int64) hcloud.LoadBalancerAddServerTargetOpts
- func (s Spec) AttachToNetworkOpts(network *hcloud.Network) hcloud.LoadBalancerAttachToNetworkOpts
- func (s Spec) ChangeAlgorithmOpts() hcloud.LoadBalancerChangeAlgorithmOpts
- func (s Spec) CreateOpts(lbType *hcloud.LoadBalancerType) hcloud.LoadBalancerCreateOpts
- func (s Spec) UpdateOpts(lb *hcloud.LoadBalancer) (hcloud.LoadBalancerUpdateOpts, bool)
Constants ¶
const DefaultType = "lb11"
const LabelServiceUID = "hcloud-ccm/service-uid"
LabelServiceUID is a label added to the Hetzner Cloud backend to uniquely identify a load balancer managed by Hetzner Cloud Cloud Controller Manager.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type HTTPSpec ¶
type HTTPSpec struct {
CookieName *string
CookieLifetime *time.Duration
TimeoutIdle *time.Duration
RedirectHTTP *bool
StickySessions *bool
// Certificates reference certificates either by ID or by name, exactly as
// the annotation spelled them. Resolving names to IDs needs the API and is
// left to the caller. Certificates that already exist are referenced here
// whatever their type, managed ones included. Empty for an
// [OwnedCertificate], which the caller looks up by label instead.
Certificates []*hcloud.Certificate
}
HTTPSpec holds the HTTP options of a Load Balancer service.
type HealthCheckHTTPSpec ¶
HealthCheckHTTPSpec holds the HTTP options of a health check.
type HealthCheckSpec ¶
type HealthCheckSpec struct {
// Protocol defaults to the service protocol when no health check protocol
// is configured.
Protocol hcloud.LoadBalancerServiceProtocol
// Port is nil when unconfigured, in which case the destination port is
// checked.
Port *int
Interval *time.Duration
Timeout *time.Duration
Retries *int
// HTTP is only applied for the HTTP and HTTPS protocols, so it is a value:
// its options can all be unset while the block itself is still sent.
HTTP HealthCheckHTTPSpec
}
HealthCheckSpec holds the health check options of a Load Balancer service.
type OwnedCertificate ¶
type OwnedCertificate struct {
Name string
Labels map[string]string
Domains []string
// UseACMEStaging is for Hetzner internal testing only.
UseACMEStaging bool
}
OwnedCertificate is a certificate the cloud controller manager creates on behalf of the Service and owns for its lifetime.
It is of the Hetzner Cloud "managed" certificate type, so the backend renews it, but not every managed certificate is an OwnedCertificate: one created outside the cluster is referenced by ID or name through HTTPSpec.Certificates like an uploaded one.
func (OwnedCertificate) CreateOpts ¶
func (c OwnedCertificate) CreateOpts() hcloud.CertificateCreateOpts
type ServiceSpec ¶
type ServiceSpec struct {
Protocol hcloud.LoadBalancerServiceProtocol
ProxyProtocol *bool
// HTTP is nil unless at least one HTTP option is configured, in which case
// no HTTP block is sent to the API at all.
HTTP *HTTPSpec
// HealthCheck is nil unless at least one health check option is
// configured, in which case a TCP check against the destination port is
// used.
HealthCheck *HealthCheckSpec
}
ServiceSpec is the desired state of the services exposed by the Load Balancer.
func (ServiceSpec) AddServiceOpts ¶
func (s ServiceSpec) AddServiceOpts( port corev1.ServicePort, certificates []*hcloud.Certificate, ) hcloud.LoadBalancerAddServiceOpts
func (ServiceSpec) UpdateServiceOpts ¶
func (s ServiceSpec) UpdateServiceOpts( port corev1.ServicePort, certificates []*hcloud.Certificate, ) hcloud.LoadBalancerUpdateServiceOpts
type Spec ¶
type Spec struct {
// Name is the effective Load Balancer name, never empty.
Name string
// NameUnset reports that Name is derived from the Service UID because no
// name was requested. An unrequested name is not applied to an existing
// Load Balancer, so that one created by other means keeps its own.
NameUnset bool
// Labels are the labels the Load Balancer must carry.
Labels map[string]string
// Hostname is published as the ingress address instead of the IPs when set.
Hostname string
// NodeSelector restricts which Nodes become targets. Never nil.
NodeSelector labels.Selector
// Type is the Load Balancer type name, never empty.
Type string
// TypeUnset reports that Type holds [DefaultType] because nothing
// configured it. An unconfigured type is not applied to an existing Load
// Balancer, to avoid downgrading it.
TypeUnset bool
Location string
NetworkZone hcloud.NetworkZone
// Algorithm is empty when unconfigured, in which case it is left alone.
Algorithm hcloud.LoadBalancerAlgorithmType
// PublicInterface reports whether the public interface should be enabled.
// Nil when unconfigured, in which case it is left alone.
PublicInterface *bool
// IPv4RDNS and IPv6RDNS are nil when unconfigured. The empty string is a
// valid value and resets the record.
IPv4RDNS *string
IPv6RDNS *string
// PrivateIPv4 is the address the Load Balancer should have in the private
// network. The zero value when unconfigured.
PrivateIPv4 netip.Addr
// PrivateSubnetIPRange is the existing subnet to attach to. The zero value
// when unconfigured.
PrivateSubnetIPRange netip.Prefix
// UsePrivateIP makes server targets use their private IP.
UsePrivateIP bool
// PrivateIngress publishes the private IPs as ingress addresses.
PrivateIngress bool
// IPv6 publishes the public IPv6 address as an ingress address.
IPv6 bool
// Service applies to every port of the Kubernetes Service. Every HTTP and
// health check annotation is read from the Service, so only the listen and
// destination ports differ per port.
Service ServiceSpec
// OwnedCertificate is set when the Service asks the cloud controller
// manager to provide the certificate itself. The certificate is created
// and looked up by the caller.
OwnedCertificate *OwnedCertificate
}
Spec is the desired state of the Hetzner Cloud Load Balancer for a Service.
Pointer fields distinguish "not configured anywhere" (nil) from a configured value, so we never ask the API to change something the user never set.
func Resolve ¶
func Resolve(recorder record.EventRecorder, svc *corev1.Service, cfg config.LoadBalancerConfiguration) (Spec, error)
Resolve builds the desired state from the Service annotations and the cluster-wide Load Balancer configuration. Annotations take precedence over the configuration, which takes precedence over the built-in defaults.
All invalid annotations are reported together in the returned error. The returned Spec is still fully populated, with the offending settings left at their fallback, so callers must not use it when err is non-nil.
func (Spec) AddServerTargetOpts ¶
func (s Spec) AddServerTargetOpts(serverID int64) hcloud.LoadBalancerAddServerTargetOpts
func (Spec) AttachToNetworkOpts ¶
func (s Spec) AttachToNetworkOpts(network *hcloud.Network) hcloud.LoadBalancerAttachToNetworkOpts
func (Spec) ChangeAlgorithmOpts ¶
func (s Spec) ChangeAlgorithmOpts() hcloud.LoadBalancerChangeAlgorithmOpts
func (Spec) CreateOpts ¶
func (s Spec) CreateOpts(lbType *hcloud.LoadBalancerType) hcloud.LoadBalancerCreateOpts
func (Spec) UpdateOpts ¶
func (s Spec) UpdateOpts(lb *hcloud.LoadBalancer) (hcloud.LoadBalancerUpdateOpts, bool)