Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚠️ Refactors loadbalancer target. Changes services to extraTarget. #45

Merged
merged 2 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 17 additions & 4 deletions api/v1beta1/hetznercluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,28 @@ type LoadBalancerSpec struct {
// +optional
Name *string `json:"name,omitempty"`

// Could be round-robin or least-connection
Algorithm LoadBalancerAlgorithmType `json:"algorithm"`
// Could be round_robin or least_connection. The default value is "round_robin".
// +optional
// +kubebuilder:validation:Enum=round_robin;least_connections
// +kubebuilder:default=round_robin
Algorithm LoadBalancerAlgorithmType `json:"algorithm,omitempty"`

// Loadbalancer type
// +optional
// +kubebuilder:validation:Enum=lb11;lb21;lb31
Type string `json:"type"`
// +kubebuilder:default=lb11
Type string `json:"type,omitempty"`

// API Server port. It must be valid ports range (1-65535). If omitted, default value is 6443.
// +optional
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=65535
// +kubebuilder:default=6443
Port int `json:"port,omitempty"`

// Defines how traffic will be routed from the Load Balancer to your target server.
Services []LoadBalancerServiceSpec `json:"services"`
// +optional
Targets []LoadBalancerTargetSpec `json:"extraTarget,omitempty"`

Region Region `json:"region"`
}
Expand Down
22 changes: 16 additions & 6 deletions api/v1beta1/network_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,22 @@ func (s *HCloudNetworkSpec) IsZero() bool {
return true
}

// LoadBalancerServiceSpec defines a Loadbalncer Service.
type LoadBalancerServiceSpec struct {
// http, https, tcp
Protocol string `json:"protocol"`
// LoadBalancerTargetSpec defines a Loadbalancer Target.
type LoadBalancerTargetSpec struct {
// Protocol specifies the supported Loadbalancer Protocol.
// +optional
// +kubebuilder:validation:Enum=http;https;tcp
Protocol string `json:"protocol,omitempty"`

// Equal Source port, defines the incoming port open on the loadbalancer
ListenPort int `json:"listenPort"`
// +optional
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=65535
ListenPort int `json:"listenPort,omitempty"`

// Defines the port on the server
DestinationPort int `json:"destinationPort"`
// +optional
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=65535
DestinationPort int `json:"destinationPort,omitempty"`
}
36 changes: 18 additions & 18 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -75,55 +75,71 @@ spec:
cluster-api project.
properties:
algorithm:
description: Could be round-robin or least-connection
enum:
- round_robin
- least_connections
type: string
name:
type: string
region:
description: Region is a Hetzner Location
enum:
- fsn1
- hel1
- nbg1
- ash
allOf:
- enum:
- round_robin
- least_connections
- enum:
- round_robin
- least_connections
default: round_robin
description: Could be round_robin or least_connection. The default
value is "round_robin".
type: string
services:
extraTarget:
description: Defines how traffic will be routed from the Load
Balancer to your target server.
items:
description: LoadBalancerServiceSpec defines a Loadbalncer Service.
description: LoadBalancerTargetSpec defines a Loadbalancer Target.
properties:
destinationPort:
description: Defines the port on the server
maximum: 65535
minimum: 1
type: integer
listenPort:
description: Equal Source port, defines the incoming port
open on the loadbalancer
maximum: 65535
minimum: 1
type: integer
protocol:
description: http, https, tcp
description: Protocol specifies the supported Loadbalancer
Protocol.
enum:
- http
- https
- tcp
type: string
required:
- destinationPort
- listenPort
- protocol
type: object
type: array
name:
type: string
port:
default: 6443
description: API Server port. It must be valid ports range (1-65535).
If omitted, default value is 6443.
maximum: 65535
minimum: 1
type: integer
region:
description: Region is a Hetzner Location
enum:
- fsn1
- hel1
- nbg1
- ash
type: string
type:
default: lb11
description: Loadbalancer type
enum:
- lb11
- lb21
- lb31
type: string
required:
- algorithm
- region
- services
- type
type: object
controlPlaneRegion:
description: ControlPlaneRegion consists of a list of HCloud Regions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,56 +110,72 @@ spec:
is from upstream cluster-api project.
properties:
algorithm:
description: Could be round-robin or least-connection
enum:
- round_robin
- least_connections
type: string
name:
type: string
region:
description: Region is a Hetzner Location
enum:
- fsn1
- hel1
- nbg1
- ash
allOf:
- enum:
- round_robin
- least_connections
- enum:
- round_robin
- least_connections
default: round_robin
description: Could be round_robin or least_connection.
The default value is "round_robin".
type: string
services:
extraTarget:
description: Defines how traffic will be routed from the
Load Balancer to your target server.
items:
description: LoadBalancerServiceSpec defines a Loadbalncer
Service.
description: LoadBalancerTargetSpec defines a Loadbalancer
Target.
properties:
destinationPort:
description: Defines the port on the server
maximum: 65535
minimum: 1
type: integer
listenPort:
description: Equal Source port, defines the incoming
port open on the loadbalancer
maximum: 65535
minimum: 1
type: integer
protocol:
description: http, https, tcp
description: Protocol specifies the supported Loadbalancer
Protocol.
enum:
- http
- https
- tcp
type: string
required:
- destinationPort
- listenPort
- protocol
type: object
type: array
name:
type: string
port:
default: 6443
description: API Server port. It must be valid ports range
(1-65535). If omitted, default value is 6443.
maximum: 65535
minimum: 1
type: integer
region:
description: Region is a Hetzner Location
enum:
- fsn1
- hel1
- nbg1
- ash
type: string
type:
default: lb11
description: Loadbalancer type
enum:
- lb11
- lb21
- lb31
type: string
required:
- algorithm
- region
- services
- type
type: object
controlPlaneRegion:
description: ControlPlaneRegion consists of a list of HCloud
Expand Down
2 changes: 1 addition & 1 deletion controllers/hetznercluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func (r *HetznerClusterReconciler) reconcileNormal(ctx context.Context, clusterS
// destinationPort as default
if hetznerCluster.Status.ControlPlaneLoadBalancer.IPv4 != "<nil>" {
var defaultHost = hetznerCluster.Status.ControlPlaneLoadBalancer.IPv4
var defaultPort = int32(hetznerCluster.Spec.ControlPlaneLoadBalancer.Services[0].DestinationPort)
var defaultPort = int32(hetznerCluster.Spec.ControlPlaneLoadBalancer.Port)

if hetznerCluster.Spec.ControlPlaneEndpoint == nil {
hetznerCluster.Spec.ControlPlaneEndpoint = &clusterv1.APIEndpoint{
Expand Down
5 changes: 5 additions & 0 deletions pkg/scope/hcloud_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type HCloudClient interface {
AddTargetServerToLoadBalancer(context.Context, hcloud.LoadBalancerAddServerTargetOpts, *hcloud.LoadBalancer) (*hcloud.Action, *hcloud.Response, error)
DeleteTargetServerOfLoadBalancer(context.Context, *hcloud.LoadBalancer, *hcloud.Server) (*hcloud.Action, *hcloud.Response, error)
AddServiceToLoadBalancer(context.Context, *hcloud.LoadBalancer, hcloud.LoadBalancerAddServiceOpts) (*hcloud.Action, *hcloud.Response, error)
DeleteServiceFromLoadBalancer(context.Context, *hcloud.LoadBalancer, int) (*hcloud.Action, *hcloud.Response, error)
ListImages(context.Context, hcloud.ImageListOpts) ([]*hcloud.Image, error)
CreateServer(context.Context, hcloud.ServerCreateOpts) (hcloud.ServerCreateResult, *hcloud.Response, error)
AttachServerToNetwork(context.Context, *hcloud.Server, hcloud.ServerAttachToNetworkOpts) (*hcloud.Action, *hcloud.Response, error)
Expand Down Expand Up @@ -111,6 +112,10 @@ func (c *realHCloudClient) AddServiceToLoadBalancer(ctx context.Context, lb *hcl
return c.client.LoadBalancer.AddService(ctx, lb, opts)
}

func (c *realHCloudClient) DeleteServiceFromLoadBalancer(ctx context.Context, lb *hcloud.LoadBalancer, listenPort int) (*hcloud.Action, *hcloud.Response, error) {
return c.client.LoadBalancer.DeleteService(ctx, lb, listenPort)
}

func (c *realHCloudClient) ListImages(ctx context.Context, opts hcloud.ImageListOpts) ([]*hcloud.Image, error) {
return c.client.Image.AllWithOpts(ctx, opts)
}
Expand Down