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: support for externally managed control plane #106

Merged
merged 6 commits into from
Nov 4, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -42,6 +42,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 @@ -615,6 +615,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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,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.
Expand Down
24 changes: 24 additions & 0 deletions internal/controller/proxmoxcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,30 @@ 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 {
if clusterScope.ProxmoxCluster.Spec.ControlPlaneEndpoint == nil {
clusterScope.Logger.Info("ProxmoxCluster is not ready, missing or waiting for a ControlPlaneEndpoint")

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

return ctrl.Result{Requeue: true}, nil
}
if clusterScope.ProxmoxCluster.Spec.ControlPlaneEndpoint.Host == "" {
wikkyk marked this conversation as resolved.
Show resolved Hide resolved
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
}
if 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
}
}

// when a Cluster is marked failed cause the Proxmox client is nil.
// the cluster doesn't reconcile the failed state if we restart the controller.
// so we need to check if the ProxmoxClient is not nil and the ProxmoxCluster has a failure reason.
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