diff --git a/controllers/openstackcluster_controller.go b/controllers/openstackcluster_controller.go index dd275fe489..8f159fb728 100644 --- a/controllers/openstackcluster_controller.go +++ b/controllers/openstackcluster_controller.go @@ -170,10 +170,17 @@ func (r *OpenStackClusterReconciler) reconcileCluster(logger logr.Logger, cluste return reconcile.Result{}, errors.Errorf("failed to get control plane machine: %v", err) } if controlPlaneMachine != nil { + var apiPort int + if cluster.Spec.ClusterNetwork.APIServerPort == nil { + logger.Info("No API endpoint given, default to 6443") + apiPort = 6443 + } else { + apiPort = int(*cluster.Spec.ClusterNetwork.APIServerPort) + } openStackCluster.Status.APIEndpoints = []infrav1.APIEndpoint{ { Host: controlPlaneMachine.Spec.FloatingIP, - Port: int(*cluster.Spec.ClusterNetwork.APIServerPort), + Port: apiPort, }, } } else { diff --git a/examples/cluster/cluster.yaml b/examples/cluster/cluster.yaml index f68056a557..f540f5b37d 100644 --- a/examples/cluster/cluster.yaml +++ b/examples/cluster/cluster.yaml @@ -15,7 +15,7 @@ spec: # * Disable the apiServerPort property # single-node control-plane: # * Enable the apiServerPort property - #apiServerPort: 6443 + apiServerPort: infrastructureRef: apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2 kind: OpenStackCluster