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

🌱Added function to update control plane endpoint #1004

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
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
55 changes: 30 additions & 25 deletions controllers/hetznercluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,31 +198,9 @@ func (r *HetznerClusterReconciler) reconcileNormal(ctx context.Context, clusterS
if err := placementgroup.NewService(clusterScope).Reconcile(ctx); err != nil {
return reconcile.Result{}, fmt.Errorf("failed to reconcile placement groups for HetznerCluster %s/%s: %w", hetznerCluster.Namespace, hetznerCluster.Name, err)
}

if hetznerCluster.Spec.ControlPlaneLoadBalancer.Enabled {
if hetznerCluster.Status.ControlPlaneLoadBalancer.IPv4 != "<nil>" {
defaultHost := hetznerCluster.Status.ControlPlaneLoadBalancer.IPv4
defaultPort := int32(hetznerCluster.Spec.ControlPlaneLoadBalancer.Port)

if hetznerCluster.Spec.ControlPlaneEndpoint == nil {
hetznerCluster.Spec.ControlPlaneEndpoint = &clusterv1.APIEndpoint{
Host: defaultHost,
Port: defaultPort,
}
} else {
if hetznerCluster.Spec.ControlPlaneEndpoint.Host == "" {
hetznerCluster.Spec.ControlPlaneEndpoint.Host = defaultHost
}
if hetznerCluster.Spec.ControlPlaneEndpoint.Port == 0 {
hetznerCluster.Spec.ControlPlaneEndpoint.Port = defaultPort
}
}

hetznerCluster.Status.Ready = true
}
} else if hetznerCluster.Spec.ControlPlaneEndpoint != nil {
hetznerCluster.Status.Ready = true
}

// update control plane endpoint
hetznerCluster.Status.Ready = SetControlPlaneEndpoint(hetznerCluster)

// delete deprecated conditions of old clusters
conditions.Delete(clusterScope.HetznerCluster, infrav1.DeprecatedHetznerClusterTargetClusterReadyCondition)
Expand Down Expand Up @@ -260,6 +238,33 @@ func (r *HetznerClusterReconciler) reconcileNormal(ctx context.Context, clusterS
return reconcile.Result{}, nil
}

func SetControlPlaneEndpoint(hetznerCluster *infrav1.HetznerCluster) (bool) {
if hetznerCluster.Spec.ControlPlaneLoadBalancer.Enabled {
if hetznerCluster.Status.ControlPlaneLoadBalancer.IPv4 != "<nil>" {
defaultHost := hetznerCluster.Status.ControlPlaneLoadBalancer.IPv4
defaultPort := int32(hetznerCluster.Spec.ControlPlaneLoadBalancer.Port)

if hetznerCluster.Spec.ControlPlaneEndpoint == nil {
hetznerCluster.Spec.ControlPlaneEndpoint = &clusterv1.APIEndpoint{
janiskemper marked this conversation as resolved.
Show resolved Hide resolved
Host: defaultHost,
Port: defaultPort,
}
} else {
if hetznerCluster.Spec.ControlPlaneEndpoint.Host == "" {
hetznerCluster.Spec.ControlPlaneEndpoint.Host = defaultHost
}
if hetznerCluster.Spec.ControlPlaneEndpoint.Port == 0 {
hetznerCluster.Spec.ControlPlaneEndpoint.Port = defaultPort
}
}
return true
}
} else if hetznerCluster.Spec.ControlPlaneEndpoint != nil {
return true
}
return false
}

func (r *HetznerClusterReconciler) reconcileDelete(ctx context.Context, clusterScope *scope.ClusterScope) (reconcile.Result, error) {
hetznerCluster := clusterScope.HetznerCluster

Expand Down
Loading