diff --git a/pkg/cloud/isolated_network.go b/pkg/cloud/isolated_network.go index 974229ee..65a9e60c 100644 --- a/pkg/cloud/isolated_network.go +++ b/pkg/cloud/isolated_network.go @@ -18,6 +18,7 @@ package cloud import ( "fmt" + "k8s.io/klog/v2" "slices" "strconv" "strings" @@ -247,11 +248,17 @@ func (c *client) ReconcileLoadBalancerRules(isoNet *infrav1.CloudStackIsolatedNe ports = append(ports, csCluster.Spec.APIServerLoadBalancer.AdditionalPorts...) } + logger := klog.Background() + logger.Info("reconciling load balancer rules", "ports", ports, "portsAndIDs", portsAndIDs) + lbRuleIDs := make([]string, 0) + logger.Info("lbRuleIDs", "lbRuleIDs", lbRuleIDs, "length", len(lbRuleIDs)) for _, port := range ports { // Check if lb rule for port already exists + logger.Info("Checking if rule exists", "port", port) ruleID, found := portsAndIDs[strconv.Itoa(port)] if found { + logger.Info("Rule found", "ruleID", ruleID) lbRuleIDs = append(lbRuleIDs, ruleID) } else { // If not found, create the lb rule for port @@ -259,8 +266,10 @@ func (c *client) ReconcileLoadBalancerRules(isoNet *infrav1.CloudStackIsolatedNe if err != nil { return errors.Wrap(err, "creating load balancer rule") } + logger.Info("Rule not found & created", "ruleID", ruleID) lbRuleIDs = append(lbRuleIDs, ruleID) } + logger.Info("lbRuleIDs", "lbRuleIDs", lbRuleIDs, "length", len(lbRuleIDs)) // For backwards compatibility. if port == int(csCluster.Spec.ControlPlaneEndpoint.Port) { @@ -282,12 +291,9 @@ func (c *client) ReconcileLoadBalancerRules(isoNet *infrav1.CloudStackIsolatedNe } } } - - if len(lbRuleIDs) > 1 { - capcstrings.Canonicalize(lbRuleIDs) - } - - isoNet.Status.LoadBalancerRuleIDs = lbRuleIDs + // Update isoNet status with the current list of loadbalancer rule ID's. + logger.Info("ReconcileLoadBalancerRules done", "lbRuleIDs", lbRuleIDs, "length", len(lbRuleIDs)) + isoNet.Status.LoadBalancerRuleIDs = capcstrings.Canonicalize(lbRuleIDs) return nil }