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 Sep 3, 2020
1 parent 8e6cf27 commit af85738
Show file tree
Hide file tree
Showing 24 changed files with 481 additions and 169 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 @@ -219,7 +219,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 @@ -268,7 +268,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 @@ -315,7 +315,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 @@ -365,7 +365,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 @@ -67,5 +67,6 @@ type ClusterDescriber interface {
IsVnetManaged() bool
NodeSubnet() *infrav1.SubnetSpec
ControlPlaneSubnet() *infrav1.SubnetSpec
RouteTable() *infrav1.RouteTable
NodeRouteTable() *infrav1.RouteTable
ControlPlaneRouteTable() *infrav1.RouteTable
}
26 changes: 20 additions & 6 deletions cloud/mocks/service_mock.go

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

27 changes: 20 additions & 7 deletions cloud/scope/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,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,
Subnet: s.ControlPlaneSubnet(),
},
{
Name: s.NodeRouteTable().Name,
Subnet: s.NodeSubnet(),
},
}
}

// NSGSpecs returns the security group specs.
Expand Down Expand Up @@ -193,7 +200,7 @@ func (s *ClusterScope) SubnetSpecs() []azure.SubnetSpec {
}
}

/// VNetSpecs returns the virtual network specs.
// VNetSpecs returns the virtual network specs.
func (s *ClusterScope) VNetSpecs() []azure.VNetSpec {
return []azure.VNetSpec{
{
Expand Down Expand Up @@ -229,8 +236,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 Expand Up @@ -307,6 +319,7 @@ func (s *ClusterScope) SetFailureDomain(id string, spec clusterv1.FailureDomainS
s.AzureCluster.Status.FailureDomains[id] = spec
}

// SetControlPlaneIngressRules will set the ingress rules or the control plane subnet
func (s *ClusterScope) SetControlPlaneIngressRules() {
if s.ControlPlaneSubnet().SecurityGroup.IngressRules == nil {
s.ControlPlaneSubnet().SecurityGroup.IngressRules = infrav1.IngressRules{
Expand Down

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/disks/mock_disks/disks_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.

Loading

0 comments on commit af85738

Please sign in to comment.