Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions api/v1beta1/conditions_consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ const (
LoadBalancerMachineReconciliationFailedReason = "MachineReconciliationFailed"
// LoadBalancerAddressUnavailableReason used when waiting for loadbalancer to have an address.
LoadBalancerAddressUnavailableReason = "AddressUnavailable"
// LoadBalancerVIPOutOfRangeReason used when provided Load Balancer VIP is out of the vip address range.
LoadBalancerVIPOutOfRangeReason = "LoadBalancerVIPOutOfRange"
// LoadBalancerNoReplicasReadyReason used when no replicas are in a ready state.
LoadBalancerNoReplicasReadyReason = "NoReplicasReady"

Expand Down
46 changes: 46 additions & 0 deletions controllers/azurestackhciloadbalancer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,19 @@ package controllers
import (
"context"
"fmt"
"net"
"time"

"github.com/go-logr/logr"
infrav1 "github.com/microsoft/cluster-api-provider-azurestackhci/api/v1beta1"
azurestackhci "github.com/microsoft/cluster-api-provider-azurestackhci/cloud"
"github.com/microsoft/cluster-api-provider-azurestackhci/cloud/scope"
"github.com/microsoft/cluster-api-provider-azurestackhci/cloud/services/loadbalancers"
"github.com/microsoft/cluster-api-provider-azurestackhci/cloud/services/virtualnetworks"
infrav1util "github.com/microsoft/cluster-api-provider-azurestackhci/pkg/util"
"github.com/microsoft/moc-sdk-for-go/services/network"
mocerrors "github.com/microsoft/moc/pkg/errors"
mocnet "github.com/microsoft/moc/pkg/net"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -223,6 +226,13 @@ func (r *AzureStackHCILoadBalancerReconciler) reconcileNormal(lbs *scope.LoadBal
}
}

err = r.reconcileLoadBalancerVIP(lbs, clusterScope)
if err != nil {
r.Recorder.Eventf(lbs.AzureStackHCILoadBalancer, corev1.EventTypeWarning, "FailureReconcileLBVIP", errors.Wrapf(err, "Failed to reconcile Load Balancer VIP").Error())
conditions.MarkFalse(lbs.AzureStackHCILoadBalancer, infrav1.LoadBalancerInfrastructureReadyCondition, infrav1.LoadBalancerVIPOutOfRangeReason, clusterv1.ConditionSeverityError, err.Error())
return reconcile.Result{}, err
}

// When a SDN integration is present, LB replica count will be 0 as the loadbalancing is handled by SDN.
// So fail only if the configured replica count is not 0.
if lbs.GetReplicas() != 0 && lbs.GetReadyReplicas() < 1 {
Expand Down Expand Up @@ -370,3 +380,39 @@ func (r *AzureStackHCILoadBalancerReconciler) reconcileStatus(lbs *scope.LoadBal

lbs.SetPhase(infrav1.AzureStackHCILoadBalancerPhaseProvisioned)
}

func (r *AzureStackHCILoadBalancerReconciler) reconcileLoadBalancerVIP(lbs *scope.LoadBalancerScope, clusterScope *scope.ClusterScope) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we find out what would happening when Arc Vnets is used


lbs.Info("Attempting to get vnet for loadbalancer vip", "name", lbs.AzureStackHCILoadBalancer.Name)
vnetSpec := &virtualnetworks.Spec{
Name: clusterScope.AzureStackHCICluster.Spec.NetworkSpec.Vnet.Name,
Group: clusterScope.AzureStackHCICluster.Spec.NetworkSpec.Vnet.Group,
}
vnetInterface, err := virtualnetworks.NewService(clusterScope).Get(clusterScope.Context, vnetSpec)
if err != nil {
return err
}

vnet, ok := vnetInterface.(network.VirtualNetwork)
if !ok {
return errors.New("error getting virtualnetwork service")
}

lbVIP := net.ParseIP(lbs.Address())

for _, subnet := range *vnet.Subnets {
for _, ippool := range subnet.IPPools {

if ippool.Type == network.VIPPOOL {
startVIP := net.ParseIP(ippool.Start)
endVIP := net.ParseIP(ippool.End)

if mocnet.RangeContains(startVIP, endVIP, lbVIP) {
return nil
}
}
}
}

return errors.Errorf("Load Balancer VIP out of VIP Pool range.")
}