From af857384f2725a265ae2c148df6dcca475d257f2 Mon Sep 17 00:00:00 2001 From: Nader Ziada Date: Wed, 22 Jul 2020 11:47:03 -0400 Subject: [PATCH] Add the ability to have different route tables for control plane and worker --- api/v1alpha3/azurecluster_default.go | 13 +- api/v1alpha3/azurecluster_default_test.go | 8 +- cloud/interfaces.go | 3 +- cloud/mocks/service_mock.go | 26 ++- cloud/scope/cluster.go | 27 ++- .../mocks_bastionhosts/bastionhosts_mock.go | 26 ++- cloud/services/disks/mock_disks/disks_mock.go | 26 ++- .../inboundnatrules_mock.go | 26 ++- .../mock_loadbalancers/loadbalancers_mock.go | 26 ++- .../networkinterfaces_mock.go | 26 ++- .../mock_publicips/publicips_mock.go | 26 ++- .../roleassignments_mock.go | 26 ++- .../mock_routetables/routetables_mock.go | 26 ++- cloud/services/routetables/routetables.go | 37 ++-- .../services/routetables/routetables_test.go | 161 +++++++++++++----- .../mock_scalesets/scalesets_mock.go | 26 ++- .../securitygroups_mock.go | 26 ++- .../subnets/mock_subnets/subnets_mock.go | 26 ++- cloud/services/tags/mock_tags/tags_mock.go | 26 ++- .../virtualmachines_mock.go | 26 ++- .../virtualnetworks_mock.go | 26 ++- cloud/types.go | 6 +- controllers/azurecluster_reconciler.go | 3 +- controllers/helpers.go | 2 +- 24 files changed, 481 insertions(+), 169 deletions(-) diff --git a/api/v1alpha3/azurecluster_default.go b/api/v1alpha3/azurecluster_default.go index 62c81098c9f5..7b46c6ba593b 100644 --- a/api/v1alpha3/azurecluster_default.go +++ b/api/v1alpha3/azurecluster_default.go @@ -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 == "" { @@ -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) } } @@ -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") } diff --git a/api/v1alpha3/azurecluster_default_test.go b/api/v1alpha3/azurecluster_default_test.go index bb190d573d89..c14c295df59a 100644 --- a/api/v1alpha3/azurecluster_default_test.go +++ b/api/v1alpha3/azurecluster_default_test.go @@ -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, @@ -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, @@ -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, @@ -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"}, }, }, }, diff --git a/cloud/interfaces.go b/cloud/interfaces.go index 7af0171ec16d..b04dde4d13eb 100644 --- a/cloud/interfaces.go +++ b/cloud/interfaces.go @@ -67,5 +67,6 @@ type ClusterDescriber interface { IsVnetManaged() bool NodeSubnet() *infrav1.SubnetSpec ControlPlaneSubnet() *infrav1.SubnetSpec - RouteTable() *infrav1.RouteTable + NodeRouteTable() *infrav1.RouteTable + ControlPlaneRouteTable() *infrav1.RouteTable } diff --git a/cloud/mocks/service_mock.go b/cloud/mocks/service_mock.go index bf3bb36400ce..4aa49ed442ef 100644 --- a/cloud/mocks/service_mock.go +++ b/cloud/mocks/service_mock.go @@ -550,16 +550,30 @@ func (mr *MockClusterDescriberMockRecorder) ControlPlaneSubnet() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ControlPlaneSubnet", reflect.TypeOf((*MockClusterDescriber)(nil).ControlPlaneSubnet)) } -// RouteTable mocks base method. -func (m *MockClusterDescriber) RouteTable() *v1alpha3.RouteTable { +// NodeRouteTable mocks base method. +func (m *MockClusterDescriber) NodeRouteTable() *v1alpha3.RouteTable { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "RouteTable") + ret := m.ctrl.Call(m, "NodeRouteTable") ret0, _ := ret[0].(*v1alpha3.RouteTable) return ret0 } -// RouteTable indicates an expected call of RouteTable. -func (mr *MockClusterDescriberMockRecorder) RouteTable() *gomock.Call { +// NodeRouteTable indicates an expected call of NodeRouteTable. +func (mr *MockClusterDescriberMockRecorder) NodeRouteTable() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RouteTable", reflect.TypeOf((*MockClusterDescriber)(nil).RouteTable)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeRouteTable", reflect.TypeOf((*MockClusterDescriber)(nil).NodeRouteTable)) +} + +// ControlPlaneRouteTable mocks base method. +func (m *MockClusterDescriber) ControlPlaneRouteTable() *v1alpha3.RouteTable { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ControlPlaneRouteTable") + ret0, _ := ret[0].(*v1alpha3.RouteTable) + return ret0 +} + +// ControlPlaneRouteTable indicates an expected call of ControlPlaneRouteTable. +func (mr *MockClusterDescriberMockRecorder) ControlPlaneRouteTable() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ControlPlaneRouteTable", reflect.TypeOf((*MockClusterDescriber)(nil).ControlPlaneRouteTable)) } diff --git a/cloud/scope/cluster.go b/cloud/scope/cluster.go index 9c5d5dd48b42..d69fa540f18a 100644 --- a/cloud/scope/cluster.go +++ b/cloud/scope/cluster.go @@ -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. @@ -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{ { @@ -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 } @@ -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{ diff --git a/cloud/services/bastionhosts/mocks_bastionhosts/bastionhosts_mock.go b/cloud/services/bastionhosts/mocks_bastionhosts/bastionhosts_mock.go index 82027d5ffba5..5656764fb8bd 100644 --- a/cloud/services/bastionhosts/mocks_bastionhosts/bastionhosts_mock.go +++ b/cloud/services/bastionhosts/mocks_bastionhosts/bastionhosts_mock.go @@ -262,18 +262,32 @@ func (mr *MockBastionScopeMockRecorder) ControlPlaneSubnet() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ControlPlaneSubnet", reflect.TypeOf((*MockBastionScope)(nil).ControlPlaneSubnet)) } -// RouteTable mocks base method. -func (m *MockBastionScope) RouteTable() *v1alpha3.RouteTable { +// NodeRouteTable mocks base method. +func (m *MockBastionScope) NodeRouteTable() *v1alpha3.RouteTable { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "RouteTable") + ret := m.ctrl.Call(m, "NodeRouteTable") ret0, _ := ret[0].(*v1alpha3.RouteTable) return ret0 } -// RouteTable indicates an expected call of RouteTable. -func (mr *MockBastionScopeMockRecorder) RouteTable() *gomock.Call { +// NodeRouteTable indicates an expected call of NodeRouteTable. +func (mr *MockBastionScopeMockRecorder) NodeRouteTable() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RouteTable", reflect.TypeOf((*MockBastionScope)(nil).RouteTable)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeRouteTable", reflect.TypeOf((*MockBastionScope)(nil).NodeRouteTable)) +} + +// ControlPlaneRouteTable mocks base method. +func (m *MockBastionScope) ControlPlaneRouteTable() *v1alpha3.RouteTable { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ControlPlaneRouteTable") + ret0, _ := ret[0].(*v1alpha3.RouteTable) + return ret0 +} + +// ControlPlaneRouteTable indicates an expected call of ControlPlaneRouteTable. +func (mr *MockBastionScopeMockRecorder) ControlPlaneRouteTable() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ControlPlaneRouteTable", reflect.TypeOf((*MockBastionScope)(nil).ControlPlaneRouteTable)) } // Info mocks base method. diff --git a/cloud/services/disks/mock_disks/disks_mock.go b/cloud/services/disks/mock_disks/disks_mock.go index 7049f50502e6..3a0b5ba12b2a 100644 --- a/cloud/services/disks/mock_disks/disks_mock.go +++ b/cloud/services/disks/mock_disks/disks_mock.go @@ -356,18 +356,32 @@ func (mr *MockDiskScopeMockRecorder) ControlPlaneSubnet() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ControlPlaneSubnet", reflect.TypeOf((*MockDiskScope)(nil).ControlPlaneSubnet)) } -// RouteTable mocks base method. -func (m *MockDiskScope) RouteTable() *v1alpha3.RouteTable { +// NodeRouteTable mocks base method. +func (m *MockDiskScope) NodeRouteTable() *v1alpha3.RouteTable { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "RouteTable") + ret := m.ctrl.Call(m, "NodeRouteTable") ret0, _ := ret[0].(*v1alpha3.RouteTable) return ret0 } -// RouteTable indicates an expected call of RouteTable. -func (mr *MockDiskScopeMockRecorder) RouteTable() *gomock.Call { +// NodeRouteTable indicates an expected call of NodeRouteTable. +func (mr *MockDiskScopeMockRecorder) NodeRouteTable() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RouteTable", reflect.TypeOf((*MockDiskScope)(nil).RouteTable)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeRouteTable", reflect.TypeOf((*MockDiskScope)(nil).NodeRouteTable)) +} + +// ControlPlaneRouteTable mocks base method. +func (m *MockDiskScope) ControlPlaneRouteTable() *v1alpha3.RouteTable { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ControlPlaneRouteTable") + ret0, _ := ret[0].(*v1alpha3.RouteTable) + return ret0 +} + +// ControlPlaneRouteTable indicates an expected call of ControlPlaneRouteTable. +func (mr *MockDiskScopeMockRecorder) ControlPlaneRouteTable() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ControlPlaneRouteTable", reflect.TypeOf((*MockDiskScope)(nil).ControlPlaneRouteTable)) } // DiskSpecs mocks base method. diff --git a/cloud/services/inboundnatrules/mock_inboundnatrules/inboundnatrules_mock.go b/cloud/services/inboundnatrules/mock_inboundnatrules/inboundnatrules_mock.go index 1ef24860e4bc..4572bb64f398 100644 --- a/cloud/services/inboundnatrules/mock_inboundnatrules/inboundnatrules_mock.go +++ b/cloud/services/inboundnatrules/mock_inboundnatrules/inboundnatrules_mock.go @@ -356,18 +356,32 @@ func (mr *MockInboundNatScopeMockRecorder) ControlPlaneSubnet() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ControlPlaneSubnet", reflect.TypeOf((*MockInboundNatScope)(nil).ControlPlaneSubnet)) } -// RouteTable mocks base method. -func (m *MockInboundNatScope) RouteTable() *v1alpha3.RouteTable { +// NodeRouteTable mocks base method. +func (m *MockInboundNatScope) NodeRouteTable() *v1alpha3.RouteTable { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "RouteTable") + ret := m.ctrl.Call(m, "NodeRouteTable") ret0, _ := ret[0].(*v1alpha3.RouteTable) return ret0 } -// RouteTable indicates an expected call of RouteTable. -func (mr *MockInboundNatScopeMockRecorder) RouteTable() *gomock.Call { +// NodeRouteTable indicates an expected call of NodeRouteTable. +func (mr *MockInboundNatScopeMockRecorder) NodeRouteTable() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RouteTable", reflect.TypeOf((*MockInboundNatScope)(nil).RouteTable)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeRouteTable", reflect.TypeOf((*MockInboundNatScope)(nil).NodeRouteTable)) +} + +// ControlPlaneRouteTable mocks base method. +func (m *MockInboundNatScope) ControlPlaneRouteTable() *v1alpha3.RouteTable { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ControlPlaneRouteTable") + ret0, _ := ret[0].(*v1alpha3.RouteTable) + return ret0 +} + +// ControlPlaneRouteTable indicates an expected call of ControlPlaneRouteTable. +func (mr *MockInboundNatScopeMockRecorder) ControlPlaneRouteTable() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ControlPlaneRouteTable", reflect.TypeOf((*MockInboundNatScope)(nil).ControlPlaneRouteTable)) } // InboundNatSpecs mocks base method. diff --git a/cloud/services/loadbalancers/mock_loadbalancers/loadbalancers_mock.go b/cloud/services/loadbalancers/mock_loadbalancers/loadbalancers_mock.go index cfe463d41b1f..a49dd0e7690f 100644 --- a/cloud/services/loadbalancers/mock_loadbalancers/loadbalancers_mock.go +++ b/cloud/services/loadbalancers/mock_loadbalancers/loadbalancers_mock.go @@ -262,18 +262,32 @@ func (mr *MockLBScopeMockRecorder) ControlPlaneSubnet() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ControlPlaneSubnet", reflect.TypeOf((*MockLBScope)(nil).ControlPlaneSubnet)) } -// RouteTable mocks base method. -func (m *MockLBScope) RouteTable() *v1alpha3.RouteTable { +// NodeRouteTable mocks base method. +func (m *MockLBScope) NodeRouteTable() *v1alpha3.RouteTable { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "RouteTable") + ret := m.ctrl.Call(m, "NodeRouteTable") ret0, _ := ret[0].(*v1alpha3.RouteTable) return ret0 } -// RouteTable indicates an expected call of RouteTable. -func (mr *MockLBScopeMockRecorder) RouteTable() *gomock.Call { +// NodeRouteTable indicates an expected call of NodeRouteTable. +func (mr *MockLBScopeMockRecorder) NodeRouteTable() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RouteTable", reflect.TypeOf((*MockLBScope)(nil).RouteTable)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeRouteTable", reflect.TypeOf((*MockLBScope)(nil).NodeRouteTable)) +} + +// ControlPlaneRouteTable mocks base method. +func (m *MockLBScope) ControlPlaneRouteTable() *v1alpha3.RouteTable { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ControlPlaneRouteTable") + ret0, _ := ret[0].(*v1alpha3.RouteTable) + return ret0 +} + +// ControlPlaneRouteTable indicates an expected call of ControlPlaneRouteTable. +func (mr *MockLBScopeMockRecorder) ControlPlaneRouteTable() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ControlPlaneRouteTable", reflect.TypeOf((*MockLBScope)(nil).ControlPlaneRouteTable)) } // Info mocks base method. diff --git a/cloud/services/networkinterfaces/mock_networkinterfaces/networkinterfaces_mock.go b/cloud/services/networkinterfaces/mock_networkinterfaces/networkinterfaces_mock.go index 337d487e526c..02b88d2a10b1 100644 --- a/cloud/services/networkinterfaces/mock_networkinterfaces/networkinterfaces_mock.go +++ b/cloud/services/networkinterfaces/mock_networkinterfaces/networkinterfaces_mock.go @@ -262,18 +262,32 @@ func (mr *MockNICScopeMockRecorder) ControlPlaneSubnet() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ControlPlaneSubnet", reflect.TypeOf((*MockNICScope)(nil).ControlPlaneSubnet)) } -// RouteTable mocks base method. -func (m *MockNICScope) RouteTable() *v1alpha3.RouteTable { +// NodeRouteTable mocks base method. +func (m *MockNICScope) NodeRouteTable() *v1alpha3.RouteTable { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "RouteTable") + ret := m.ctrl.Call(m, "NodeRouteTable") ret0, _ := ret[0].(*v1alpha3.RouteTable) return ret0 } -// RouteTable indicates an expected call of RouteTable. -func (mr *MockNICScopeMockRecorder) RouteTable() *gomock.Call { +// NodeRouteTable indicates an expected call of NodeRouteTable. +func (mr *MockNICScopeMockRecorder) NodeRouteTable() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RouteTable", reflect.TypeOf((*MockNICScope)(nil).RouteTable)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeRouteTable", reflect.TypeOf((*MockNICScope)(nil).NodeRouteTable)) +} + +// ControlPlaneRouteTable mocks base method. +func (m *MockNICScope) ControlPlaneRouteTable() *v1alpha3.RouteTable { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ControlPlaneRouteTable") + ret0, _ := ret[0].(*v1alpha3.RouteTable) + return ret0 +} + +// ControlPlaneRouteTable indicates an expected call of ControlPlaneRouteTable. +func (mr *MockNICScopeMockRecorder) ControlPlaneRouteTable() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ControlPlaneRouteTable", reflect.TypeOf((*MockNICScope)(nil).ControlPlaneRouteTable)) } // Info mocks base method. diff --git a/cloud/services/publicips/mock_publicips/publicips_mock.go b/cloud/services/publicips/mock_publicips/publicips_mock.go index ebb22de9ad44..eb741faedd5f 100644 --- a/cloud/services/publicips/mock_publicips/publicips_mock.go +++ b/cloud/services/publicips/mock_publicips/publicips_mock.go @@ -356,18 +356,32 @@ func (mr *MockPublicIPScopeMockRecorder) ControlPlaneSubnet() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ControlPlaneSubnet", reflect.TypeOf((*MockPublicIPScope)(nil).ControlPlaneSubnet)) } -// RouteTable mocks base method. -func (m *MockPublicIPScope) RouteTable() *v1alpha3.RouteTable { +// NodeRouteTable mocks base method. +func (m *MockPublicIPScope) NodeRouteTable() *v1alpha3.RouteTable { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "RouteTable") + ret := m.ctrl.Call(m, "NodeRouteTable") ret0, _ := ret[0].(*v1alpha3.RouteTable) return ret0 } -// RouteTable indicates an expected call of RouteTable. -func (mr *MockPublicIPScopeMockRecorder) RouteTable() *gomock.Call { +// NodeRouteTable indicates an expected call of NodeRouteTable. +func (mr *MockPublicIPScopeMockRecorder) NodeRouteTable() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RouteTable", reflect.TypeOf((*MockPublicIPScope)(nil).RouteTable)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeRouteTable", reflect.TypeOf((*MockPublicIPScope)(nil).NodeRouteTable)) +} + +// ControlPlaneRouteTable mocks base method. +func (m *MockPublicIPScope) ControlPlaneRouteTable() *v1alpha3.RouteTable { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ControlPlaneRouteTable") + ret0, _ := ret[0].(*v1alpha3.RouteTable) + return ret0 +} + +// ControlPlaneRouteTable indicates an expected call of ControlPlaneRouteTable. +func (mr *MockPublicIPScopeMockRecorder) ControlPlaneRouteTable() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ControlPlaneRouteTable", reflect.TypeOf((*MockPublicIPScope)(nil).ControlPlaneRouteTable)) } // PublicIPSpecs mocks base method. diff --git a/cloud/services/roleassignments/mock_roleassignments/roleassignments_mock.go b/cloud/services/roleassignments/mock_roleassignments/roleassignments_mock.go index c7f1f3f0b764..fd89c45b8d24 100644 --- a/cloud/services/roleassignments/mock_roleassignments/roleassignments_mock.go +++ b/cloud/services/roleassignments/mock_roleassignments/roleassignments_mock.go @@ -356,18 +356,32 @@ func (mr *MockRoleAssignmentScopeMockRecorder) ControlPlaneSubnet() *gomock.Call return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ControlPlaneSubnet", reflect.TypeOf((*MockRoleAssignmentScope)(nil).ControlPlaneSubnet)) } -// RouteTable mocks base method. -func (m *MockRoleAssignmentScope) RouteTable() *v1alpha3.RouteTable { +// NodeRouteTable mocks base method. +func (m *MockRoleAssignmentScope) NodeRouteTable() *v1alpha3.RouteTable { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "RouteTable") + ret := m.ctrl.Call(m, "NodeRouteTable") ret0, _ := ret[0].(*v1alpha3.RouteTable) return ret0 } -// RouteTable indicates an expected call of RouteTable. -func (mr *MockRoleAssignmentScopeMockRecorder) RouteTable() *gomock.Call { +// NodeRouteTable indicates an expected call of NodeRouteTable. +func (mr *MockRoleAssignmentScopeMockRecorder) NodeRouteTable() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RouteTable", reflect.TypeOf((*MockRoleAssignmentScope)(nil).RouteTable)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeRouteTable", reflect.TypeOf((*MockRoleAssignmentScope)(nil).NodeRouteTable)) +} + +// ControlPlaneRouteTable mocks base method. +func (m *MockRoleAssignmentScope) ControlPlaneRouteTable() *v1alpha3.RouteTable { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ControlPlaneRouteTable") + ret0, _ := ret[0].(*v1alpha3.RouteTable) + return ret0 +} + +// ControlPlaneRouteTable indicates an expected call of ControlPlaneRouteTable. +func (mr *MockRoleAssignmentScopeMockRecorder) ControlPlaneRouteTable() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ControlPlaneRouteTable", reflect.TypeOf((*MockRoleAssignmentScope)(nil).ControlPlaneRouteTable)) } // RoleAssignmentSpecs mocks base method. diff --git a/cloud/services/routetables/mock_routetables/routetables_mock.go b/cloud/services/routetables/mock_routetables/routetables_mock.go index 77ad55372e24..03f1cd2442b3 100644 --- a/cloud/services/routetables/mock_routetables/routetables_mock.go +++ b/cloud/services/routetables/mock_routetables/routetables_mock.go @@ -262,18 +262,32 @@ func (mr *MockRouteTableScopeMockRecorder) ControlPlaneSubnet() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ControlPlaneSubnet", reflect.TypeOf((*MockRouteTableScope)(nil).ControlPlaneSubnet)) } -// RouteTable mocks base method. -func (m *MockRouteTableScope) RouteTable() *v1alpha3.RouteTable { +// NodeRouteTable mocks base method. +func (m *MockRouteTableScope) NodeRouteTable() *v1alpha3.RouteTable { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "RouteTable") + ret := m.ctrl.Call(m, "NodeRouteTable") ret0, _ := ret[0].(*v1alpha3.RouteTable) return ret0 } -// RouteTable indicates an expected call of RouteTable. -func (mr *MockRouteTableScopeMockRecorder) RouteTable() *gomock.Call { +// NodeRouteTable indicates an expected call of NodeRouteTable. +func (mr *MockRouteTableScopeMockRecorder) NodeRouteTable() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RouteTable", reflect.TypeOf((*MockRouteTableScope)(nil).RouteTable)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeRouteTable", reflect.TypeOf((*MockRouteTableScope)(nil).NodeRouteTable)) +} + +// ControlPlaneRouteTable mocks base method. +func (m *MockRouteTableScope) ControlPlaneRouteTable() *v1alpha3.RouteTable { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ControlPlaneRouteTable") + ret0, _ := ret[0].(*v1alpha3.RouteTable) + return ret0 +} + +// ControlPlaneRouteTable indicates an expected call of ControlPlaneRouteTable. +func (mr *MockRouteTableScopeMockRecorder) ControlPlaneRouteTable() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ControlPlaneRouteTable", reflect.TypeOf((*MockRouteTableScope)(nil).ControlPlaneRouteTable)) } // Info mocks base method. diff --git a/cloud/services/routetables/routetables.go b/cloud/services/routetables/routetables.go index 308b6db81a66..c932060c8fb3 100644 --- a/cloud/services/routetables/routetables.go +++ b/cloud/services/routetables/routetables.go @@ -32,40 +32,35 @@ func (s *Service) Reconcile(ctx context.Context) error { return nil } - for _, rtSpec := range s.Scope.RouteTableSpecs() { - existingRouteTable, err := s.Get(ctx, s.Scope.ResourceGroup(), rtSpec.Name) + for _, routeTableSpec := range s.Scope.RouteTableSpecs() { + existingRouteTable, err := s.Get(ctx, s.Scope.ResourceGroup(), routeTableSpec.Name) if !azure.ResourceNotFound(err) { if err != nil { - return errors.Wrapf(err, "failed to get route table %s in %s", rtSpec.Name, s.Scope.ResourceGroup()) + return errors.Wrapf(err, "failed to get route table %s in %s", routeTableSpec.Name, s.Scope.ResourceGroup()) } // route table already exists - // currently don't support: - // 1. creating separate control plane and node (#718) so update both - // 2. specifying your own routes via spec - s.Scope.NodeSubnet().RouteTable.Name = to.String(existingRouteTable.Name) - s.Scope.NodeSubnet().RouteTable.ID = to.String(existingRouteTable.ID) - s.Scope.ControlPlaneSubnet().RouteTable.Name = to.String(existingRouteTable.Name) - s.Scope.ControlPlaneSubnet().RouteTable.ID = to.String(existingRouteTable.ID) + // currently don't support specifying your own routes via spec + routeTableSpec.Subnet.RouteTable.Name = to.String(existingRouteTable.Name) + routeTableSpec.Subnet.RouteTable.ID = to.String(existingRouteTable.ID) - return nil + continue } - s.Scope.V(2).Info("creating route table", "route table", rtSpec.Name) + s.Scope.V(2).Info("creating Route Table", "route table", routeTableSpec.Name) err = s.Client.CreateOrUpdate( ctx, s.Scope.ResourceGroup(), - rtSpec.Name, + routeTableSpec.Name, network.RouteTable{ Location: to.StringPtr(s.Scope.Location()), RouteTablePropertiesFormat: &network.RouteTablePropertiesFormat{}, }, ) if err != nil { - return errors.Wrapf(err, "failed to create route table %s in resource group %s", rtSpec.Name, s.Scope.ResourceGroup()) + return errors.Wrapf(err, "failed to create route table %s in resource group %s", routeTableSpec.Name, s.Scope.ResourceGroup()) } - - s.Scope.V(2).Info("successfully created route table", "route table", rtSpec.Name) + s.Scope.V(2).Info("successfully created route table", "route table", routeTableSpec.Name) } return nil } @@ -76,18 +71,18 @@ func (s *Service) Delete(ctx context.Context) error { s.Scope.V(4).Info("Skipping route table deletion in custom vnet mode") return nil } - for _, rtSpec := range s.Scope.RouteTableSpecs() { - s.Scope.V(2).Info("deleting route table", "route table", rtSpec.Name) - err := s.Client.Delete(ctx, s.Scope.ResourceGroup(), rtSpec.Name) + for _, routeTableSpec := range s.Scope.RouteTableSpecs() { + s.Scope.V(2).Info("deleting route table", "route table", routeTableSpec.Name) + err := s.Client.Delete(ctx, s.Scope.ResourceGroup(), routeTableSpec.Name) if err != nil && azure.ResourceNotFound(err) { // already deleted continue } if err != nil { - return errors.Wrapf(err, "failed to delete route table %s in resource group %s", rtSpec.Name, s.Scope.ResourceGroup()) + return errors.Wrapf(err, "failed to delete route table %s in resource group %s", routeTableSpec.Name, s.Scope.ResourceGroup()) } - s.Scope.V(2).Info("successfully deleted route table", "route table", rtSpec.Name) + s.Scope.V(2).Info("successfully deleted route table", "route table", routeTableSpec.Name) } return nil } diff --git a/cloud/services/routetables/routetables_test.go b/cloud/services/routetables/routetables_test.go index b493e41d197f..317a277fc519 100644 --- a/cloud/services/routetables/routetables_test.go +++ b/cloud/services/routetables/routetables_test.go @@ -79,14 +79,31 @@ func TestReconcileRouteTables(t *testing.T) { }) s.V(gomock.AssignableToTypeOf(2)).AnyTimes().Return(klogr.New()) s.ClusterName() - s.RouteTableSpecs().Return([]azure.RouteTableSpec{{ - Name: "my-routetable", - }}) - s.RouteTable().AnyTimes().Return(&infrav1.RouteTable{Name: "my-routetable"}) + s.RouteTableSpecs().Return([]azure.RouteTableSpec{ + { + Name: "my-cp-routetable", + Subnet: &infrav1.SubnetSpec{ + Name: "control-plane-subnet", + Role: infrav1.SubnetControlPlane, + }, + }, + { + Name: "my-node-routetable", + Subnet: &infrav1.SubnetSpec{ + Name: "node-subnet", + Role: infrav1.SubnetNode, + }, + }, + }) + s.ControlPlaneRouteTable().AnyTimes().Return(&infrav1.RouteTable{Name: "my-cp-routetable"}) s.ResourceGroup().AnyTimes().Return("my-rg") - m.Get(context.TODO(), "my-rg", "my-routetable").Return(network.RouteTable{}, autorest.NewErrorWithResponse("", "", &http.Response{StatusCode: 404}, "Not found")) + m.Get(context.TODO(), "my-rg", "my-cp-routetable").Return(network.RouteTable{}, autorest.NewErrorWithResponse("", "", &http.Response{StatusCode: 404}, "Not found")) s.Location().Return("westus") - m.CreateOrUpdate(context.TODO(), "my-rg", "my-routetable", gomock.AssignableToTypeOf(network.RouteTable{})) + m.CreateOrUpdate(context.TODO(), "my-rg", "my-cp-routetable", gomock.AssignableToTypeOf(network.RouteTable{})) + s.NodeRouteTable().AnyTimes().Return(&infrav1.RouteTable{Name: "my-node-routetable"}) + m.Get(context.TODO(), "my-rg", "my-node-routetable").Return(network.RouteTable{}, autorest.NewErrorWithResponse("", "", &http.Response{StatusCode: 404}, "Not found")) + s.Location().Return("westus") + m.CreateOrUpdate(context.TODO(), "my-rg", "my-node-routetable", gomock.AssignableToTypeOf(network.RouteTable{})) }, }, { @@ -103,18 +120,36 @@ func TestReconcileRouteTables(t *testing.T) { }) s.V(gomock.AssignableToTypeOf(2)).AnyTimes().Return(klogr.New()) s.ClusterName() - s.RouteTableSpecs().Return([]azure.RouteTableSpec{{ - Name: "my-routetable", - }}) - s.RouteTable().AnyTimes().Return(&infrav1.RouteTable{Name: "my-routetable"}) - s.ResourceGroup().Return("my-rg") - m.Get(context.TODO(), "my-rg", "my-routetable").Return(network.RouteTable{ - Name: to.StringPtr("my-routetable"), + s.RouteTableSpecs().AnyTimes().Return([]azure.RouteTableSpec{ + { + Name: "my-cp-routetable", + Subnet: &infrav1.SubnetSpec{ + Name: "control-plane-subnet", + Role: infrav1.SubnetControlPlane, + }, + }, + { + Name: "my-node-routetable", + Subnet: &infrav1.SubnetSpec{ + Name: "node-subnet", + Role: infrav1.SubnetNode, + }, + }, + }) + s.ControlPlaneSubnet().AnyTimes().Return(&infrav1.SubnetSpec{Name: "control-plane-subnet", Role: infrav1.SubnetControlPlane}) + s.ControlPlaneRouteTable().AnyTimes().Return(&infrav1.RouteTable{Name: "my-cp-routetable"}) + s.ResourceGroup().AnyTimes().Return("my-rg") + m.Get(context.TODO(), "my-rg", "my-cp-routetable").Return(network.RouteTable{ + Name: to.StringPtr("my-cp-routetable"), ID: to.StringPtr("1"), }, nil) - s.NodeSubnet().AnyTimes().Return(&infrav1.SubnetSpec{}) - s.ControlPlaneSubnet().AnyTimes().Return(&infrav1.SubnetSpec{}) - m.CreateOrUpdate(context.TODO(), gomock.Any(), gomock.Any(), gomock.AssignableToTypeOf(network.RouteTable{})).Times(0) + s.NodeSubnet().AnyTimes().Return(&infrav1.SubnetSpec{Name: "node-subnet", Role: infrav1.SubnetNode}) + s.NodeRouteTable().AnyTimes().Return(&infrav1.RouteTable{Name: "my-node-routetable"}) + s.ResourceGroup().AnyTimes().Return("my-rg") + m.Get(context.TODO(), "my-rg", "my-node-routetable").Return(network.RouteTable{ + Name: to.StringPtr("my-node-routetable"), + ID: to.StringPtr("2"), + }, nil) }, }, { @@ -124,7 +159,7 @@ func TestReconcileRouteTables(t *testing.T) { "sigs.k8s.io_cluster-api-provider-azure_cluster_test-cluster": "owned", "sigs.k8s.io_cluster-api-provider-azure_role": "common", }, - expectedError: "failed to get route table my-routetable in my-rg: #: Internal Server Error: StatusCode=500", + expectedError: "failed to get route table my-cp-routetable in my-rg: #: Internal Server Error: StatusCode=500", expect: func(s *mock_routetables.MockRouteTableScopeMockRecorder, m *mock_routetables.MockClientMockRecorder) { s.Vnet().Return(&infrav1.VnetSpec{ Name: "my-vnet", @@ -132,12 +167,18 @@ func TestReconcileRouteTables(t *testing.T) { s.V(gomock.AssignableToTypeOf(2)).AnyTimes().Return(klogr.New()) s.ClusterName() s.RouteTableSpecs().Return([]azure.RouteTableSpec{{ - Name: "my-routetable", + Name: "my-cp-routetable", + Subnet: &infrav1.SubnetSpec{ + Name: "control-plane-subnet", + Role: infrav1.SubnetControlPlane, + }, }}) - s.RouteTable().AnyTimes().Return(&infrav1.RouteTable{Name: "my-routetable"}) + s.ControlPlaneSubnet().AnyTimes().Return(&infrav1.SubnetSpec{}) + s.ControlPlaneRouteTable().AnyTimes().Return(&infrav1.RouteTable{Name: "my-routetable"}) s.ResourceGroup().AnyTimes().Return("my-rg") - m.Get(context.TODO(), "my-rg", "my-routetable").Return(network.RouteTable{}, autorest.NewErrorWithResponse("", "", &http.Response{StatusCode: 500}, "Internal Server Error")) + m.Get(context.TODO(), "my-rg", "my-cp-routetable").Return(network.RouteTable{}, autorest.NewErrorWithResponse("", "", &http.Response{StatusCode: 500}, "Internal Server Error")) m.CreateOrUpdate(context.TODO(), gomock.Any(), gomock.Any(), gomock.AssignableToTypeOf(network.RouteTable{})).Times(0) + s.NodeRouteTable().Times(0) }, }, { @@ -147,7 +188,7 @@ func TestReconcileRouteTables(t *testing.T) { "sigs.k8s.io_cluster-api-provider-azure_cluster_test-cluster": "owned", "sigs.k8s.io_cluster-api-provider-azure_role": "common", }, - expectedError: "failed to create route table my-routetable in resource group my-rg: #: Internal Server Error: StatusCode=500", + expectedError: "failed to create route table my-cp-routetable in resource group my-rg: #: Internal Server Error: StatusCode=500", expect: func(s *mock_routetables.MockRouteTableScopeMockRecorder, m *mock_routetables.MockClientMockRecorder) { s.Vnet().Return(&infrav1.VnetSpec{ Name: "my-vnet", @@ -155,13 +196,18 @@ func TestReconcileRouteTables(t *testing.T) { s.V(gomock.AssignableToTypeOf(2)).AnyTimes().Return(klogr.New()) s.ClusterName() s.RouteTableSpecs().Return([]azure.RouteTableSpec{{ - Name: "my-routetable", + Name: "my-cp-routetable", + Subnet: &infrav1.SubnetSpec{ + Name: "control-plane-subnet", + Role: infrav1.SubnetControlPlane, + }, }}) - s.RouteTable().AnyTimes().Return(&infrav1.RouteTable{Name: "my-routetable"}) + s.ControlPlaneSubnet().AnyTimes().Return(&infrav1.SubnetSpec{}) + s.ControlPlaneRouteTable().AnyTimes().Return(&infrav1.RouteTable{Name: "my-cp-routetable"}) s.ResourceGroup().AnyTimes().Return("my-rg") - m.Get(context.TODO(), "my-rg", "my-routetable").Return(network.RouteTable{}, autorest.NewErrorWithResponse("", "", &http.Response{StatusCode: 404}, "Not found")) + m.Get(context.TODO(), "my-rg", "my-cp-routetable").Return(network.RouteTable{}, autorest.NewErrorWithResponse("", "", &http.Response{StatusCode: 404}, "Not found")) s.Location().Return("westus") - m.CreateOrUpdate(context.TODO(), "my-rg", "my-routetable", gomock.AssignableToTypeOf(network.RouteTable{})).Return(autorest.NewErrorWithResponse("", "", &http.Response{StatusCode: 500}, "Internal Server Error")) + m.CreateOrUpdate(context.TODO(), "my-rg", "my-cp-routetable", gomock.AssignableToTypeOf(network.RouteTable{})).Return(autorest.NewErrorWithResponse("", "", &http.Response{StatusCode: 500}, "Internal Server Error")) }, }, } @@ -232,12 +278,28 @@ func TestDeleteRouteTable(t *testing.T) { }) s.V(gomock.AssignableToTypeOf(2)).AnyTimes().Return(klogr.New()) s.ClusterName() - s.RouteTableSpecs().Return([]azure.RouteTableSpec{{ - Name: "my-routetable", - }}) - s.RouteTable().AnyTimes().Return(&infrav1.RouteTable{Name: "my-routetable"}) + s.RouteTableSpecs().Return([]azure.RouteTableSpec{ + { + Name: "my-cp-routetable", + Subnet: &infrav1.SubnetSpec{ + Name: "control-plane-subnet", + Role: infrav1.SubnetControlPlane, + }, + }, + { + Name: "my-node-routetable", + Subnet: &infrav1.SubnetSpec{ + Name: "node-subnet", + Role: infrav1.SubnetNode, + }, + }, + }) + s.ControlPlaneRouteTable().AnyTimes().Return(&infrav1.RouteTable{Name: "my-cp-routetable"}) s.ResourceGroup().Return("my-rg") - m.Delete(context.TODO(), "my-rg", "my-routetable") + m.Delete(context.TODO(), "my-rg", "my-cp-routetable") + s.NodeRouteTable().AnyTimes().Return(&infrav1.RouteTable{Name: "my-node-routetable"}) + s.ResourceGroup().Return("my-rg") + m.Delete(context.TODO(), "my-rg", "my-node-routetable") }, }, { @@ -254,12 +316,28 @@ func TestDeleteRouteTable(t *testing.T) { }) s.V(gomock.AssignableToTypeOf(2)).AnyTimes().Return(klogr.New()) s.ClusterName() - s.RouteTableSpecs().Return([]azure.RouteTableSpec{{ - Name: "my-routetable", - }}) - s.RouteTable().AnyTimes().Return(&infrav1.RouteTable{Name: "my-routetable"}) + s.RouteTableSpecs().Return([]azure.RouteTableSpec{ + { + Name: "my-cp-routetable", + Subnet: &infrav1.SubnetSpec{ + Name: "control-plane-subnet", + Role: infrav1.SubnetControlPlane, + }, + }, + { + Name: "my-node-routetable", + Subnet: &infrav1.SubnetSpec{ + Name: "node-subnet", + Role: infrav1.SubnetNode, + }, + }, + }) + s.ControlPlaneRouteTable().AnyTimes().Return(&infrav1.RouteTable{Name: "my-cp-routetable"}) + s.ResourceGroup().Return("my-rg") + m.Delete(context.TODO(), "my-rg", "my-cp-routetable").Return(autorest.NewErrorWithResponse("", "", &http.Response{StatusCode: 404}, "Not Found")) + s.NodeRouteTable().AnyTimes().Return(&infrav1.RouteTable{Name: "my-node-routetable"}) s.ResourceGroup().Return("my-rg") - m.Delete(context.TODO(), "my-rg", "my-routetable").Return(autorest.NewErrorWithResponse("", "", &http.Response{StatusCode: 404}, "Not Found")) + m.Delete(context.TODO(), "my-rg", "my-node-routetable").Return(autorest.NewErrorWithResponse("", "", &http.Response{StatusCode: 404}, "Not Found")) }, }, { @@ -269,7 +347,7 @@ func TestDeleteRouteTable(t *testing.T) { "sigs.k8s.io_cluster-api-provider-azure_cluster_test-cluster": "owned", "sigs.k8s.io_cluster-api-provider-azure_role": "common", }, - expectedError: "failed to delete route table my-routetable in resource group my-rg: #: Internal Server Error: StatusCode=500", + expectedError: "failed to delete route table my-cp-routetable in resource group my-rg: #: Internal Server Error: StatusCode=500", expect: func(s *mock_routetables.MockRouteTableScopeMockRecorder, m *mock_routetables.MockClientMockRecorder) { s.Vnet().Return(&infrav1.VnetSpec{ Name: "my-vnet", @@ -277,11 +355,16 @@ func TestDeleteRouteTable(t *testing.T) { s.V(gomock.AssignableToTypeOf(2)).AnyTimes().Return(klogr.New()) s.ClusterName() s.RouteTableSpecs().Return([]azure.RouteTableSpec{{ - Name: "my-routetable", + Name: "my-cp-routetable", + Subnet: &infrav1.SubnetSpec{ + Name: "control-plane-subnet", + Role: infrav1.SubnetControlPlane, + }, }}) - s.RouteTable().AnyTimes().Return(&infrav1.RouteTable{Name: "my-routetable"}) + s.ControlPlaneRouteTable().AnyTimes().Return(&infrav1.RouteTable{Name: "my-cp-routetable"}) s.ResourceGroup().AnyTimes().Return("my-rg") - m.Delete(context.TODO(), "my-rg", "my-routetable").Return(autorest.NewErrorWithResponse("", "", &http.Response{StatusCode: 500}, "Internal Server Error")) + m.Delete(context.TODO(), "my-rg", "my-cp-routetable").Return(autorest.NewErrorWithResponse("", "", &http.Response{StatusCode: 500}, "Internal Server Error")) + s.NodeRouteTable().Times(0) }, }, } diff --git a/cloud/services/scalesets/mock_scalesets/scalesets_mock.go b/cloud/services/scalesets/mock_scalesets/scalesets_mock.go index 21ff3d299ebe..b6c405618142 100644 --- a/cloud/services/scalesets/mock_scalesets/scalesets_mock.go +++ b/cloud/services/scalesets/mock_scalesets/scalesets_mock.go @@ -263,18 +263,32 @@ func (mr *MockScaleSetScopeMockRecorder) ControlPlaneSubnet() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ControlPlaneSubnet", reflect.TypeOf((*MockScaleSetScope)(nil).ControlPlaneSubnet)) } -// RouteTable mocks base method. -func (m *MockScaleSetScope) RouteTable() *v1alpha3.RouteTable { +// NodeRouteTable mocks base method. +func (m *MockScaleSetScope) NodeRouteTable() *v1alpha3.RouteTable { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "RouteTable") + ret := m.ctrl.Call(m, "NodeRouteTable") ret0, _ := ret[0].(*v1alpha3.RouteTable) return ret0 } -// RouteTable indicates an expected call of RouteTable. -func (mr *MockScaleSetScopeMockRecorder) RouteTable() *gomock.Call { +// NodeRouteTable indicates an expected call of NodeRouteTable. +func (mr *MockScaleSetScopeMockRecorder) NodeRouteTable() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RouteTable", reflect.TypeOf((*MockScaleSetScope)(nil).RouteTable)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeRouteTable", reflect.TypeOf((*MockScaleSetScope)(nil).NodeRouteTable)) +} + +// ControlPlaneRouteTable mocks base method. +func (m *MockScaleSetScope) ControlPlaneRouteTable() *v1alpha3.RouteTable { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ControlPlaneRouteTable") + ret0, _ := ret[0].(*v1alpha3.RouteTable) + return ret0 +} + +// ControlPlaneRouteTable indicates an expected call of ControlPlaneRouteTable. +func (mr *MockScaleSetScopeMockRecorder) ControlPlaneRouteTable() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ControlPlaneRouteTable", reflect.TypeOf((*MockScaleSetScope)(nil).ControlPlaneRouteTable)) } // Info mocks base method. diff --git a/cloud/services/securitygroups/mock_securitygroups/securitygroups_mock.go b/cloud/services/securitygroups/mock_securitygroups/securitygroups_mock.go index d2f14290ef71..1461a0edfe54 100644 --- a/cloud/services/securitygroups/mock_securitygroups/securitygroups_mock.go +++ b/cloud/services/securitygroups/mock_securitygroups/securitygroups_mock.go @@ -262,18 +262,32 @@ func (mr *MockNSGScopeMockRecorder) ControlPlaneSubnet() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ControlPlaneSubnet", reflect.TypeOf((*MockNSGScope)(nil).ControlPlaneSubnet)) } -// RouteTable mocks base method. -func (m *MockNSGScope) RouteTable() *v1alpha3.RouteTable { +// NodeRouteTable mocks base method. +func (m *MockNSGScope) NodeRouteTable() *v1alpha3.RouteTable { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "RouteTable") + ret := m.ctrl.Call(m, "NodeRouteTable") ret0, _ := ret[0].(*v1alpha3.RouteTable) return ret0 } -// RouteTable indicates an expected call of RouteTable. -func (mr *MockNSGScopeMockRecorder) RouteTable() *gomock.Call { +// NodeRouteTable indicates an expected call of NodeRouteTable. +func (mr *MockNSGScopeMockRecorder) NodeRouteTable() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RouteTable", reflect.TypeOf((*MockNSGScope)(nil).RouteTable)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeRouteTable", reflect.TypeOf((*MockNSGScope)(nil).NodeRouteTable)) +} + +// ControlPlaneRouteTable mocks base method. +func (m *MockNSGScope) ControlPlaneRouteTable() *v1alpha3.RouteTable { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ControlPlaneRouteTable") + ret0, _ := ret[0].(*v1alpha3.RouteTable) + return ret0 +} + +// ControlPlaneRouteTable indicates an expected call of ControlPlaneRouteTable. +func (mr *MockNSGScopeMockRecorder) ControlPlaneRouteTable() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ControlPlaneRouteTable", reflect.TypeOf((*MockNSGScope)(nil).ControlPlaneRouteTable)) } // Info mocks base method. diff --git a/cloud/services/subnets/mock_subnets/subnets_mock.go b/cloud/services/subnets/mock_subnets/subnets_mock.go index b58446e416a4..3776a45b4b5b 100644 --- a/cloud/services/subnets/mock_subnets/subnets_mock.go +++ b/cloud/services/subnets/mock_subnets/subnets_mock.go @@ -262,18 +262,32 @@ func (mr *MockSubnetScopeMockRecorder) ControlPlaneSubnet() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ControlPlaneSubnet", reflect.TypeOf((*MockSubnetScope)(nil).ControlPlaneSubnet)) } -// RouteTable mocks base method. -func (m *MockSubnetScope) RouteTable() *v1alpha3.RouteTable { +// NodeRouteTable mocks base method. +func (m *MockSubnetScope) NodeRouteTable() *v1alpha3.RouteTable { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "RouteTable") + ret := m.ctrl.Call(m, "NodeRouteTable") ret0, _ := ret[0].(*v1alpha3.RouteTable) return ret0 } -// RouteTable indicates an expected call of RouteTable. -func (mr *MockSubnetScopeMockRecorder) RouteTable() *gomock.Call { +// NodeRouteTable indicates an expected call of NodeRouteTable. +func (mr *MockSubnetScopeMockRecorder) NodeRouteTable() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RouteTable", reflect.TypeOf((*MockSubnetScope)(nil).RouteTable)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeRouteTable", reflect.TypeOf((*MockSubnetScope)(nil).NodeRouteTable)) +} + +// ControlPlaneRouteTable mocks base method. +func (m *MockSubnetScope) ControlPlaneRouteTable() *v1alpha3.RouteTable { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ControlPlaneRouteTable") + ret0, _ := ret[0].(*v1alpha3.RouteTable) + return ret0 +} + +// ControlPlaneRouteTable indicates an expected call of ControlPlaneRouteTable. +func (mr *MockSubnetScopeMockRecorder) ControlPlaneRouteTable() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ControlPlaneRouteTable", reflect.TypeOf((*MockSubnetScope)(nil).ControlPlaneRouteTable)) } // Info mocks base method. diff --git a/cloud/services/tags/mock_tags/tags_mock.go b/cloud/services/tags/mock_tags/tags_mock.go index e0d7d712d884..e4fc02c0373a 100644 --- a/cloud/services/tags/mock_tags/tags_mock.go +++ b/cloud/services/tags/mock_tags/tags_mock.go @@ -262,18 +262,32 @@ func (mr *MockTagScopeMockRecorder) ControlPlaneSubnet() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ControlPlaneSubnet", reflect.TypeOf((*MockTagScope)(nil).ControlPlaneSubnet)) } -// RouteTable mocks base method. -func (m *MockTagScope) RouteTable() *v1alpha3.RouteTable { +// NodeRouteTable mocks base method. +func (m *MockTagScope) NodeRouteTable() *v1alpha3.RouteTable { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "RouteTable") + ret := m.ctrl.Call(m, "NodeRouteTable") ret0, _ := ret[0].(*v1alpha3.RouteTable) return ret0 } -// RouteTable indicates an expected call of RouteTable. -func (mr *MockTagScopeMockRecorder) RouteTable() *gomock.Call { +// NodeRouteTable indicates an expected call of NodeRouteTable. +func (mr *MockTagScopeMockRecorder) NodeRouteTable() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RouteTable", reflect.TypeOf((*MockTagScope)(nil).RouteTable)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeRouteTable", reflect.TypeOf((*MockTagScope)(nil).NodeRouteTable)) +} + +// ControlPlaneRouteTable mocks base method. +func (m *MockTagScope) ControlPlaneRouteTable() *v1alpha3.RouteTable { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ControlPlaneRouteTable") + ret0, _ := ret[0].(*v1alpha3.RouteTable) + return ret0 +} + +// ControlPlaneRouteTable indicates an expected call of ControlPlaneRouteTable. +func (mr *MockTagScopeMockRecorder) ControlPlaneRouteTable() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ControlPlaneRouteTable", reflect.TypeOf((*MockTagScope)(nil).ControlPlaneRouteTable)) } // Info mocks base method. diff --git a/cloud/services/virtualmachines/mock_virtualmachines/virtualmachines_mock.go b/cloud/services/virtualmachines/mock_virtualmachines/virtualmachines_mock.go index 1c58966eff3e..a352a68cb58a 100644 --- a/cloud/services/virtualmachines/mock_virtualmachines/virtualmachines_mock.go +++ b/cloud/services/virtualmachines/mock_virtualmachines/virtualmachines_mock.go @@ -264,18 +264,32 @@ func (mr *MockVMScopeMockRecorder) ControlPlaneSubnet() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ControlPlaneSubnet", reflect.TypeOf((*MockVMScope)(nil).ControlPlaneSubnet)) } -// RouteTable mocks base method. -func (m *MockVMScope) RouteTable() *v1alpha3.RouteTable { +// NodeRouteTable mocks base method. +func (m *MockVMScope) NodeRouteTable() *v1alpha3.RouteTable { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "RouteTable") + ret := m.ctrl.Call(m, "NodeRouteTable") ret0, _ := ret[0].(*v1alpha3.RouteTable) return ret0 } -// RouteTable indicates an expected call of RouteTable. -func (mr *MockVMScopeMockRecorder) RouteTable() *gomock.Call { +// NodeRouteTable indicates an expected call of NodeRouteTable. +func (mr *MockVMScopeMockRecorder) NodeRouteTable() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RouteTable", reflect.TypeOf((*MockVMScope)(nil).RouteTable)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeRouteTable", reflect.TypeOf((*MockVMScope)(nil).NodeRouteTable)) +} + +// ControlPlaneRouteTable mocks base method. +func (m *MockVMScope) ControlPlaneRouteTable() *v1alpha3.RouteTable { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ControlPlaneRouteTable") + ret0, _ := ret[0].(*v1alpha3.RouteTable) + return ret0 +} + +// ControlPlaneRouteTable indicates an expected call of ControlPlaneRouteTable. +func (mr *MockVMScopeMockRecorder) ControlPlaneRouteTable() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ControlPlaneRouteTable", reflect.TypeOf((*MockVMScope)(nil).ControlPlaneRouteTable)) } // Info mocks base method. diff --git a/cloud/services/virtualnetworks/mock_virtualnetworks/virtualnetworks_mock.go b/cloud/services/virtualnetworks/mock_virtualnetworks/virtualnetworks_mock.go index c7681cd2c44b..9d7c870e5f3f 100644 --- a/cloud/services/virtualnetworks/mock_virtualnetworks/virtualnetworks_mock.go +++ b/cloud/services/virtualnetworks/mock_virtualnetworks/virtualnetworks_mock.go @@ -356,18 +356,32 @@ func (mr *MockVNetScopeMockRecorder) ControlPlaneSubnet() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ControlPlaneSubnet", reflect.TypeOf((*MockVNetScope)(nil).ControlPlaneSubnet)) } -// RouteTable mocks base method. -func (m *MockVNetScope) RouteTable() *v1alpha3.RouteTable { +// NodeRouteTable mocks base method. +func (m *MockVNetScope) NodeRouteTable() *v1alpha3.RouteTable { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "RouteTable") + ret := m.ctrl.Call(m, "NodeRouteTable") ret0, _ := ret[0].(*v1alpha3.RouteTable) return ret0 } -// RouteTable indicates an expected call of RouteTable. -func (mr *MockVNetScopeMockRecorder) RouteTable() *gomock.Call { +// NodeRouteTable indicates an expected call of NodeRouteTable. +func (mr *MockVNetScopeMockRecorder) NodeRouteTable() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RouteTable", reflect.TypeOf((*MockVNetScope)(nil).RouteTable)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NodeRouteTable", reflect.TypeOf((*MockVNetScope)(nil).NodeRouteTable)) +} + +// ControlPlaneRouteTable mocks base method. +func (m *MockVNetScope) ControlPlaneRouteTable() *v1alpha3.RouteTable { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ControlPlaneRouteTable") + ret0, _ := ret[0].(*v1alpha3.RouteTable) + return ret0 +} + +// ControlPlaneRouteTable indicates an expected call of ControlPlaneRouteTable. +func (mr *MockVNetScopeMockRecorder) ControlPlaneRouteTable() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ControlPlaneRouteTable", reflect.TypeOf((*MockVNetScope)(nil).ControlPlaneRouteTable)) } // VNetSpecs mocks base method. diff --git a/cloud/types.go b/cloud/types.go index 87eb2b963995..8761b96acd92 100644 --- a/cloud/types.go +++ b/cloud/types.go @@ -60,9 +60,13 @@ type LBSpec struct { APIServerPort int32 } +// RouteTableRole defines the unique role of a route table. +type RouteTableRole string + // RouteTableSpec defines the specification for a Route Table. type RouteTableSpec struct { - Name string + Name string + Subnet *infrav1.SubnetSpec } // InboundNatSpec defines the specification for an inbound NAT rule. diff --git a/controllers/azurecluster_reconciler.go b/controllers/azurecluster_reconciler.go index d253cb1f2834..bec548cb79a2 100644 --- a/controllers/azurecluster_reconciler.go +++ b/controllers/azurecluster_reconciler.go @@ -19,8 +19,9 @@ package controllers import ( "context" "fmt" - "github.com/pkg/errors" "hash/fnv" + + "github.com/pkg/errors" clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3" azure "sigs.k8s.io/cluster-api-provider-azure/cloud" diff --git a/controllers/helpers.go b/controllers/helpers.go index ae3313188a83..e6464b5c5d9f 100644 --- a/controllers/helpers.go +++ b/controllers/helpers.go @@ -225,7 +225,7 @@ func newCloudProviderConfig(d azure.ClusterDescriber) *CloudProviderConfig { VnetName: d.Vnet().Name, VnetResourceGroup: d.Vnet().ResourceGroup, SubnetName: d.NodeSubnet().Name, - RouteTableName: fmt.Sprintf("%s-node-routetable", d.ClusterName()), + RouteTableName: d.NodeRouteTable().Name, LoadBalancerSku: "Standard", MaximumLoadBalancerRuleCount: 250, UseManagedIdentityExtension: false,