Skip to content

Commit 3033ae8

Browse files
committed
fix outbound lb conversion for v1alpha3 clusters
1 parent 1383fd6 commit 3033ae8

File tree

3 files changed

+31
-24
lines changed

3 files changed

+31
-24
lines changed

api/v1alpha3/azurecluster_conversion.go

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,37 +42,42 @@ func (src *AzureCluster) ConvertTo(dstRaw conversion.Hub) error { // nolint
4242
dst.Annotations = nil
4343
}
4444
}
45+
46+
// set default control plane outbound lb for private v1alpha3 clusters.
47+
if src.Spec.NetworkSpec.APIServerLB.Type == Internal {
48+
dst.Spec.NetworkSpec.ControlPlaneOutboundLB = &infrav1beta1.LoadBalancerSpec{
49+
FrontendIPsCount: pointer.Int32Ptr(1),
50+
}
51+
// We also need to set the defaults here because "get" won't set defaults, and hence there is no mismatch when a client
52+
// gets a v1alpha3 cluster.
53+
dst.SetControlPlaneOutboundLBDefaults()
54+
}
55+
56+
// set default node plane outbound lb for all v1alpha3 clusters.
57+
dst.Spec.NetworkSpec.NodeOutboundLB = &infrav1beta1.LoadBalancerSpec{
58+
FrontendIPsCount: pointer.Int32Ptr(1),
59+
}
60+
// We also need to set the defaults here because "get" won't set defaults, and hence there is no mismatch when a client
61+
// gets a v1alpha3 cluster.
62+
dst.SetNodeOutboundLBDefaults()
63+
4564
// Manually restore data.
4665
restored := &infrav1beta1.AzureCluster{}
4766
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
4867
return err
4968
}
5069

70+
// override outbound lb if it's present in restored.
71+
dst.Spec.NetworkSpec.ControlPlaneOutboundLB = restored.Spec.NetworkSpec.ControlPlaneOutboundLB
72+
dst.Spec.NetworkSpec.NodeOutboundLB = restored.Spec.NetworkSpec.NodeOutboundLB
73+
5174
dst.Spec.NetworkSpec.PrivateDNSZoneName = restored.Spec.NetworkSpec.PrivateDNSZoneName
5275

5376
dst.Spec.NetworkSpec.APIServerLB.FrontendIPsCount = restored.Spec.NetworkSpec.APIServerLB.FrontendIPsCount
5477
dst.Spec.NetworkSpec.APIServerLB.IdleTimeoutInMinutes = restored.Spec.NetworkSpec.APIServerLB.IdleTimeoutInMinutes
5578
dst.Spec.CloudProviderConfigOverrides = restored.Spec.CloudProviderConfigOverrides
5679
dst.Spec.BastionSpec = restored.Spec.BastionSpec
5780

58-
// set default control plane outbound lb for private v1alpha3 clusters
59-
if src.Spec.NetworkSpec.APIServerLB.Type == Internal && restored.Spec.NetworkSpec.ControlPlaneOutboundLB == nil {
60-
dst.Spec.NetworkSpec.ControlPlaneOutboundLB = &infrav1beta1.LoadBalancerSpec{
61-
FrontendIPsCount: pointer.Int32Ptr(1),
62-
}
63-
} else {
64-
dst.Spec.NetworkSpec.ControlPlaneOutboundLB = restored.Spec.NetworkSpec.ControlPlaneOutboundLB
65-
}
66-
67-
// set default node plane outbound lb for all v1alpha3 clusters
68-
if restored.Spec.NetworkSpec.NodeOutboundLB == nil {
69-
dst.Spec.NetworkSpec.NodeOutboundLB = &infrav1beta1.LoadBalancerSpec{
70-
FrontendIPsCount: pointer.Int32Ptr(1),
71-
}
72-
} else {
73-
dst.Spec.NetworkSpec.NodeOutboundLB = restored.Spec.NetworkSpec.NodeOutboundLB
74-
}
75-
7681
// Here we manually restore outbound security rules. Since v1alpha3 only supports ingress ("Inbound") rules, all v1alpha4/v1beta1 outbound rules are dropped when an AzureCluster
7782
// is converted to v1alpha3. We loop through all security group rules. For all previously existing outbound rules we restore the full rule.
7883
for _, restoredSubnet := range restored.Spec.NetworkSpec.Subnets {

api/v1beta1/azurecluster_default.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ func (c *AzureCluster) setNetworkSpecDefaults() {
5555
c.setSubnetDefaults()
5656
c.setVnetPeeringDefaults()
5757
c.setAPIServerLBDefaults()
58-
c.setNodeOutboundLBDefaults()
59-
c.setControlPlaneOutboundLBDefaults()
58+
c.SetNodeOutboundLBDefaults()
59+
c.SetControlPlaneOutboundLBDefaults()
6060
}
6161

6262
func (c *AzureCluster) setResourceGroupDefault() {
@@ -205,7 +205,8 @@ func (c *AzureCluster) setAPIServerLBDefaults() {
205205
}
206206
}
207207

208-
func (c *AzureCluster) setNodeOutboundLBDefaults() {
208+
// SetNodeOutboundLBDefaults sets the node outbound lb defaults.
209+
func (c *AzureCluster) SetNodeOutboundLBDefaults() {
209210
if c.Spec.NetworkSpec.NodeOutboundLB == nil {
210211
if c.Spec.NetworkSpec.APIServerLB.Type == Internal {
211212
return
@@ -245,7 +246,8 @@ func (c *AzureCluster) setNodeOutboundLBDefaults() {
245246
c.setOutboundLBFrontendIPs(lb, generateNodeOutboundIPName)
246247
}
247248

248-
func (c *AzureCluster) setControlPlaneOutboundLBDefaults() {
249+
// SetControlPlaneOutboundLBDefaults sets the control plane outbound lb defaults.
250+
func (c *AzureCluster) SetControlPlaneOutboundLBDefaults() {
249251
// public clusters don't need control plane outbound lb
250252
if c.Spec.NetworkSpec.APIServerLB.Type == Public {
251253
return

api/v1beta1/azurecluster_default_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,7 +1386,7 @@ func TestNodeOutboundLBDefaults(t *testing.T) {
13861386
tc := c
13871387
t.Run(tc.name, func(t *testing.T) {
13881388
t.Parallel()
1389-
tc.cluster.setNodeOutboundLBDefaults()
1389+
tc.cluster.SetNodeOutboundLBDefaults()
13901390
if !reflect.DeepEqual(tc.cluster, tc.output) {
13911391
expected, _ := json.MarshalIndent(tc.output, "", "\t")
13921392
actual, _ := json.MarshalIndent(tc.cluster, "", "\t")
@@ -1508,7 +1508,7 @@ func TestControlPlaneOutboundLBDefaults(t *testing.T) {
15081508
tc := c
15091509
t.Run(tc.name, func(t *testing.T) {
15101510
t.Parallel()
1511-
tc.cluster.setControlPlaneOutboundLBDefaults()
1511+
tc.cluster.SetControlPlaneOutboundLBDefaults()
15121512
if !reflect.DeepEqual(tc.cluster, tc.output) {
15131513
expected, _ := json.MarshalIndent(tc.output, "", "\t")
15141514
actual, _ := json.MarshalIndent(tc.cluster, "", "\t")

0 commit comments

Comments
 (0)