From 3669e52d611c88bc8e92645cbca5dd48a24eb51d Mon Sep 17 00:00:00 2001 From: shysank Date: Thu, 17 Mar 2022 10:04:41 -0700 Subject: [PATCH] fix outbound lb conversion for v1alpha3 clusters --- api/v1alpha3/azurecluster_conversion.go | 41 +++++++++++++----------- api/v1beta1/azurecluster_default.go | 8 ++--- api/v1beta1/azurecluster_default_test.go | 4 +-- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/api/v1alpha3/azurecluster_conversion.go b/api/v1alpha3/azurecluster_conversion.go index 5f3b5a8dda4..bfbb4d1c7a6 100644 --- a/api/v1alpha3/azurecluster_conversion.go +++ b/api/v1alpha3/azurecluster_conversion.go @@ -42,12 +42,35 @@ func (src *AzureCluster) ConvertTo(dstRaw conversion.Hub) error { dst.Annotations = nil } } + + // set default control plane outbound lb for private v1alpha3 clusters. + if src.Spec.NetworkSpec.APIServerLB.Type == Internal { + dst.Spec.NetworkSpec.ControlPlaneOutboundLB = &infrav1beta1.LoadBalancerSpec{ + FrontendIPsCount: pointer.Int32Ptr(1), + } + // We also need to set the defaults here because "get" won't set defaults, and hence there is no mismatch when a client + // gets a v1alpha3 cluster. + dst.SetControlPlaneOutboundLBDefaults() + } + + // set default node plane outbound lb for all v1alpha3 clusters. + dst.Spec.NetworkSpec.NodeOutboundLB = &infrav1beta1.LoadBalancerSpec{ + FrontendIPsCount: pointer.Int32Ptr(1), + } + // We also need to set the defaults here because "get" won't set defaults, and hence there is no mismatch when a client + // gets a v1alpha3 cluster. + dst.SetNodeOutboundLBDefaults() + // Manually restore data. restored := &infrav1beta1.AzureCluster{} if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok { return err } + // override outbound lb if it's present in restored. + dst.Spec.NetworkSpec.ControlPlaneOutboundLB = restored.Spec.NetworkSpec.ControlPlaneOutboundLB + dst.Spec.NetworkSpec.NodeOutboundLB = restored.Spec.NetworkSpec.NodeOutboundLB + dst.Spec.NetworkSpec.PrivateDNSZoneName = restored.Spec.NetworkSpec.PrivateDNSZoneName dst.Spec.NetworkSpec.APIServerLB.FrontendIPsCount = restored.Spec.NetworkSpec.APIServerLB.FrontendIPsCount @@ -55,24 +78,6 @@ func (src *AzureCluster) ConvertTo(dstRaw conversion.Hub) error { dst.Spec.CloudProviderConfigOverrides = restored.Spec.CloudProviderConfigOverrides dst.Spec.BastionSpec = restored.Spec.BastionSpec - // set default control plane outbound lb for private v1alpha3 clusters - if src.Spec.NetworkSpec.APIServerLB.Type == Internal && restored.Spec.NetworkSpec.ControlPlaneOutboundLB == nil { - dst.Spec.NetworkSpec.ControlPlaneOutboundLB = &infrav1beta1.LoadBalancerSpec{ - FrontendIPsCount: pointer.Int32Ptr(1), - } - } else { - dst.Spec.NetworkSpec.ControlPlaneOutboundLB = restored.Spec.NetworkSpec.ControlPlaneOutboundLB - } - - // set default node plane outbound lb for all v1alpha3 clusters - if restored.Spec.NetworkSpec.NodeOutboundLB == nil { - dst.Spec.NetworkSpec.NodeOutboundLB = &infrav1beta1.LoadBalancerSpec{ - FrontendIPsCount: pointer.Int32Ptr(1), - } - } else { - dst.Spec.NetworkSpec.NodeOutboundLB = restored.Spec.NetworkSpec.NodeOutboundLB - } - // Here we manually restore outbound security rules. Since v1alpha3 only supports ingress ("Inbound") rules, all v1alpha4/v1beta1 outbound rules are dropped when an AzureCluster // is converted to v1alpha3. We loop through all security group rules. For all previously existing outbound rules we restore the full rule. for _, restoredSubnet := range restored.Spec.NetworkSpec.Subnets { diff --git a/api/v1beta1/azurecluster_default.go b/api/v1beta1/azurecluster_default.go index 0e26d468274..71ff0f20282 100644 --- a/api/v1beta1/azurecluster_default.go +++ b/api/v1beta1/azurecluster_default.go @@ -57,8 +57,8 @@ func (c *AzureCluster) setNetworkSpecDefaults() { c.setSubnetDefaults() c.setVnetPeeringDefaults() c.setAPIServerLBDefaults() - c.setNodeOutboundLBDefaults() - c.setControlPlaneOutboundLBDefaults() + c.SetNodeOutboundLBDefaults() + c.SetControlPlaneOutboundLBDefaults() } func (c *AzureCluster) setResourceGroupDefault() { @@ -194,7 +194,7 @@ func (c *AzureCluster) setAPIServerLBDefaults() { } } -func (c *AzureCluster) setNodeOutboundLBDefaults() { +func (c *AzureCluster) SetNodeOutboundLBDefaults() { if c.Spec.NetworkSpec.NodeOutboundLB == nil { if c.Spec.NetworkSpec.APIServerLB.Type == Internal { return @@ -230,7 +230,7 @@ func (c *AzureCluster) setNodeOutboundLBDefaults() { c.setOutboundLBFrontendIPs(lb, generateNodeOutboundIPName) } -func (c *AzureCluster) setControlPlaneOutboundLBDefaults() { +func (c *AzureCluster) SetControlPlaneOutboundLBDefaults() { lb := c.Spec.NetworkSpec.ControlPlaneOutboundLB if lb == nil { diff --git a/api/v1beta1/azurecluster_default_test.go b/api/v1beta1/azurecluster_default_test.go index e708080a055..e92b03d5516 100644 --- a/api/v1beta1/azurecluster_default_test.go +++ b/api/v1beta1/azurecluster_default_test.go @@ -1596,7 +1596,7 @@ func TestNodeOutboundLBDefaults(t *testing.T) { tc := c t.Run(tc.name, func(t *testing.T) { t.Parallel() - tc.cluster.setNodeOutboundLBDefaults() + tc.cluster.SetNodeOutboundLBDefaults() if !reflect.DeepEqual(tc.cluster, tc.output) { expected, _ := json.MarshalIndent(tc.output, "", "\t") actual, _ := json.MarshalIndent(tc.cluster, "", "\t") @@ -1728,7 +1728,7 @@ func TestControlPlaneOutboundLBDefaults(t *testing.T) { tc := c t.Run(tc.name, func(t *testing.T) { t.Parallel() - tc.cluster.setControlPlaneOutboundLBDefaults() + tc.cluster.SetControlPlaneOutboundLBDefaults() if !reflect.DeepEqual(tc.cluster, tc.output) { expected, _ := json.MarshalIndent(tc.output, "", "\t") actual, _ := json.MarshalIndent(tc.cluster, "", "\t")