Skip to content

Commit

Permalink
Add the ability to have different route tables for control plane and …
Browse files Browse the repository at this point in the history
…worker
  • Loading branch information
nader-ziada committed Jul 23, 2020
1 parent 6ad50d0 commit 58ffc3c
Show file tree
Hide file tree
Showing 18 changed files with 375 additions and 141 deletions.
13 changes: 9 additions & 4 deletions api/v1alpha3/azurecluster_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (c *AzureCluster) setSubnetDefaults() {
cpSubnet.SecurityGroup.Name = generateControlPlaneSecurityGroupName(c.ObjectMeta.Name)
}
if cpSubnet.RouteTable.Name == "" {
cpSubnet.RouteTable.Name = generateRouteTableName(c.ObjectMeta.Name)
cpSubnet.RouteTable.Name = generateControlPlaneRouteTableName(c.ObjectMeta.Name)
}

if nodeSubnet.Name == "" {
Expand All @@ -93,7 +93,7 @@ func (c *AzureCluster) setSubnetDefaults() {
nodeSubnet.SecurityGroup.Name = generateNodeSecurityGroupName(c.ObjectMeta.Name)
}
if nodeSubnet.RouteTable.Name == "" {
nodeSubnet.RouteTable.Name = generateRouteTableName(c.ObjectMeta.Name)
nodeSubnet.RouteTable.Name = generateNodeRouteTableName(c.ObjectMeta.Name)
}
}

Expand Down Expand Up @@ -122,7 +122,12 @@ func generateNodeSecurityGroupName(clusterName string) string {
return fmt.Sprintf("%s-%s", clusterName, "node-nsg")
}

// generateRouteTableName generates a route table name, based on the cluster name.
func generateRouteTableName(clusterName string) string {
// generateControlPlaneRouteTableName generates a controlplane route table name, based on the cluster name.
func generateControlPlaneRouteTableName(clusterName string) string {
return fmt.Sprintf("%s-%s", clusterName, "controlplane-routetable")
}

// generateNodeRouteTableName generates a node route table name, based on the cluster name.
func generateNodeRouteTableName(clusterName string) string {
return fmt.Sprintf("%s-%s", clusterName, "node-routetable")
}
8 changes: 4 additions & 4 deletions api/v1alpha3/azurecluster_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func TestSubnetDefaults(t *testing.T) {
Name: "cluster-test-controlplane-subnet",
CidrBlock: DefaultControlPlaneSubnetCIDR,
SecurityGroup: SecurityGroup{Name: "cluster-test-controlplane-nsg"},
RouteTable: RouteTable{Name: "cluster-test-node-routetable"},
RouteTable: RouteTable{Name: "cluster-test-controlplane-routetable"},
},
{
Role: SubnetNode,
Expand Down Expand Up @@ -265,7 +265,7 @@ func TestSubnetDefaults(t *testing.T) {
Name: "my-controlplane-subnet",
CidrBlock: "10.0.0.16/24",
SecurityGroup: SecurityGroup{Name: "cluster-test-controlplane-nsg"},
RouteTable: RouteTable{Name: "cluster-test-node-routetable"},
RouteTable: RouteTable{Name: "cluster-test-controlplane-routetable"},
},
{
Role: SubnetNode,
Expand Down Expand Up @@ -312,7 +312,7 @@ func TestSubnetDefaults(t *testing.T) {
Name: "cluster-test-controlplane-subnet",
CidrBlock: DefaultControlPlaneSubnetCIDR,
SecurityGroup: SecurityGroup{Name: "cluster-test-controlplane-nsg"},
RouteTable: RouteTable{Name: "cluster-test-node-routetable"},
RouteTable: RouteTable{Name: "cluster-test-controlplane-routetable"},
},
{
Role: SubnetNode,
Expand Down Expand Up @@ -362,7 +362,7 @@ func TestSubnetDefaults(t *testing.T) {
Name: "cluster-test-controlplane-subnet",
CidrBlock: DefaultControlPlaneSubnetCIDR,
SecurityGroup: SecurityGroup{Name: "cluster-test-controlplane-nsg"},
RouteTable: RouteTable{Name: "cluster-test-node-routetable"},
RouteTable: RouteTable{Name: "cluster-test-controlplane-routetable"},
},
},
},
Expand Down
3 changes: 2 additions & 1 deletion cloud/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,6 @@ type ClusterDescriber interface {
IsVnetManaged() bool
NodeSubnet() *infrav1.SubnetSpec
ControlPlaneSubnet() *infrav1.SubnetSpec
RouteTable() *infrav1.RouteTable
NodeRouteTable() *infrav1.RouteTable
ControlPlaneRouteTable() *infrav1.RouteTable
}
24 changes: 18 additions & 6 deletions cloud/scope/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,18 @@ func (s *ClusterScope) LBSpecs() []azure.LBSpec {
}
}

// RouteTableSpecs returns the node route table(s)
// RouteTableSpecs returns the node route table
func (s *ClusterScope) RouteTableSpecs() []azure.RouteTableSpec {
return []azure.RouteTableSpec{{
Name: s.RouteTable().Name,
}}
return []azure.RouteTableSpec{
{
Name: s.ControlPlaneRouteTable().Name,
Role: azure.RouteTableControlPlane,
},
{
Name: s.NodeRouteTable().Name,
Role: azure.RouteTableNode,
},
}
}

// SubnetSpecs returns the subnets specs.
Expand Down Expand Up @@ -212,8 +219,13 @@ func (s *ClusterScope) NodeSubnet() *infrav1.SubnetSpec {
return s.AzureCluster.Spec.NetworkSpec.GetNodeSubnet()
}

// RouteTable returns the cluster node routetable.
func (s *ClusterScope) RouteTable() *infrav1.RouteTable {
// ControlPlaneRouteTable returns the cluster controlplane routetable.
func (s *ClusterScope) ControlPlaneRouteTable() *infrav1.RouteTable {
return &s.AzureCluster.Spec.NetworkSpec.GetControlPlaneSubnet().RouteTable
}

// NodeRouteTable returns the cluster node routetable.
func (s *ClusterScope) NodeRouteTable() *infrav1.RouteTable {
return &s.AzureCluster.Spec.NetworkSpec.GetNodeSubnet().RouteTable
}

Expand Down
26 changes: 20 additions & 6 deletions cloud/services/disks/mock_disks/disks_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 20 additions & 6 deletions cloud/services/groups/mock_groups/groups_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 20 additions & 6 deletions cloud/services/publicips/mock_publicips/publicips_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 58ffc3c

Please sign in to comment.