Skip to content

Commit

Permalink
Merge pull request #2185 from k8s-infra-cherrypick-robot/cherry-pick-…
Browse files Browse the repository at this point in the history
…2176-to-release-1.2

[release-1.2] Fix outbound lb conversion for v1alpha3 clusters
  • Loading branch information
k8s-ci-robot committed Mar 21, 2022
2 parents bd37f1c + 3669e52 commit 1352fa2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
41 changes: 23 additions & 18 deletions api/v1alpha3/azurecluster_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,37 +42,42 @@ 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
dst.Spec.NetworkSpec.APIServerLB.IdleTimeoutInMinutes = restored.Spec.NetworkSpec.APIServerLB.IdleTimeoutInMinutes
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 {
Expand Down
8 changes: 4 additions & 4 deletions api/v1beta1/azurecluster_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions api/v1beta1/azurecluster_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 1352fa2

Please sign in to comment.