Skip to content

Commit 6e15b75

Browse files
committed
fixed issue when cluster configuration changes to using IP pools from DHCP and IP would still fail to be set
Signed-off-by: Mohamed Belgaied Hassine <belgaied2@hotmail.com>
1 parent 94c5b86 commit 6e15b75

1 file changed

Lines changed: 26 additions & 14 deletions

File tree

controllers/harvestercluster_controller.go

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ const (
7373
cpVMLabelValuePrefix = "controlplane"
7474
requeueTimeThirtySeconds = 30 * time.Second
7575
requeueTimeFiveMinutes = 5 * time.Minute
76+
dhcpLbIP = "0.0.0.0"
7677
)
7778

7879
// HarvesterClusterReconciler reconciles a HarvesterCluster object.
@@ -293,7 +294,7 @@ func (r *HarvesterClusterReconciler) ReconcileNormal(scope ClusterScope) (res ct
293294

294295
return ctrl.Result{RequeueAfter: requeueTimeFiveMinutes}, err1
295296
} else {
296-
lbIP := "0.0.0.0"
297+
lbIP := dhcpLbIP
297298
if scope.HarvesterCluster.Spec.LoadBalancerConfig.IPAMType == infrav1.POOL {
298299
lbIP, err = getIPFromIPPool(scope, lbNamespacedName)
299300
if err != nil {
@@ -357,31 +358,42 @@ func (r *HarvesterClusterReconciler) ReconcileNormal(scope ClusterScope) (res ct
357358
logger.Info("placeholder LoadBalancer IP is empty, waiting for IP to be set ...")
358359

359360
if scope.HarvesterCluster.Spec.LoadBalancerConfig.IPAMType == infrav1.POOL {
361+
newLbIP := dhcpLbIP
362+
360363
ipPool, err := scope.HarvesterClient.LoadbalancerV1beta1().IPPools().Get(context.TODO(),
361364
scope.HarvesterCluster.Spec.LoadBalancerConfig.IpPoolRef, v1.GetOptions{})
362365
if err != nil {
363366
return ctrl.Result{RequeueAfter: requeueTimeThirtySeconds}, err
364367
}
365368

366-
if ipPool.Status.AllocatedHistory == nil {
367-
return ctrl.Result{RequeueAfter: requeueTimeThirtySeconds}, fmt.Errorf("IP Pool %s does not have any allocated IPs", ipPool.Name)
369+
if ipPool.Status.AllocatedHistory != nil {
370+
for k, v := range ipPool.Status.AllocatedHistory {
371+
if lbNamespacedName == v {
372+
newLbIP = k
373+
}
374+
}
375+
}
376+
377+
if newLbIP == dhcpLbIP {
378+
newLbIP, err = getIPFromIPPool(scope, lbNamespacedName)
379+
if err != nil {
380+
return ctrl.Result{RequeueAfter: requeueTimeThirtySeconds}, err
381+
}
368382
}
369383

370-
for k, v := range ipPool.Status.AllocatedHistory {
371-
if lbNamespacedName == v {
372-
existingPlaceholderLB.Spec.LoadBalancerIP = k
384+
existingPlaceholderLB.Spec.LoadBalancerIP = newLbIP
373385

374-
_, err = scope.HarvesterClient.CoreV1().Services(scope.HarvesterCluster.Spec.TargetNamespace).Update(context.TODO(),
375-
existingPlaceholderLB, v1.UpdateOptions{})
376-
if err != nil {
377-
err = errors.Wrap(err, "could not update the placeholder LoadBalancer")
386+
_, err = scope.HarvesterClient.CoreV1().Services(scope.HarvesterCluster.Spec.TargetNamespace).Update(context.TODO(),
387+
existingPlaceholderLB, v1.UpdateOptions{})
388+
if err != nil {
389+
err = errors.Wrap(err, "could not update the placeholder LoadBalancer")
378390

379-
return ctrl.Result{RequeueAfter: requeueTimeThirtySeconds}, err
380-
}
381-
}
391+
return ctrl.Result{RequeueAfter: requeueTimeThirtySeconds}, err
382392
}
383393

384-
return ctrl.Result{RequeueAfter: requeueTimeThirtySeconds}, nil
394+
logger.Info("placeholder LoadBalancer IP updated successfully using IP Pools", "IP", newLbIP)
395+
396+
return ctrl.Result{Requeue: true}, nil
385397
} else {
386398
return ctrl.Result{RequeueAfter: requeueTimeThirtySeconds}, nil
387399
}

0 commit comments

Comments
 (0)