Skip to content
Merged
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
16 changes: 10 additions & 6 deletions cloud/scope/powervs_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1955,6 +1955,8 @@ func (s *PowerVSClusterScope) ReconcileLoadBalancers() (bool, error) {
loadBalancers = append(loadBalancers, s.IBMPowerVSCluster.Spec.LoadBalancers...)
}

isAnyLoadBalancerNotReady := false

for index, loadBalancer := range loadBalancers {
var loadBalancerID *string
if loadBalancer.ID != nil {
Expand All @@ -1974,8 +1976,9 @@ func (s *PowerVSClusterScope) ReconcileLoadBalancers() (bool, error) {
return false, err
}

if requeue := s.checkLoadBalancerStatus(*loadBalancer); requeue {
return requeue, nil
if isReady := s.checkLoadBalancerStatus(*loadBalancer); !isReady {
s.V(3).Info("LoadBalancer is still not Active", "name", *loadBalancer.Name, "state", *loadBalancer.ProvisioningStatus)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*loadbalancer.Name can be nil when user sets only id. so better avoid it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's coming from cloud API resp right, would be able to create a LB without name?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah, sorry, I overlooked loadbalancer from

for index, loadBalancer := range loadBalancers {

isAnyLoadBalancerNotReady = true
}

loadBalancerStatus := infrav1beta2.VPCLoadBalancerStatus{
Expand Down Expand Up @@ -2012,25 +2015,26 @@ func (s *PowerVSClusterScope) ReconcileLoadBalancers() (bool, error) {
}
s.Info("Created VPC load balancer", "loadBalancerID", loadBalancerStatus.ID)
s.SetLoadBalancerStatus(loadBalancer.Name, *loadBalancerStatus)
isAnyLoadBalancerNotReady = true
}
if isAnyLoadBalancerNotReady {
return false, nil
}
return true, nil
}

// checkLoadBalancerStatus checks the state of a VPC load balancer.
// If state is pending, true is returned indicating a requeue for reconciliation.
// In all other cases, it returns false.
// If state is active, true is returned, in all other cases, it returns false indicating that load balancer is still not ready.
func (s *PowerVSClusterScope) checkLoadBalancerStatus(lb vpcv1.LoadBalancer) bool {
s.V(3).Info("Checking the status of VPC load balancer", "name", *lb.Name)
switch *lb.ProvisioningStatus {
case string(infrav1beta2.VPCLoadBalancerStateActive):
s.V(3).Info("VPC load balancer is in active state")
return true
case string(infrav1beta2.VPCLoadBalancerStateCreatePending):
s.V(3).Info("VPC load balancer creation is in pending state")
return true
case string(infrav1beta2.VPCLoadBalancerStateUpdatePending):
s.V(3).Info("VPC load balancer is in updating state")
return true
}
return false
}
Expand Down