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

feat: add controller for external load balancer #101

Open
wants to merge 7 commits into
base: rcfeat_add_api_types_for_external_load_b
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions api/v1alpha1/condition_consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,15 @@ const (
// to be available before proceeding.
WaitingForBootstrapDataReason = "WaitingForBoostrapData"
)

const (
// ExternalLoadBalancerEndpointAvailableCondition is a condition that indicates that the API server Load Balancer is available.
ExternalLoadBalancerEndpointAvailableCondition clusterv1.ConditionType = "ExternalLoadBalancerEndpointAvailable"

// ExternalLoadBalancerEndpointNotAvailableReason is used to indicate any error with the
// availability of the load balancer.
ExternalLoadBalancerEndpointFailedReason = "ExternalLoadBalancerEndpointFailed"

// ExternalLoadBalancerEndpointNotAvailableReason is used to indicate that the load balancer isn't available.
ExternalLoadBalancerEndpointNotAvailableReason = "ExternalLoadBalancerEndpointNotAvailable"
)
24 changes: 22 additions & 2 deletions api/v1alpha1/externalloadbalancer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,35 @@
package v1alpha1

import (
"strconv"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

type ExternalLoadBalancerEndpoint struct {
// The hostname on which the API server is serving.
// +required
Host string `json:"host"`

// The port on which the API server is serving.
// +optional
// +kubebuilder:default=6443
Port int32 `json:"port"`
}

func (ep *ExternalLoadBalancerEndpoint) String() string {
port := strconv.Itoa(int(ep.Port))

return ep.Host + ":" + port
}

// ExternalLoadBalancerSpec defines the desired state for a ExternalLoadBalancer.
type ExternalLoadBalancerSpec struct {
// Endpoint represents the endpoint for the load balancer. This endpoint will
// best tested to see if its available.
Endpoint clusterv1.APIEndpoint `json:"endpoint"`
// be tested to see if its available.
Endpoint ExternalLoadBalancerEndpoint `json:"endpoint"`
ClusterName string `json:"clusterName"`
}

type ExternalLoadBalancerStatus struct {
Expand Down
10 changes: 3 additions & 7 deletions api/v1alpha1/microvmcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@
package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

// MicrovmClusterSpec defines the desired state of MicrovmCluster.
type MicrovmClusterSpec struct {
// ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
//
// See https://cluster-api.sigs.k8s.io/developer/architecture/controllers/cluster.html
// for more details.
//
// +optional
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`
// SSHPublicKey is an SSH public key that will be used with the default user. If specified
// this will apply to all machine created unless you specify a different key at the
// machine level.
Expand All @@ -25,6 +19,8 @@ type MicrovmClusterSpec struct {
// Placement specifies how machines for the cluster should be placed onto hosts (i.e. where the microvms are created).
// +kubebuilder:validation:Required
Placement Placement `json:"placement"`
// LoadBalancerRef
LoadBalancerRef *corev1.ObjectReference `json:"loadBalancerRef,omitempty"`
}

// MicrovmClusterStatus defines the observed state of MicrovmCluster.
Expand Down
22 changes: 21 additions & 1 deletion api/v1alpha1/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 @@ -50,22 +50,25 @@ spec:
description: ExternalLoadBalancerSpec defines the desired state for a
ExternalLoadBalancer.
properties:
clusterName:
type: string
endpoint:
description: Endpoint represents the endpoint for the load balancer.
This endpoint will best tested to see if its available.
This endpoint will be tested to see if its available.
properties:
host:
description: The hostname on which the API server is serving.
type: string
port:
default: 6443
description: The port on which the API server is serving.
format: int32
type: integer
required:
- host
- port
type: object
required:
- clusterName
- endpoint
type: object
status:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,41 @@ spec:
spec:
description: MicrovmClusterSpec defines the desired state of MicrovmCluster.
properties:
controlPlaneEndpoint:
description: "ControlPlaneEndpoint represents the endpoint used to
communicate with the control plane. \n See https://cluster-api.sigs.k8s.io/developer/architecture/controllers/cluster.html
for more details."
loadBalancerRef:
description: LoadBalancerRef
properties:
host:
description: The hostname on which the API server is serving.
apiVersion:
description: API version of the referent.
type: string
fieldPath:
description: 'If referring to a piece of an object instead of
an entire object, this string should contain a valid JSON/Go
field access statement, such as desiredState.manifest.containers[2].
For example, if the object reference is to a container within
a pod, this would take on a value like: "spec.containers{name}"
(where "name" refers to the name of the container that triggered
the event) or if no container name is specified "spec.containers[2]"
(container with index 2 in this pod). This syntax is chosen
only to have some well-defined way of referencing a part of
an object. TODO: this design is not final and this field is
subject to change in the future.'
type: string
kind:
description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names'
type: string
namespace:
description: 'Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/'
type: string
resourceVersion:
description: 'Specific resourceVersion to which this reference
is made, if any. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency'
type: string
uid:
description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids'
type: string
port:
description: The port on which the API server is serving.
format: int32
type: integer
required:
- host
- port
type: object
placement:
description: Placement specifies how machines for the cluster should
Expand Down
1 change: 1 addition & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ resources:
- bases/infrastructure.cluster.x-k8s.io_microvmclusters.yaml
- bases/infrastructure.cluster.x-k8s.io_microvmmachines.yaml
- bases/infrastructure.cluster.x-k8s.io_microvmmachinetemplates.yaml
- bases/infrastructure.cluster.x-k8s.io_externalloadbalancers.yaml
#+kubebuilder:scaffold:crdkustomizeresource

patchesStrategicMerge:
Expand Down
20 changes: 20 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,26 @@ rules:
- get
- list
- watch
- apiGroups:
- infrastructure.cluster.x-k8s.io
resources:
- externalloadbalancers
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- infrastructure.cluster.x-k8s.io
resources:
- externalloadbalancers/status
verbs:
- get
- patch
- update
- apiGroups:
- infrastructure.cluster.x-k8s.io
resources:
Expand Down
13 changes: 7 additions & 6 deletions controllers/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ package controllers
import "errors"

var (
errControlplaneEndpointRequired = errors.New("controlplane endpoint is required on cluster or mvmcluster")
errClientFactoryFuncRequired = errors.New("factory function required to create grpc client")
errMicrovmFailed = errors.New("microvm is in a failed state")
errMicrovmUnknownState = errors.New("microvm is in an unknown/unsupported state")
errExpectedMicrovmCluster = errors.New("expected microvm cluster")
errNoPlacement = errors.New("no placement specified")
errExternalLoadBalancerEndpointRefRequired = errors.New("endpointRef is required on mvmcluster")
errClientFactoryFuncRequired = errors.New("factory function required to create grpc client")
errMicrovmFailed = errors.New("microvm is in a failed state")
errMicrovmUnknownState = errors.New("microvm is in an unknown/unsupported state")
errExpectedMicrovmCluster = errors.New("expected microvm cluster")
errNoPlacement = errors.New("no placement specified")
errInvalidLoadBalancerResponseStatusCode = errors.New("endpoint returned a 5XX status code")
)
Loading