Skip to content

Commit

Permalink
Merge pull request #1623 from shysank/alpha3_ob_lb
Browse files Browse the repository at this point in the history
Set default outbound lb for v1alpha3 clusters
  • Loading branch information
k8s-ci-robot authored Aug 20, 2021
2 parents 3585dbe + 9bce317 commit 57dff6b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
21 changes: 19 additions & 2 deletions api/v1alpha3/azurecluster_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 11 additions & 1 deletion api/v1alpha3/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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{
Expand Down Expand Up @@ -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)}
},
}
}

0 comments on commit 57dff6b

Please sign in to comment.