diff --git a/api/v1alpha3/azurecluster_default.go b/api/v1alpha3/azurecluster_default.go index 6807adcec2f..6903512f48d 100644 --- a/api/v1alpha3/azurecluster_default.go +++ b/api/v1alpha3/azurecluster_default.go @@ -88,9 +88,6 @@ func (c *AzureCluster) setSubnetDefaults() { if cpSubnet.SecurityGroup.Name == "" { cpSubnet.SecurityGroup.Name = generateControlPlaneSecurityGroupName(c.ObjectMeta.Name) } - if cpSubnet.RouteTable.Name == "" { - cpSubnet.RouteTable.Name = generateRouteTableName(c.ObjectMeta.Name) - } if nodeSubnet.Name == "" { nodeSubnet.Name = generateNodeSubnetName(c.ObjectMeta.Name) @@ -102,7 +99,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) } } @@ -131,7 +128,7 @@ 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 { +// 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 ec2a220581e..d8becddcb11 100644 --- a/api/v1alpha3/azurecluster_default_test.go +++ b/api/v1alpha3/azurecluster_default_test.go @@ -250,7 +250,7 @@ func TestSubnetDefaults(t *testing.T) { Name: "cluster-test-controlplane-subnet", CIDRBlocks: []string{DefaultControlPlaneSubnetCIDR}, SecurityGroup: SecurityGroup{Name: "cluster-test-controlplane-nsg"}, - RouteTable: RouteTable{Name: "cluster-test-node-routetable"}, + RouteTable: RouteTable{}, }, { Role: SubnetNode, @@ -299,7 +299,7 @@ func TestSubnetDefaults(t *testing.T) { Name: "my-controlplane-subnet", CIDRBlocks: []string{"10.0.0.16/24"}, SecurityGroup: SecurityGroup{Name: "cluster-test-controlplane-nsg"}, - RouteTable: RouteTable{Name: "cluster-test-node-routetable"}, + RouteTable: RouteTable{}, }, { Role: SubnetNode, @@ -346,8 +346,58 @@ func TestSubnetDefaults(t *testing.T) { Name: "cluster-test-controlplane-subnet", CIDRBlocks: []string{DefaultControlPlaneSubnetCIDR}, SecurityGroup: SecurityGroup{Name: "cluster-test-controlplane-nsg"}, + RouteTable: RouteTable{}, + }, + { + Role: SubnetNode, + Name: "cluster-test-node-subnet", + CIDRBlocks: []string{DefaultNodeSubnetCIDR}, + SecurityGroup: SecurityGroup{Name: "cluster-test-node-nsg"}, RouteTable: RouteTable{Name: "cluster-test-node-routetable"}, }, + }, + }, + }, + }, + }, + { + name: "subnets route tables specified", + cluster: &AzureCluster{ + ObjectMeta: v1.ObjectMeta{ + Name: "cluster-test", + }, + Spec: AzureClusterSpec{ + NetworkSpec: NetworkSpec{ + Subnets: Subnets{ + { + Role: SubnetControlPlane, + Name: "cluster-test-controlplane-subnet", + RouteTable: RouteTable{ + Name: "control-plane-custom-route-table", + }, + }, + { + Role: SubnetNode, + Name: "cluster-test-node-subnet", + }, + }, + }, + }, + }, + output: &AzureCluster{ + ObjectMeta: v1.ObjectMeta{ + Name: "cluster-test", + }, + Spec: AzureClusterSpec{ + NetworkSpec: NetworkSpec{ + Subnets: Subnets{ + { + Role: SubnetControlPlane, + Name: "cluster-test-controlplane-subnet", + CIDRBlocks: []string{DefaultControlPlaneSubnetCIDR}, + SecurityGroup: SecurityGroup{Name: "cluster-test-controlplane-nsg"}, + RouteTable: RouteTable{Name: "control-plane-custom-route-table"}, + }, { Role: SubnetNode, Name: "cluster-test-node-subnet", @@ -396,7 +446,7 @@ func TestSubnetDefaults(t *testing.T) { Name: "cluster-test-controlplane-subnet", CIDRBlocks: []string{DefaultControlPlaneSubnetCIDR}, SecurityGroup: SecurityGroup{Name: "cluster-test-controlplane-nsg"}, - RouteTable: RouteTable{Name: "cluster-test-node-routetable"}, + RouteTable: RouteTable{}, }, }, }, @@ -444,7 +494,7 @@ func TestSubnetDefaults(t *testing.T) { Name: "cluster-test-controlplane-subnet", CIDRBlocks: []string{"2001:beef::1/64"}, SecurityGroup: SecurityGroup{Name: "cluster-test-controlplane-nsg"}, - RouteTable: RouteTable{Name: "cluster-test-node-routetable"}, + RouteTable: RouteTable{}, }, { Role: SubnetNode, diff --git a/cloud/interfaces.go b/cloud/interfaces.go index 8f8515fcf4f..2e6b3417de8 100644 --- a/cloud/interfaces.go +++ b/cloud/interfaces.go @@ -67,6 +67,7 @@ type ClusterDescriber interface { IsVnetManaged() bool NodeSubnet() *infrav1.SubnetSpec ControlPlaneSubnet() *infrav1.SubnetSpec - RouteTable() *infrav1.RouteTable IsIPv6Enabled() bool + NodeRouteTable() *infrav1.RouteTable + ControlPlaneRouteTable() *infrav1.RouteTable } diff --git a/cloud/mocks/service_mock.go b/cloud/mocks/service_mock.go index 2507127e509..b3f92dd15a7 100644 --- a/cloud/mocks/service_mock.go +++ b/cloud/mocks/service_mock.go @@ -550,30 +550,44 @@ 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 { +// IsIPv6Enabled mocks base method. +func (m *MockClusterDescriber) IsIPv6Enabled() bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IsIPv6Enabled") + ret0, _ := ret[0].(bool) + return ret0 +} + +// IsIPv6Enabled indicates an expected call of IsIPv6Enabled. +func (mr *MockClusterDescriberMockRecorder) IsIPv6Enabled() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsIPv6Enabled", reflect.TypeOf((*MockClusterDescriber)(nil).IsIPv6Enabled)) +} + +// 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)) } -// IsIPv6Enabled mocks base method. -func (m *MockClusterDescriber) IsIPv6Enabled() bool { +// ControlPlaneRouteTable mocks base method. +func (m *MockClusterDescriber) ControlPlaneRouteTable() *v1alpha3.RouteTable { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "IsIPv6Enabled") - ret0, _ := ret[0].(bool) + ret := m.ctrl.Call(m, "ControlPlaneRouteTable") + ret0, _ := ret[0].(*v1alpha3.RouteTable) return ret0 } -// IsIPv6Enabled indicates an expected call of IsIPv6Enabled. -func (mr *MockClusterDescriberMockRecorder) IsIPv6Enabled() *gomock.Call { +// 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, "IsIPv6Enabled", reflect.TypeOf((*MockClusterDescriber)(nil).IsIPv6Enabled)) + 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 964cde426a7..d41d0b59480 100644 --- a/cloud/scope/cluster.go +++ b/cloud/scope/cluster.go @@ -19,9 +19,10 @@ package scope import ( "context" "fmt" - "k8s.io/utils/net" "strconv" + "k8s.io/utils/net" + "github.com/Azure/go-autorest/autorest/to" "github.com/Azure/go-autorest/autorest" @@ -152,11 +153,16 @@ func (s *ClusterScope) LBSpecs() []azure.LBSpec { return specs } -// 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, - }} + routetables := []azure.RouteTableSpec{} + if s.ControlPlaneRouteTable().Name != "" { + routetables = append(routetables, azure.RouteTableSpec{Name: s.ControlPlaneRouteTable().Name, Subnet: s.ControlPlaneSubnet()}) + } + if s.NodeRouteTable().Name != "" { + routetables = append(routetables, azure.RouteTableSpec{Name: s.NodeRouteTable().Name, Subnet: s.NodeSubnet()}) + } + return routetables } // NSGSpecs returns the security group specs. @@ -196,7 +202,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{ { @@ -242,8 +248,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 } @@ -320,6 +331,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 d9edbc2824d..3007d7538fd 100644 --- a/cloud/services/bastionhosts/mocks_bastionhosts/bastionhosts_mock.go +++ b/cloud/services/bastionhosts/mocks_bastionhosts/bastionhosts_mock.go @@ -262,32 +262,46 @@ 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 { +// IsIPv6Enabled mocks base method. +func (m *MockBastionScope) IsIPv6Enabled() bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IsIPv6Enabled") + ret0, _ := ret[0].(bool) + return ret0 +} + +// IsIPv6Enabled indicates an expected call of IsIPv6Enabled. +func (mr *MockBastionScopeMockRecorder) IsIPv6Enabled() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsIPv6Enabled", reflect.TypeOf((*MockBastionScope)(nil).IsIPv6Enabled)) +} + +// 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)) } -// IsIPv6Enabled mocks base method. -func (m *MockBastionScope) IsIPv6Enabled() bool { +// ControlPlaneRouteTable mocks base method. +func (m *MockBastionScope) ControlPlaneRouteTable() *v1alpha3.RouteTable { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "IsIPv6Enabled") - ret0, _ := ret[0].(bool) + ret := m.ctrl.Call(m, "ControlPlaneRouteTable") + ret0, _ := ret[0].(*v1alpha3.RouteTable) return ret0 } -// IsIPv6Enabled indicates an expected call of IsIPv6Enabled. -func (mr *MockBastionScopeMockRecorder) IsIPv6Enabled() *gomock.Call { +// 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, "IsIPv6Enabled", reflect.TypeOf((*MockBastionScope)(nil).IsIPv6Enabled)) + 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 a76d3377695..8bb46474f2d 100644 --- a/cloud/services/disks/mock_disks/disks_mock.go +++ b/cloud/services/disks/mock_disks/disks_mock.go @@ -356,32 +356,46 @@ 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 { +// IsIPv6Enabled mocks base method. +func (m *MockDiskScope) IsIPv6Enabled() bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IsIPv6Enabled") + ret0, _ := ret[0].(bool) + return ret0 +} + +// IsIPv6Enabled indicates an expected call of IsIPv6Enabled. +func (mr *MockDiskScopeMockRecorder) IsIPv6Enabled() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsIPv6Enabled", reflect.TypeOf((*MockDiskScope)(nil).IsIPv6Enabled)) +} + +// 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)) } -// IsIPv6Enabled mocks base method. -func (m *MockDiskScope) IsIPv6Enabled() bool { +// ControlPlaneRouteTable mocks base method. +func (m *MockDiskScope) ControlPlaneRouteTable() *v1alpha3.RouteTable { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "IsIPv6Enabled") - ret0, _ := ret[0].(bool) + ret := m.ctrl.Call(m, "ControlPlaneRouteTable") + ret0, _ := ret[0].(*v1alpha3.RouteTable) return ret0 } -// IsIPv6Enabled indicates an expected call of IsIPv6Enabled. -func (mr *MockDiskScopeMockRecorder) IsIPv6Enabled() *gomock.Call { +// 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, "IsIPv6Enabled", reflect.TypeOf((*MockDiskScope)(nil).IsIPv6Enabled)) + 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 49514ec1699..885afcc6c80 100644 --- a/cloud/services/inboundnatrules/mock_inboundnatrules/inboundnatrules_mock.go +++ b/cloud/services/inboundnatrules/mock_inboundnatrules/inboundnatrules_mock.go @@ -356,32 +356,46 @@ 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 { +// IsIPv6Enabled mocks base method. +func (m *MockInboundNatScope) IsIPv6Enabled() bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IsIPv6Enabled") + ret0, _ := ret[0].(bool) + return ret0 +} + +// IsIPv6Enabled indicates an expected call of IsIPv6Enabled. +func (mr *MockInboundNatScopeMockRecorder) IsIPv6Enabled() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsIPv6Enabled", reflect.TypeOf((*MockInboundNatScope)(nil).IsIPv6Enabled)) +} + +// 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)) } -// IsIPv6Enabled mocks base method. -func (m *MockInboundNatScope) IsIPv6Enabled() bool { +// ControlPlaneRouteTable mocks base method. +func (m *MockInboundNatScope) ControlPlaneRouteTable() *v1alpha3.RouteTable { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "IsIPv6Enabled") - ret0, _ := ret[0].(bool) + ret := m.ctrl.Call(m, "ControlPlaneRouteTable") + ret0, _ := ret[0].(*v1alpha3.RouteTable) return ret0 } -// IsIPv6Enabled indicates an expected call of IsIPv6Enabled. -func (mr *MockInboundNatScopeMockRecorder) IsIPv6Enabled() *gomock.Call { +// 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, "IsIPv6Enabled", reflect.TypeOf((*MockInboundNatScope)(nil).IsIPv6Enabled)) + 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 ac1733cdc96..e191b52f848 100644 --- a/cloud/services/loadbalancers/mock_loadbalancers/loadbalancers_mock.go +++ b/cloud/services/loadbalancers/mock_loadbalancers/loadbalancers_mock.go @@ -262,32 +262,46 @@ 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 { +// IsIPv6Enabled mocks base method. +func (m *MockLBScope) IsIPv6Enabled() bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IsIPv6Enabled") + ret0, _ := ret[0].(bool) + return ret0 +} + +// IsIPv6Enabled indicates an expected call of IsIPv6Enabled. +func (mr *MockLBScopeMockRecorder) IsIPv6Enabled() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsIPv6Enabled", reflect.TypeOf((*MockLBScope)(nil).IsIPv6Enabled)) +} + +// 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)) } -// IsIPv6Enabled mocks base method. -func (m *MockLBScope) IsIPv6Enabled() bool { +// ControlPlaneRouteTable mocks base method. +func (m *MockLBScope) ControlPlaneRouteTable() *v1alpha3.RouteTable { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "IsIPv6Enabled") - ret0, _ := ret[0].(bool) + ret := m.ctrl.Call(m, "ControlPlaneRouteTable") + ret0, _ := ret[0].(*v1alpha3.RouteTable) return ret0 } -// IsIPv6Enabled indicates an expected call of IsIPv6Enabled. -func (mr *MockLBScopeMockRecorder) IsIPv6Enabled() *gomock.Call { +// 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, "IsIPv6Enabled", reflect.TypeOf((*MockLBScope)(nil).IsIPv6Enabled)) + 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 b0654a303eb..d93aa183492 100644 --- a/cloud/services/networkinterfaces/mock_networkinterfaces/networkinterfaces_mock.go +++ b/cloud/services/networkinterfaces/mock_networkinterfaces/networkinterfaces_mock.go @@ -262,32 +262,46 @@ 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 { +// IsIPv6Enabled mocks base method. +func (m *MockNICScope) IsIPv6Enabled() bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IsIPv6Enabled") + ret0, _ := ret[0].(bool) + return ret0 +} + +// IsIPv6Enabled indicates an expected call of IsIPv6Enabled. +func (mr *MockNICScopeMockRecorder) IsIPv6Enabled() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsIPv6Enabled", reflect.TypeOf((*MockNICScope)(nil).IsIPv6Enabled)) +} + +// 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)) } -// IsIPv6Enabled mocks base method. -func (m *MockNICScope) IsIPv6Enabled() bool { +// ControlPlaneRouteTable mocks base method. +func (m *MockNICScope) ControlPlaneRouteTable() *v1alpha3.RouteTable { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "IsIPv6Enabled") - ret0, _ := ret[0].(bool) + ret := m.ctrl.Call(m, "ControlPlaneRouteTable") + ret0, _ := ret[0].(*v1alpha3.RouteTable) return ret0 } -// IsIPv6Enabled indicates an expected call of IsIPv6Enabled. -func (mr *MockNICScopeMockRecorder) IsIPv6Enabled() *gomock.Call { +// 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, "IsIPv6Enabled", reflect.TypeOf((*MockNICScope)(nil).IsIPv6Enabled)) + 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 dfdc0a3a0b6..2148685b1c3 100644 --- a/cloud/services/publicips/mock_publicips/publicips_mock.go +++ b/cloud/services/publicips/mock_publicips/publicips_mock.go @@ -356,32 +356,46 @@ 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 { +// IsIPv6Enabled mocks base method. +func (m *MockPublicIPScope) IsIPv6Enabled() bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IsIPv6Enabled") + ret0, _ := ret[0].(bool) + return ret0 +} + +// IsIPv6Enabled indicates an expected call of IsIPv6Enabled. +func (mr *MockPublicIPScopeMockRecorder) IsIPv6Enabled() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsIPv6Enabled", reflect.TypeOf((*MockPublicIPScope)(nil).IsIPv6Enabled)) +} + +// 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)) } -// IsIPv6Enabled mocks base method. -func (m *MockPublicIPScope) IsIPv6Enabled() bool { +// ControlPlaneRouteTable mocks base method. +func (m *MockPublicIPScope) ControlPlaneRouteTable() *v1alpha3.RouteTable { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "IsIPv6Enabled") - ret0, _ := ret[0].(bool) + ret := m.ctrl.Call(m, "ControlPlaneRouteTable") + ret0, _ := ret[0].(*v1alpha3.RouteTable) return ret0 } -// IsIPv6Enabled indicates an expected call of IsIPv6Enabled. -func (mr *MockPublicIPScopeMockRecorder) IsIPv6Enabled() *gomock.Call { +// 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, "IsIPv6Enabled", reflect.TypeOf((*MockPublicIPScope)(nil).IsIPv6Enabled)) + 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 1e96f342ea0..87c82429132 100644 --- a/cloud/services/roleassignments/mock_roleassignments/roleassignments_mock.go +++ b/cloud/services/roleassignments/mock_roleassignments/roleassignments_mock.go @@ -356,32 +356,46 @@ 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 { +// IsIPv6Enabled mocks base method. +func (m *MockRoleAssignmentScope) IsIPv6Enabled() bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IsIPv6Enabled") + ret0, _ := ret[0].(bool) + return ret0 +} + +// IsIPv6Enabled indicates an expected call of IsIPv6Enabled. +func (mr *MockRoleAssignmentScopeMockRecorder) IsIPv6Enabled() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsIPv6Enabled", reflect.TypeOf((*MockRoleAssignmentScope)(nil).IsIPv6Enabled)) +} + +// 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)) } -// IsIPv6Enabled mocks base method. -func (m *MockRoleAssignmentScope) IsIPv6Enabled() bool { +// ControlPlaneRouteTable mocks base method. +func (m *MockRoleAssignmentScope) ControlPlaneRouteTable() *v1alpha3.RouteTable { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "IsIPv6Enabled") - ret0, _ := ret[0].(bool) + ret := m.ctrl.Call(m, "ControlPlaneRouteTable") + ret0, _ := ret[0].(*v1alpha3.RouteTable) return ret0 } -// IsIPv6Enabled indicates an expected call of IsIPv6Enabled. -func (mr *MockRoleAssignmentScopeMockRecorder) IsIPv6Enabled() *gomock.Call { +// 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, "IsIPv6Enabled", reflect.TypeOf((*MockRoleAssignmentScope)(nil).IsIPv6Enabled)) + 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 f1f20bee736..74bf7f44742 100644 --- a/cloud/services/routetables/mock_routetables/routetables_mock.go +++ b/cloud/services/routetables/mock_routetables/routetables_mock.go @@ -262,32 +262,46 @@ 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 { +// IsIPv6Enabled mocks base method. +func (m *MockRouteTableScope) IsIPv6Enabled() bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IsIPv6Enabled") + ret0, _ := ret[0].(bool) + return ret0 +} + +// IsIPv6Enabled indicates an expected call of IsIPv6Enabled. +func (mr *MockRouteTableScopeMockRecorder) IsIPv6Enabled() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsIPv6Enabled", reflect.TypeOf((*MockRouteTableScope)(nil).IsIPv6Enabled)) +} + +// 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)) } -// IsIPv6Enabled mocks base method. -func (m *MockRouteTableScope) IsIPv6Enabled() bool { +// ControlPlaneRouteTable mocks base method. +func (m *MockRouteTableScope) ControlPlaneRouteTable() *v1alpha3.RouteTable { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "IsIPv6Enabled") - ret0, _ := ret[0].(bool) + ret := m.ctrl.Call(m, "ControlPlaneRouteTable") + ret0, _ := ret[0].(*v1alpha3.RouteTable) return ret0 } -// IsIPv6Enabled indicates an expected call of IsIPv6Enabled. -func (mr *MockRouteTableScopeMockRecorder) IsIPv6Enabled() *gomock.Call { +// 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, "IsIPv6Enabled", reflect.TypeOf((*MockRouteTableScope)(nil).IsIPv6Enabled)) + 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 308b6db81a6..c932060c8fb 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 b493e41d197..317a277fc51 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 aabf3f28928..3c6d280c409 100644 --- a/cloud/services/scalesets/mock_scalesets/scalesets_mock.go +++ b/cloud/services/scalesets/mock_scalesets/scalesets_mock.go @@ -263,32 +263,46 @@ 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 { +// IsIPv6Enabled mocks base method. +func (m *MockScaleSetScope) IsIPv6Enabled() bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IsIPv6Enabled") + ret0, _ := ret[0].(bool) + return ret0 +} + +// IsIPv6Enabled indicates an expected call of IsIPv6Enabled. +func (mr *MockScaleSetScopeMockRecorder) IsIPv6Enabled() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsIPv6Enabled", reflect.TypeOf((*MockScaleSetScope)(nil).IsIPv6Enabled)) +} + +// 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)) } -// IsIPv6Enabled mocks base method. -func (m *MockScaleSetScope) IsIPv6Enabled() bool { +// ControlPlaneRouteTable mocks base method. +func (m *MockScaleSetScope) ControlPlaneRouteTable() *v1alpha3.RouteTable { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "IsIPv6Enabled") - ret0, _ := ret[0].(bool) + ret := m.ctrl.Call(m, "ControlPlaneRouteTable") + ret0, _ := ret[0].(*v1alpha3.RouteTable) return ret0 } -// IsIPv6Enabled indicates an expected call of IsIPv6Enabled. -func (mr *MockScaleSetScopeMockRecorder) IsIPv6Enabled() *gomock.Call { +// 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, "IsIPv6Enabled", reflect.TypeOf((*MockScaleSetScope)(nil).IsIPv6Enabled)) + 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 0061e0a5a00..c7f1ef1a51e 100644 --- a/cloud/services/securitygroups/mock_securitygroups/securitygroups_mock.go +++ b/cloud/services/securitygroups/mock_securitygroups/securitygroups_mock.go @@ -262,32 +262,46 @@ 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 { +// IsIPv6Enabled mocks base method. +func (m *MockNSGScope) IsIPv6Enabled() bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IsIPv6Enabled") + ret0, _ := ret[0].(bool) + return ret0 +} + +// IsIPv6Enabled indicates an expected call of IsIPv6Enabled. +func (mr *MockNSGScopeMockRecorder) IsIPv6Enabled() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsIPv6Enabled", reflect.TypeOf((*MockNSGScope)(nil).IsIPv6Enabled)) +} + +// 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)) } -// IsIPv6Enabled mocks base method. -func (m *MockNSGScope) IsIPv6Enabled() bool { +// ControlPlaneRouteTable mocks base method. +func (m *MockNSGScope) ControlPlaneRouteTable() *v1alpha3.RouteTable { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "IsIPv6Enabled") - ret0, _ := ret[0].(bool) + ret := m.ctrl.Call(m, "ControlPlaneRouteTable") + ret0, _ := ret[0].(*v1alpha3.RouteTable) return ret0 } -// IsIPv6Enabled indicates an expected call of IsIPv6Enabled. -func (mr *MockNSGScopeMockRecorder) IsIPv6Enabled() *gomock.Call { +// 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, "IsIPv6Enabled", reflect.TypeOf((*MockNSGScope)(nil).IsIPv6Enabled)) + 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 0696299afa9..426e62d0ac0 100644 --- a/cloud/services/subnets/mock_subnets/subnets_mock.go +++ b/cloud/services/subnets/mock_subnets/subnets_mock.go @@ -262,32 +262,46 @@ 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 { +// IsIPv6Enabled mocks base method. +func (m *MockSubnetScope) IsIPv6Enabled() bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IsIPv6Enabled") + ret0, _ := ret[0].(bool) + return ret0 +} + +// IsIPv6Enabled indicates an expected call of IsIPv6Enabled. +func (mr *MockSubnetScopeMockRecorder) IsIPv6Enabled() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsIPv6Enabled", reflect.TypeOf((*MockSubnetScope)(nil).IsIPv6Enabled)) +} + +// 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)) } -// IsIPv6Enabled mocks base method. -func (m *MockSubnetScope) IsIPv6Enabled() bool { +// ControlPlaneRouteTable mocks base method. +func (m *MockSubnetScope) ControlPlaneRouteTable() *v1alpha3.RouteTable { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "IsIPv6Enabled") - ret0, _ := ret[0].(bool) + ret := m.ctrl.Call(m, "ControlPlaneRouteTable") + ret0, _ := ret[0].(*v1alpha3.RouteTable) return ret0 } -// IsIPv6Enabled indicates an expected call of IsIPv6Enabled. -func (mr *MockSubnetScopeMockRecorder) IsIPv6Enabled() *gomock.Call { +// 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, "IsIPv6Enabled", reflect.TypeOf((*MockSubnetScope)(nil).IsIPv6Enabled)) + 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 f6b9249f3c4..24ce2c32107 100644 --- a/cloud/services/tags/mock_tags/tags_mock.go +++ b/cloud/services/tags/mock_tags/tags_mock.go @@ -262,32 +262,46 @@ 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 { +// IsIPv6Enabled mocks base method. +func (m *MockTagScope) IsIPv6Enabled() bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IsIPv6Enabled") + ret0, _ := ret[0].(bool) + return ret0 +} + +// IsIPv6Enabled indicates an expected call of IsIPv6Enabled. +func (mr *MockTagScopeMockRecorder) IsIPv6Enabled() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsIPv6Enabled", reflect.TypeOf((*MockTagScope)(nil).IsIPv6Enabled)) +} + +// 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)) } -// IsIPv6Enabled mocks base method. -func (m *MockTagScope) IsIPv6Enabled() bool { +// ControlPlaneRouteTable mocks base method. +func (m *MockTagScope) ControlPlaneRouteTable() *v1alpha3.RouteTable { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "IsIPv6Enabled") - ret0, _ := ret[0].(bool) + ret := m.ctrl.Call(m, "ControlPlaneRouteTable") + ret0, _ := ret[0].(*v1alpha3.RouteTable) return ret0 } -// IsIPv6Enabled indicates an expected call of IsIPv6Enabled. -func (mr *MockTagScopeMockRecorder) IsIPv6Enabled() *gomock.Call { +// 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, "IsIPv6Enabled", reflect.TypeOf((*MockTagScope)(nil).IsIPv6Enabled)) + 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 0a57af15d70..77399690245 100644 --- a/cloud/services/virtualmachines/mock_virtualmachines/virtualmachines_mock.go +++ b/cloud/services/virtualmachines/mock_virtualmachines/virtualmachines_mock.go @@ -264,32 +264,46 @@ 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 { +// IsIPv6Enabled mocks base method. +func (m *MockVMScope) IsIPv6Enabled() bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IsIPv6Enabled") + ret0, _ := ret[0].(bool) + return ret0 +} + +// IsIPv6Enabled indicates an expected call of IsIPv6Enabled. +func (mr *MockVMScopeMockRecorder) IsIPv6Enabled() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsIPv6Enabled", reflect.TypeOf((*MockVMScope)(nil).IsIPv6Enabled)) +} + +// 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)) } -// IsIPv6Enabled mocks base method. -func (m *MockVMScope) IsIPv6Enabled() bool { +// ControlPlaneRouteTable mocks base method. +func (m *MockVMScope) ControlPlaneRouteTable() *v1alpha3.RouteTable { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "IsIPv6Enabled") - ret0, _ := ret[0].(bool) + ret := m.ctrl.Call(m, "ControlPlaneRouteTable") + ret0, _ := ret[0].(*v1alpha3.RouteTable) return ret0 } -// IsIPv6Enabled indicates an expected call of IsIPv6Enabled. -func (mr *MockVMScopeMockRecorder) IsIPv6Enabled() *gomock.Call { +// 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, "IsIPv6Enabled", reflect.TypeOf((*MockVMScope)(nil).IsIPv6Enabled)) + 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 05323b4666d..8eeb685722b 100644 --- a/cloud/services/virtualnetworks/mock_virtualnetworks/virtualnetworks_mock.go +++ b/cloud/services/virtualnetworks/mock_virtualnetworks/virtualnetworks_mock.go @@ -356,32 +356,46 @@ 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 { +// IsIPv6Enabled mocks base method. +func (m *MockVNetScope) IsIPv6Enabled() bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IsIPv6Enabled") + ret0, _ := ret[0].(bool) + return ret0 +} + +// IsIPv6Enabled indicates an expected call of IsIPv6Enabled. +func (mr *MockVNetScopeMockRecorder) IsIPv6Enabled() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsIPv6Enabled", reflect.TypeOf((*MockVNetScope)(nil).IsIPv6Enabled)) +} + +// 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)) } -// IsIPv6Enabled mocks base method. -func (m *MockVNetScope) IsIPv6Enabled() bool { +// ControlPlaneRouteTable mocks base method. +func (m *MockVNetScope) ControlPlaneRouteTable() *v1alpha3.RouteTable { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "IsIPv6Enabled") - ret0, _ := ret[0].(bool) + ret := m.ctrl.Call(m, "ControlPlaneRouteTable") + ret0, _ := ret[0].(*v1alpha3.RouteTable) return ret0 } -// IsIPv6Enabled indicates an expected call of IsIPv6Enabled. -func (mr *MockVNetScopeMockRecorder) IsIPv6Enabled() *gomock.Call { +// 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, "IsIPv6Enabled", reflect.TypeOf((*MockVNetScope)(nil).IsIPv6Enabled)) + 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 7b9e5f2c989..85033ed0d97 100644 --- a/cloud/types.go +++ b/cloud/types.go @@ -63,9 +63,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 6d07d51c4a1..1ea024bed39 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 c3a09ee7c04..67ad4762cbc 100644 --- a/controllers/helpers.go +++ b/controllers/helpers.go @@ -20,6 +20,7 @@ import ( "context" "encoding/json" "fmt" + "sigs.k8s.io/cluster-api-provider-azure/cloud/scope" "sigs.k8s.io/cluster-api-provider-azure/cloud/services/groups" @@ -223,7 +224,7 @@ func newCloudProviderConfig(d azure.ClusterDescriber) (controlPlaneConfig *Cloud 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, @@ -241,7 +242,7 @@ func newCloudProviderConfig(d azure.ClusterDescriber) (controlPlaneConfig *Cloud 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,