зеркало из https://github.com/Azure/ARO-RP.git
Subnets controller refactor
This commit is contained in:
Родитель
853a637c38
Коммит
bc49980ffa
|
@ -146,7 +146,7 @@ func New(ctx context.Context, log *logrus.Entry, _env env.Interface, db database
|
||||||
|
|
||||||
dns: dns.NewManager(_env, localFPAuthorizer),
|
dns: dns.NewManager(_env, localFPAuthorizer),
|
||||||
storage: storage,
|
storage: storage,
|
||||||
subnet: subnet.NewManager(_env, r.SubscriptionID, fpAuthorizer),
|
subnet: subnet.NewManager(_env.Environment(), r.SubscriptionID, fpAuthorizer),
|
||||||
graph: graph.NewManager(log, aead, storage),
|
graph: graph.NewManager(log, aead, storage),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
mgmtnetwork "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-07-01/network"
|
mgmtnetwork "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-07-01/network"
|
||||||
"github.com/Azure/go-autorest/autorest/azure"
|
|
||||||
"github.com/Azure/go-autorest/autorest/to"
|
"github.com/Azure/go-autorest/autorest/to"
|
||||||
"github.com/golang/mock/gomock"
|
"github.com/golang/mock/gomock"
|
||||||
machinev1beta1 "github.com/openshift/machine-api-operator/pkg/apis/machine/v1beta1"
|
machinev1beta1 "github.com/openshift/machine-api-operator/pkg/apis/machine/v1beta1"
|
||||||
|
@ -19,25 +18,19 @@ import (
|
||||||
azureproviderv1beta1 "sigs.k8s.io/cluster-api-provider-azure/pkg/apis/azureprovider/v1beta1"
|
azureproviderv1beta1 "sigs.k8s.io/cluster-api-provider-azure/pkg/apis/azureprovider/v1beta1"
|
||||||
|
|
||||||
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
|
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
|
||||||
mocksubnet "github.com/Azure/ARO-RP/pkg/util/mocks/subnet"
|
mock_subnet "github.com/Azure/ARO-RP/pkg/util/mocks/subnet"
|
||||||
"github.com/Azure/ARO-RP/pkg/util/subnet"
|
"github.com/Azure/ARO-RP/pkg/util/subnet"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
subscriptionId = "0000000-0000-0000-0000-000000000000"
|
subscriptionId = "0000000-0000-0000-0000-000000000000"
|
||||||
vnet = azure.Resource{
|
clusterResourceGroupName = "aro-iljrzb5a"
|
||||||
SubscriptionID: subscriptionId,
|
infraId = "abcd"
|
||||||
ResourceGroup: "vnet-rg",
|
clusterResourceGroupId = "/subscriptions/" + subscriptionId + "/resourcegroups/" + clusterResourceGroupName
|
||||||
ResourceName: "vnet-name",
|
vnetResourceGroup = "vnet-rg"
|
||||||
}
|
vnetName = "vnet"
|
||||||
clusterResourceGroupName = "aro-iljrzb5a"
|
subnetNameWorker = "worker"
|
||||||
infraId = "abcd"
|
subnetNameMaster = "master"
|
||||||
clusterResourceGroupId = "/subscriptions/" + subscriptionId + "/resourcegroups/" + clusterResourceGroupName
|
|
||||||
vnetResourceGroup = "vnet-rg"
|
|
||||||
vnetResourceGroupResourceId = "/subscriptions/" + subscriptionId + "/resourcegroups/" + vnetResourceGroup
|
|
||||||
vnetName = "vnet"
|
|
||||||
subnetNameWorker = "worker"
|
|
||||||
subnetNameMaster = "master"
|
|
||||||
|
|
||||||
nsgv1NodeResourceId = clusterResourceGroupId + "/providers/Microsoft.Network/networkSecurityGroups/" + infraId + subnet.NSGNodeSuffixV1
|
nsgv1NodeResourceId = clusterResourceGroupId + "/providers/Microsoft.Network/networkSecurityGroups/" + infraId + subnet.NSGNodeSuffixV1
|
||||||
nsgv1MasterResourceId = clusterResourceGroupId + "/providers/Microsoft.Network/networkSecurityGroups/" + infraId + subnet.NSGControlPlaneSuffixV1
|
nsgv1MasterResourceId = clusterResourceGroupId + "/providers/Microsoft.Network/networkSecurityGroups/" + infraId + subnet.NSGControlPlaneSuffixV1
|
||||||
|
@ -54,15 +47,6 @@ func getValidClusterInstance() *arov1alpha1.Cluster {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getValidWorkerMachine() *machinev1beta1.Machine {
|
|
||||||
return &machinev1beta1.Machine{
|
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
|
||||||
Name: "worker",
|
|
||||||
Namespace: machineSetsNamespace,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func getValidSubnet() *mgmtnetwork.Subnet {
|
func getValidSubnet() *mgmtnetwork.Subnet {
|
||||||
return &mgmtnetwork.Subnet{
|
return &mgmtnetwork.Subnet{
|
||||||
SubnetPropertiesFormat: &mgmtnetwork.SubnetPropertiesFormat{
|
SubnetPropertiesFormat: &mgmtnetwork.SubnetPropertiesFormat{
|
||||||
|
@ -109,7 +93,7 @@ func TestReconcileManager(t *testing.T) {
|
||||||
|
|
||||||
for _, tt := range []struct {
|
for _, tt := range []struct {
|
||||||
name string
|
name string
|
||||||
subnetMock func(*mocksubnet.MockManager)
|
subnetMock func(*mock_subnet.MockManager)
|
||||||
maocli func() (*maofake.Clientset, error)
|
maocli func() (*maofake.Clientset, error)
|
||||||
instance func(*arov1alpha1.Cluster)
|
instance func(*arov1alpha1.Cluster)
|
||||||
wantErr error
|
wantErr error
|
||||||
|
@ -129,7 +113,7 @@ func TestReconcileManager(t *testing.T) {
|
||||||
|
|
||||||
return maofake.NewSimpleClientset(machine1, machine2), nil
|
return maofake.NewSimpleClientset(machine1, machine2), nil
|
||||||
},
|
},
|
||||||
subnetMock: func(mock *mocksubnet.MockManager) {
|
subnetMock: func(mock *mock_subnet.MockManager) {
|
||||||
|
|
||||||
resourceId := "/subscriptions/" + subscriptionId + "/resourceGroups/" + vnetResourceGroup + "/providers/Microsoft.Network/virtualNetworks/" + vnetName + "/subnets/" + subnetNameMaster
|
resourceId := "/subscriptions/" + subscriptionId + "/resourceGroups/" + vnetResourceGroup + "/providers/Microsoft.Network/virtualNetworks/" + vnetName + "/subnets/" + subnetNameMaster
|
||||||
subnetObjectMaster := getValidSubnet()
|
subnetObjectMaster := getValidSubnet()
|
||||||
|
@ -156,7 +140,7 @@ func TestReconcileManager(t *testing.T) {
|
||||||
|
|
||||||
return maofake.NewSimpleClientset(machine1, machine2), nil
|
return maofake.NewSimpleClientset(machine1, machine2), nil
|
||||||
},
|
},
|
||||||
subnetMock: func(mock *mocksubnet.MockManager) {
|
subnetMock: func(mock *mock_subnet.MockManager) {
|
||||||
|
|
||||||
resourceId := "/subscriptions/" + subscriptionId + "/resourceGroups/" + vnetResourceGroup + "/providers/Microsoft.Network/virtualNetworks/" + vnetName + "/subnets/" + subnetNameMaster
|
resourceId := "/subscriptions/" + subscriptionId + "/resourceGroups/" + vnetResourceGroup + "/providers/Microsoft.Network/virtualNetworks/" + vnetName + "/subnets/" + subnetNameMaster
|
||||||
subnetObjectMaster := getValidSubnet()
|
subnetObjectMaster := getValidSubnet()
|
||||||
|
@ -192,7 +176,7 @@ func TestReconcileManager(t *testing.T) {
|
||||||
|
|
||||||
return maofake.NewSimpleClientset(machine1, machine2), nil
|
return maofake.NewSimpleClientset(machine1, machine2), nil
|
||||||
},
|
},
|
||||||
subnetMock: func(mock *mocksubnet.MockManager) {
|
subnetMock: func(mock *mock_subnet.MockManager) {
|
||||||
|
|
||||||
resourceId := "/subscriptions/" + subscriptionId + "/resourceGroups/" + vnetResourceGroup + "/providers/Microsoft.Network/virtualNetworks/" + vnetName + "/subnets/" + subnetNameMaster
|
resourceId := "/subscriptions/" + subscriptionId + "/resourceGroups/" + vnetResourceGroup + "/providers/Microsoft.Network/virtualNetworks/" + vnetName + "/subnets/" + subnetNameMaster
|
||||||
subnetObjectMaster := getValidSubnet()
|
subnetObjectMaster := getValidSubnet()
|
||||||
|
@ -223,7 +207,7 @@ func TestReconcileManager(t *testing.T) {
|
||||||
|
|
||||||
return maofake.NewSimpleClientset(machine1, machine2), nil
|
return maofake.NewSimpleClientset(machine1, machine2), nil
|
||||||
},
|
},
|
||||||
subnetMock: func(mock *mocksubnet.MockManager) {
|
subnetMock: func(mock *mock_subnet.MockManager) {
|
||||||
|
|
||||||
resourceId := "/subscriptions/" + subscriptionId + "/resourceGroups/" + vnetResourceGroup + "/providers/Microsoft.Network/virtualNetworks/" + vnetName + "/subnets/" + subnetNameMaster
|
resourceId := "/subscriptions/" + subscriptionId + "/resourceGroups/" + vnetResourceGroup + "/providers/Microsoft.Network/virtualNetworks/" + vnetName + "/subnets/" + subnetNameMaster
|
||||||
subnetObjectMaster := getValidSubnet()
|
subnetObjectMaster := getValidSubnet()
|
||||||
|
@ -254,7 +238,7 @@ func TestReconcileManager(t *testing.T) {
|
||||||
|
|
||||||
return maofake.NewSimpleClientset(machine1, machine2), nil
|
return maofake.NewSimpleClientset(machine1, machine2), nil
|
||||||
},
|
},
|
||||||
subnetMock: func(mock *mocksubnet.MockManager) {
|
subnetMock: func(mock *mock_subnet.MockManager) {
|
||||||
|
|
||||||
resourceId := "/subscriptions/" + subscriptionId + "/resourceGroups/" + vnetResourceGroup + "/providers/Microsoft.Network/virtualNetworks/" + vnetName + "/subnets/" + subnetNameMaster
|
resourceId := "/subscriptions/" + subscriptionId + "/resourceGroups/" + vnetResourceGroup + "/providers/Microsoft.Network/virtualNetworks/" + vnetName + "/subnets/" + subnetNameMaster
|
||||||
subnetObjectMaster := getValidSubnet()
|
subnetObjectMaster := getValidSubnet()
|
||||||
|
@ -283,7 +267,7 @@ func TestReconcileManager(t *testing.T) {
|
||||||
controller := gomock.NewController(t)
|
controller := gomock.NewController(t)
|
||||||
defer controller.Finish()
|
defer controller.Finish()
|
||||||
|
|
||||||
manager := mocksubnet.NewMockManager(controller)
|
manager := mock_subnet.NewMockManager(controller)
|
||||||
if tt.subnetMock != nil {
|
if tt.subnetMock != nil {
|
||||||
tt.subnetMock(manager)
|
tt.subnetMock(manager)
|
||||||
}
|
}
|
||||||
|
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -50,11 +50,15 @@ spec:
|
||||||
content:
|
content:
|
||||||
type: string
|
type: string
|
||||||
type: object
|
type: object
|
||||||
|
clusterResourceGroupId:
|
||||||
|
type: string
|
||||||
domain:
|
domain:
|
||||||
type: string
|
type: string
|
||||||
features:
|
features:
|
||||||
description: FeaturesSpec defines ARO operator feature gates
|
description: FeaturesSpec defines ARO operator feature gates
|
||||||
properties:
|
properties:
|
||||||
|
ReconcileSubnets:
|
||||||
|
type: boolean
|
||||||
reconcileAlertWebhook:
|
reconcileAlertWebhook:
|
||||||
type: boolean
|
type: boolean
|
||||||
reconcileBanner:
|
reconcileBanner:
|
||||||
|
@ -67,8 +71,6 @@ spec:
|
||||||
type: boolean
|
type: boolean
|
||||||
reconcileMonitoringConfig:
|
reconcileMonitoringConfig:
|
||||||
type: boolean
|
type: boolean
|
||||||
reconcileNSGs:
|
|
||||||
type: boolean
|
|
||||||
reconcileNodeDrainer:
|
reconcileNodeDrainer:
|
||||||
type: boolean
|
type: boolean
|
||||||
reconcilePullSecret:
|
reconcilePullSecret:
|
||||||
|
|
|
@ -49,7 +49,7 @@ func NewResourceCleaner(log *logrus.Entry, env env.Core, shouldDelete checkFn, d
|
||||||
privatelinkservicescli: network.NewPrivateLinkServicesClient(env.Environment(), env.SubscriptionID(), authorizer),
|
privatelinkservicescli: network.NewPrivateLinkServicesClient(env.Environment(), env.SubscriptionID(), authorizer),
|
||||||
securitygroupscli: network.NewSecurityGroupsClient(env.Environment(), env.SubscriptionID(), authorizer),
|
securitygroupscli: network.NewSecurityGroupsClient(env.Environment(), env.SubscriptionID(), authorizer),
|
||||||
|
|
||||||
subnet: subnet.NewManager(env, env.SubscriptionID(), authorizer),
|
subnet: subnet.NewManager(env.Environment(), env.SubscriptionID(), authorizer),
|
||||||
|
|
||||||
// ShouldDelete decides whether the resource group gets deleted
|
// ShouldDelete decides whether the resource group gets deleted
|
||||||
shouldDelete: shouldDelete,
|
shouldDelete: shouldDelete,
|
||||||
|
|
|
@ -15,7 +15,7 @@ import (
|
||||||
"github.com/apparentlymart/go-cidr/cidr"
|
"github.com/apparentlymart/go-cidr/cidr"
|
||||||
|
|
||||||
"github.com/Azure/ARO-RP/pkg/api"
|
"github.com/Azure/ARO-RP/pkg/api"
|
||||||
"github.com/Azure/ARO-RP/pkg/env"
|
"github.com/Azure/ARO-RP/pkg/util/azureclient"
|
||||||
"github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/network"
|
"github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/network"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -29,9 +29,9 @@ type manager struct {
|
||||||
subnets network.SubnetsClient
|
subnets network.SubnetsClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewManager(env env.Core, subscriptionID string, spAuthorizer autorest.Authorizer) Manager {
|
func NewManager(azEnv *azureclient.AROEnvironment, subscriptionID string, spAuthorizer autorest.Authorizer) Manager {
|
||||||
return &manager{
|
return &manager{
|
||||||
subnets: network.NewSubnetsClient(env.Environment(), subscriptionID, spAuthorizer),
|
subnets: network.NewSubnetsClient(azEnv, subscriptionID, spAuthorizer),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче