Skip to content

Commit

Permalink
feat: support for externally managed control plane
Browse files Browse the repository at this point in the history
Signed-off-by: Dario Tranchitella <[email protected]>
  • Loading branch information
prometherion committed Jul 1, 2024
1 parent 1cfdf0b commit f40f2f9
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 2 deletions.
3 changes: 3 additions & 0 deletions api/v1alpha1/conditions_consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ const (

// UnknownReason (Severity=Warning) documents the ProxmoxVM Unknown.
UnknownReason = "Unknown"

// MissingControlPlaneEndpointReason (Severity=Warning) documents the missing Control Plane endpoint when Cluster is backed by an externally managed Control Plane.
MissingControlPlaneEndpointReason = "MissingControlPlaneEndpoint"
)

const (
Expand Down
4 changes: 4 additions & 0 deletions api/v1alpha1/proxmoxcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ type ProxmoxClusterSpec struct {
// +kubebuilder:validation:XValidation:rule="self.port > 0 && self.port < 65536",message="port must be within 1-65535"
ControlPlaneEndpoint *clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`

// ExternalManagedControlPlane can be enabled to allow externally managed Control Planes to patch the
// Proxmox cluster with the Load Balancer IP provided by Control Plane provider.
ExternalManagedControlPlane bool `json:"externalManagedControlPlane,omitempty"`

// AllowedNodes specifies all Proxmox nodes which will be considered
// for operations. This implies that VMs can be cloned on different nodes from
// the node which holds the VM template.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,11 @@ spec:
type: string
minItems: 1
type: array
externalManagedControlPlane:
description: ExternalManagedControlPlane can be enabled to allow externally
managed Control Planes to patch the Proxmox cluster with the Load
Balancer IP provided by Control Plane provider.
type: boolean
ipv4Config:
description: IPv4Config contains information about available IPV4
address pools and the gateway. This can be combined with ipv6Config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,12 @@ spec:
type: string
minItems: 1
type: array
externalManagedControlPlane:
description: ExternalManagedControlPlane can be enabled to
allow externally managed Control Planes to patch the Proxmox
cluster with the Load Balancer IP provided by Control Plane
provider.
type: boolean
ipv4Config:
description: IPv4Config contains information about available
IPV4 address pools and the gateway. This can be combined
Expand Down
17 changes: 17 additions & 0 deletions internal/controller/proxmoxcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,23 @@ func (r *ProxmoxClusterReconciler) reconcileNormal(ctx context.Context, clusterS
// If the ProxmoxCluster doesn't have our finalizer, add it.
ctrlutil.AddFinalizer(clusterScope.ProxmoxCluster, infrav1alpha1.ClusterFinalizer)

if clusterScope.ProxmoxCluster.Spec.ExternalManagedControlPlane {
switch {
case clusterScope.ProxmoxCluster.Spec.ControlPlaneEndpoint.Host == "":
clusterScope.Logger.Info("ProxmoxCluster is not ready, missing or waiting for a ControlPlaneEndpoint host")

conditions.MarkFalse(clusterScope.ProxmoxCluster, infrav1alpha1.ProxmoxClusterReady, infrav1alpha1.MissingControlPlaneEndpointReason, clusterv1.ConditionSeverityWarning, "The ProxmoxCluster is missing or waiting for a ControlPlaneEndpoint host")

return ctrl.Result{Requeue: true}, nil
case clusterScope.ProxmoxCluster.Spec.ControlPlaneEndpoint.Port == 0:
clusterScope.Logger.Info("ProxmoxCluster is not ready, missing or waiting for a ControlPlaneEndpoint port")

conditions.MarkFalse(clusterScope.ProxmoxCluster, infrav1alpha1.ProxmoxClusterReady, infrav1alpha1.MissingControlPlaneEndpointReason, clusterv1.ConditionSeverityWarning, "The ProxmoxCluster is missing or waiting for a ControlPlaneEndpoint port")

return ctrl.Result{Requeue: true}, nil
}
}

res, err := r.reconcileIPAM(ctx, clusterScope)
if err != nil {
return ctrl.Result{}, err
Expand Down
8 changes: 6 additions & 2 deletions internal/webhook/proxmoxcluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,15 @@ func (*ProxmoxCluster) ValidateUpdate(_ context.Context, _ runtime.Object, newOb
}

func validateControlPlaneEndpoint(cluster *infrav1.ProxmoxCluster) error {
ep := cluster.Spec.ControlPlaneEndpoint
// Skipping the validation of the Control Plane endpoint in case of externally managed Control Plane:
// the Cluster API Control Plane provider will eventually provide the LB.
if cluster.Spec.ExternalManagedControlPlane {
return nil
}

gk, name := cluster.GroupVersionKind().GroupKind(), cluster.GetName()

endpoint := ep.Host
endpoint := cluster.Spec.ControlPlaneEndpoint.Host

addr, err := netip.ParseAddr(endpoint)

Expand Down

0 comments on commit f40f2f9

Please sign in to comment.