Skip to content

Commit

Permalink
feat: making control plane endpoint fields optional
Browse files Browse the repository at this point in the history
Signed-off-by: Dario Tranchitella <[email protected]>
  • Loading branch information
prometherion authored and wikkyk committed Jun 7, 2024
1 parent 6260356 commit e2b7a89
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
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.
MissingControlPlaneEndpointReason = "MissingControlPlaneEndpoint"
)

const (
Expand Down
16 changes: 16 additions & 0 deletions internal/controller/proxmoxcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,22 @@ func (r *ProxmoxClusterReconciler) reconcileNormal(ctx context.Context, clusterS
// If the ProxmoxCluster doesn't have our finalizer, add it.
ctrlutil.AddFinalizer(clusterScope.ProxmoxCluster, infrav1alpha1.ClusterFinalizer)

cpe := clusterScope.ControlPlaneEndpoint()
switch {
case cpe.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 cpe.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: 7 additions & 1 deletion internal/webhook/proxmoxcluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ import (
"regexp"
"strings"

infrav1 "github.com/ionos-cloud/cluster-api-provider-proxmox/api/v1alpha1"
"github.com/pkg/errors"
"go4.org/netipx"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"

infrav1 "github.com/ionos-cloud/cluster-api-provider-proxmox/api/v1alpha1"
)

var _ admission.CustomValidator = &ProxmoxCluster{}
Expand Down Expand Up @@ -94,6 +95,11 @@ 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 an empty value:
// this is the case of externally managed Control Plane which eventually provides the LB.
if ep.Host == "" && ep.Port == 0 {
return nil
}

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

Expand Down

0 comments on commit e2b7a89

Please sign in to comment.