Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Cecile Robert-Michon committed Oct 30, 2020
1 parent a6c5244 commit 513ac97
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 22 deletions.
18 changes: 1 addition & 17 deletions api/v1alpha3/azurecluster_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,6 @@ const (
DefaultInternalLBIPAddress = "10.0.0.100"
)

const (
// DefaultVnetIPv6CIDR is the ipv6 Vnet CIDR
DefaultVnetIPv6CIDR = "2001:1234:5678:9a00::/56"
// DefaultControlPlaneSubnetIPv6CIDR is the default Control Plane Subnet CIDR
DefaultControlPlaneSubnetIPv6CIDR = "2001:1234:5678:9abc::/64"
// DefaultNodeSubnetIPv6CIDR is the default Node Subnet CIDR
DefaultNodeSubnetIPv6CIDR = "2001:1234:5678:9abd::/64"
// DefaultInternalLBIPv6Address is the default internal load balancer ip address
DefaultInternalLBIPv6Address = "2001:1234:5678:9abc::100"
)

func (c *AzureCluster) setDefaults() {
c.setResourceGroupDefault()
c.setNetworkSpecDefaults()
Expand Down Expand Up @@ -137,15 +126,10 @@ func (c *AzureCluster) setAPIServerLBDefaults() {
lb.Name = generateInternalLBName(c.ObjectMeta.Name)
}
if len(lb.FrontendIPs) == 0 {
// for back compat, set the private IP to the subnet InternalLBIPAddress value.
privateIP := c.Spec.NetworkSpec.GetControlPlaneSubnet().InternalLBIPAddress
if privateIP == "" {
privateIP = DefaultInternalLBIPAddress
}
lb.FrontendIPs = []FrontendIP{
{
Name: generateFrontendIPConfigName(lb.Name),
PrivateIPAddress: privateIP,
PrivateIPAddress: DefaultInternalLBIPAddress,
},
}
}
Expand Down
39 changes: 37 additions & 2 deletions api/v1alpha3/azurecluster_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func TestVnetDefaults(t *testing.T) {
ResourceGroup: "cluster-test",
NetworkSpec: NetworkSpec{
Vnet: VnetSpec{
CIDRBlocks: []string{DefaultVnetCIDR, DefaultVnetIPv6CIDR},
CIDRBlocks: []string{DefaultVnetCIDR, "2001:1234:5678:9a00::/56"},
},
},
},
Expand All @@ -214,7 +214,7 @@ func TestVnetDefaults(t *testing.T) {
Vnet: VnetSpec{
ResourceGroup: "cluster-test",
Name: "cluster-test-vnet",
CIDRBlocks: []string{DefaultVnetCIDR, DefaultVnetIPv6CIDR},
CIDRBlocks: []string{DefaultVnetCIDR, "2001:1234:5678:9a00::/56"},
},
},
},
Expand Down Expand Up @@ -578,6 +578,41 @@ func TestAPIServerLBDefaults(t *testing.T) {
},
},
},
{
name: "internal lb",
cluster: &AzureCluster{
ObjectMeta: v1.ObjectMeta{
Name: "cluster-test",
},
Spec: AzureClusterSpec{
NetworkSpec: NetworkSpec{
APIServerLB: LoadBalancerSpec{
Type: Internal,
},
},
},
},
output: &AzureCluster{
ObjectMeta: v1.ObjectMeta{
Name: "cluster-test",
},
Spec: AzureClusterSpec{
NetworkSpec: NetworkSpec{
APIServerLB: LoadBalancerSpec{
Name: "cluster-test-internal-lb",
SKU: SKUStandard,
FrontendIPs: []FrontendIP{
{
Name: "cluster-test-internal-lb-frontEnd",
PrivateIPAddress: DefaultInternalLBIPAddress,
},
},
Type: Internal,
},
},
},
},
},
}

for _, c := range cases {
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha3/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ const (
type LBType string

const (
// Internal is the value for the Azure load b alancer internal type.
// Internal is the value for the Azure load balancer internal type.
Internal = LBType("Internal")
// Public is the value for the Azure load balancer public type.
Public = LBType("Public")
Expand Down
31 changes: 31 additions & 0 deletions cloud/converters/loadbalancers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
Copyright 2019 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package converters

import (
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network"
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1alpha3"
)

// SKUtoSDK converts infrav1.SKU into a network.LoadBalancerSkuName.
func SKUtoSDK(src infrav1.SKU) network.LoadBalancerSkuName {
switch src {
case infrav1.SKUStandard:
return network.LoadBalancerSkuNameStandard
}
return ""
}
5 changes: 4 additions & 1 deletion cloud/scope/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func (s *ClusterScope) LBSpecs() []azure.LBSpec {
FrontendIPConfigs: s.APIServerLB().FrontendIPs,
APIServerPort: s.APIServerPort(),
Type: s.APIServerLB().Type,
SKU: infrav1.SKUStandard,
Role: infrav1.APIServerRole,
BackendPoolName: azure.GenerateBackendAddressPoolName(s.APIServerLB().Name),
},
Expand All @@ -150,6 +151,7 @@ func (s *ClusterScope) LBSpecs() []azure.LBSpec {
},
},
Type: infrav1.Public,
SKU: infrav1.SKUStandard,
BackendPoolName: azure.GenerateOutboundBackendAddressPoolName(s.NodeOutboundLBName()),
Role: infrav1.NodeOutboundRole,
},
Expand All @@ -170,7 +172,8 @@ func (s *ClusterScope) LBSpecs() []azure.LBSpec {
},
},
},
Type: infrav1.Public,
Type: infrav1.Public,
SKU: infrav1.SKUStandard,
BackendPoolName: azure.GenerateOutboundBackendAddressPoolName(azure.GenerateControlPlaneOutboundLBName(s.ClusterName())),
Role: infrav1.ControlPlaneOutboundRole,
})
Expand Down
2 changes: 1 addition & 1 deletion cloud/services/loadbalancers/loadbalancers.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (s *Service) Reconcile(ctx context.Context) error {
}

lb := network.LoadBalancer{
Sku: &network.LoadBalancerSku{Name: network.LoadBalancerSkuNameStandard},
Sku: &network.LoadBalancerSku{Name: converters.SKUtoSDK(lbSpec.SKU)},
Location: to.StringPtr(s.Scope.Location()),
Tags: converters.TagsToMap(infrav1.Build(infrav1.BuildParams{
ClusterName: s.Scope.ClusterName(),
Expand Down
1 change: 1 addition & 0 deletions cloud/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type LBSpec struct {
Name string
Role string
Type infrav1.LBType
SKU infrav1.SKU
SubnetName string
BackendPoolName string
FrontendIPConfigs []infrav1.FrontendIP
Expand Down

0 comments on commit 513ac97

Please sign in to comment.