From 9bce317820a4c67bddc4ee5e30b5f1ce2250abc0 Mon Sep 17 00:00:00 2001 From: shysank Date: Tue, 17 Aug 2021 15:53:58 -0700 Subject: [PATCH] set default outbound lb for v1alpha3 clusters --- api/v1alpha3/azurecluster_conversion.go | 21 +++++++++++++++++++-- api/v1alpha3/conversion_test.go | 12 +++++++++++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/api/v1alpha3/azurecluster_conversion.go b/api/v1alpha3/azurecluster_conversion.go index 555c475959b..5ee6d2507b6 100644 --- a/api/v1alpha3/azurecluster_conversion.go +++ b/api/v1alpha3/azurecluster_conversion.go @@ -18,6 +18,7 @@ package v1alpha3 import ( apiconversion "k8s.io/apimachinery/pkg/conversion" + "k8s.io/utils/pointer" infrav1alpha4 "sigs.k8s.io/cluster-api-provider-azure/api/v1alpha4" apiv1alpha3 "sigs.k8s.io/cluster-api/api/v1alpha3" apiv1alpha4 "sigs.k8s.io/cluster-api/api/v1alpha4" @@ -53,11 +54,27 @@ func (src *AzureCluster) ConvertTo(dstRaw conversion.Hub) error { // nolint dst.Spec.NetworkSpec.APIServerLB.FrontendIPsCount = restored.Spec.NetworkSpec.APIServerLB.FrontendIPsCount dst.Spec.NetworkSpec.APIServerLB.IdleTimeoutInMinutes = restored.Spec.NetworkSpec.APIServerLB.IdleTimeoutInMinutes - dst.Spec.NetworkSpec.NodeOutboundLB = restored.Spec.NetworkSpec.NodeOutboundLB - dst.Spec.NetworkSpec.ControlPlaneOutboundLB = restored.Spec.NetworkSpec.ControlPlaneOutboundLB 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 = &infrav1alpha4.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 = &infrav1alpha4.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 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/v1alpha3/conversion_test.go b/api/v1alpha3/conversion_test.go index 710cb4bfb4f..54d506ee377 100644 --- a/api/v1alpha3/conversion_test.go +++ b/api/v1alpha3/conversion_test.go @@ -19,6 +19,7 @@ package v1alpha3 import ( fuzz "github.com/google/gofuzz" . "github.com/onsi/gomega" + "k8s.io/utils/pointer" "testing" "k8s.io/apimachinery/pkg/api/apitesting/fuzzer" @@ -38,7 +39,7 @@ func TestFuzzyConversion(t *testing.T) { Scheme: scheme, Hub: &v1alpha4.AzureCluster{}, Spoke: &AzureCluster{}, - FuzzerFuncs: []fuzzer.FuzzerFuncs{overrideDeprecatedFieldsFuncs}, + FuzzerFuncs: []fuzzer.FuzzerFuncs{overrideDeprecatedFieldsFuncs, overrideOutboundLBFunc}, })) t.Run("for AzureMachine", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{ @@ -70,3 +71,12 @@ func overrideDeprecatedFieldsFuncs(codecs runtimeserializer.CodecFactory) []inte }, } } + +func overrideOutboundLBFunc(codecs runtimeserializer.CodecFactory) []interface{} { + return []interface{}{ + func(networkSpec *v1alpha4.NetworkSpec, c fuzz.Continue) { + networkSpec.ControlPlaneOutboundLB = &v1alpha4.LoadBalancerSpec{FrontendIPsCount: pointer.Int32Ptr(1)} + networkSpec.NodeOutboundLB = &v1alpha4.LoadBalancerSpec{FrontendIPsCount: pointer.Int32Ptr(1)} + }, + } +}