Skip to content

Add error reason for control plane out of range. #253

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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.")
}