From 8a77dc216b0cb6720ae8bedd0c80e5322a098d15 Mon Sep 17 00:00:00 2001 From: Ayato Tokubi Date: Tue, 8 Oct 2024 11:48:31 +0100 Subject: [PATCH 1/2] remove unused old routeTable client --- pkg/frontend/adminactions/azureactions.go | 17 +++++- pkg/frontend/adminactions/resources_list.go | 4 +- .../adminactions/resources_list_test.go | 30 +++++----- .../azuresdk/armnetwork/generate.go | 2 +- pkg/util/azureclient/mgmt/network/generate.go | 2 +- .../azureclient/mgmt/network/routetable.go | 36 ------------ .../mgmt/network/routetable_addons.go | 22 -------- .../azuresdk/armnetwork/armnetwork.go | 56 ++++++++++++++++++- .../mocks/azureclient/mgmt/network/network.go | 56 +------------------ 9 files changed, 92 insertions(+), 133 deletions(-) delete mode 100644 pkg/util/azureclient/mgmt/network/routetable.go delete mode 100644 pkg/util/azureclient/mgmt/network/routetable_addons.go diff --git a/pkg/frontend/adminactions/azureactions.go b/pkg/frontend/adminactions/azureactions.go index bf807db2582..da4c5296fd5 100644 --- a/pkg/frontend/adminactions/azureactions.go +++ b/pkg/frontend/adminactions/azureactions.go @@ -15,6 +15,7 @@ import ( "github.com/Azure/ARO-RP/pkg/api" "github.com/Azure/ARO-RP/pkg/env" + "github.com/Azure/ARO-RP/pkg/util/azureclient/azuresdk/armnetwork" "github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/compute" "github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/features" "github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/network" @@ -48,7 +49,7 @@ type azureActions struct { virtualMachines compute.VirtualMachinesClient virtualNetworks network.VirtualNetworksClient diskEncryptionSets compute.DiskEncryptionSetsClient - routeTables network.RouteTablesClient + routeTables armnetwork.RouteTablesClient storageAccounts storage.AccountsClient networkInterfaces network.InterfacesClient loadBalancers network.LoadBalancersClient @@ -63,6 +64,18 @@ func NewAzureActions(log *logrus.Entry, env env.Interface, oc *api.OpenShiftClus return nil, err } + credential, err := env.FPNewClientCertificateCredential(subscriptionDoc.Subscription.Properties.TenantID) + if err != nil { + return nil, err + } + + options := env.Environment().ArmClientOptions() + + routeTables, err := armnetwork.NewRouteTablesClient(subscriptionDoc.ID, credential, options) + if err != nil { + return nil, err + } + return &azureActions{ log: log, env: env, @@ -73,7 +86,7 @@ func NewAzureActions(log *logrus.Entry, env env.Interface, oc *api.OpenShiftClus virtualMachines: compute.NewVirtualMachinesClient(env.Environment(), subscriptionDoc.ID, fpAuth), virtualNetworks: network.NewVirtualNetworksClient(env.Environment(), subscriptionDoc.ID, fpAuth), diskEncryptionSets: compute.NewDiskEncryptionSetsClient(env.Environment(), subscriptionDoc.ID, fpAuth), - routeTables: network.NewRouteTablesClient(env.Environment(), subscriptionDoc.ID, fpAuth), + routeTables: routeTables, storageAccounts: storage.NewAccountsClient(env.Environment(), subscriptionDoc.ID, fpAuth), networkInterfaces: network.NewInterfacesClient(env.Environment(), subscriptionDoc.ID, fpAuth), loadBalancers: network.NewLoadBalancersClient(env.Environment(), subscriptionDoc.ID, fpAuth), diff --git a/pkg/frontend/adminactions/resources_list.go b/pkg/frontend/adminactions/resources_list.go index 2c78521800e..bd5c970c564 100644 --- a/pkg/frontend/adminactions/resources_list.go +++ b/pkg/frontend/adminactions/resources_list.go @@ -150,13 +150,13 @@ func (a *azureActions) appendAzureNetworkResources(ctx context.Context, armResou a.log.Warnf("skipping route table '%s' due to ID parse error: %s", *snet.RouteTable.ID, err) continue } - rt, err := a.routeTables.Get(ctx, r.ResourceGroup, r.ResourceName, "") + rt, err := a.routeTables.Get(ctx, r.ResourceGroup, r.ResourceName, nil) if err != nil { a.log.Warnf("skipping route table '%s' due to Get error: %s", *snet.RouteTable.ID, err) continue } armResources = append(armResources, arm.Resource{ - Resource: rt, + Resource: rt.RouteTable, }) } } diff --git a/pkg/frontend/adminactions/resources_list_test.go b/pkg/frontend/adminactions/resources_list_test.go index 31aa60b15c3..2a79ff7c7d9 100644 --- a/pkg/frontend/adminactions/resources_list_test.go +++ b/pkg/frontend/adminactions/resources_list_test.go @@ -10,6 +10,7 @@ import ( "io" "testing" + sdknetwork "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v2" mgmtcompute "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2020-06-01/compute" mgmtnetwork "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-08-01/network" mgmtfeatures "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2019-07-01/features" @@ -19,6 +20,7 @@ import ( "github.com/Azure/ARO-RP/pkg/api" "github.com/Azure/ARO-RP/pkg/util/azureclient" + mock_armnetwork "github.com/Azure/ARO-RP/pkg/util/mocks/azureclient/azuresdk/armnetwork" mock_compute "github.com/Azure/ARO-RP/pkg/util/mocks/azureclient/mgmt/compute" mock_features "github.com/Azure/ARO-RP/pkg/util/mocks/azureclient/mgmt/features" mock_network "github.com/Azure/ARO-RP/pkg/util/mocks/azureclient/mgmt/network" @@ -57,7 +59,7 @@ func validVirtualMachinesMock(virtualMachines *mock_compute.MockVirtualMachinesC }, nil).AnyTimes() } -func validVirtualNetworksMock(virtualNetworks *mock_network.MockVirtualNetworksClient, routeTables *mock_network.MockRouteTablesClient, mockSubID string) { +func validVirtualNetworksMock(virtualNetworks *mock_network.MockVirtualNetworksClient, routeTables *mock_armnetwork.MockRouteTablesClient, mockSubID string) { virtualNetworks.EXPECT().Get(gomock.Any(), "test-cluster", "test-vnet", "").Return(mgmtnetwork.VirtualNetwork{ ID: to.StringPtr("/subscriptions/id"), Type: to.StringPtr("Microsoft.Network/virtualNetworks"), @@ -78,9 +80,11 @@ func validVirtualNetworksMock(virtualNetworks *mock_network.MockVirtualNetworksC }, }, nil) - routeTables.EXPECT().Get(gomock.Any(), "mockrg", "routetable1", "").Return(mgmtnetwork.RouteTable{ - ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mockrg/providers/Microsoft.Network/routeTables/routetable1"), - Name: to.StringPtr("routetable1"), + routeTables.EXPECT().Get(gomock.Any(), "mockrg", "routetable1", nil).Return(sdknetwork.RouteTablesClientGetResponse{ + RouteTable: sdknetwork.RouteTable{ + ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mockrg/providers/Microsoft.Network/routeTables/routetable1"), + Name: to.StringPtr("routetable1"), + }, }, nil) } @@ -97,7 +101,7 @@ func TestResourcesList(t *testing.T) { type test struct { name string - mocks func(*mock_network.MockVirtualNetworksClient, *mock_network.MockRouteTablesClient, *mock_compute.MockDiskEncryptionSetsClient) + mocks func(*mock_network.MockVirtualNetworksClient, *mock_armnetwork.MockRouteTablesClient, *mock_compute.MockDiskEncryptionSetsClient) wantResponse []byte wantError string diskEncryptionSetId string @@ -106,14 +110,14 @@ func TestResourcesList(t *testing.T) { for _, tt := range []*test{ { name: "basic coverage", - mocks: func(virtualNetworks *mock_network.MockVirtualNetworksClient, routeTables *mock_network.MockRouteTablesClient, diskEncryptionSets *mock_compute.MockDiskEncryptionSetsClient) { + mocks: func(virtualNetworks *mock_network.MockVirtualNetworksClient, routeTables *mock_armnetwork.MockRouteTablesClient, diskEncryptionSets *mock_compute.MockDiskEncryptionSetsClient) { validVirtualNetworksMock(virtualNetworks, routeTables, mockSubID) }, - wantResponse: []byte(`[{"properties":{"dhcpOptions":{"dnsServers":[]},"subnets":[{"properties":{"routeTable":{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mockrg/providers/Microsoft.Network/routeTables/routetable1","tags":null}},"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-cluster/providers/Microsoft.Network/virtualNetworks/test-vnet/subnets/master"}]},"id":"/subscriptions/id","type":"Microsoft.Network/virtualNetworks"},{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mockrg/providers/Microsoft.Network/routeTables/routetable1","name":"routetable1"},{"properties":{"provisioningState":"Succeeded"},"id":"/subscriptions/id","type":"Microsoft.Compute/virtualMachines"},{"id":"/subscriptions/id","name":"storage","type":"Microsoft.Storage/storageAccounts","location":"eastus"}]`), + wantResponse: []byte(`[{"properties":{"dhcpOptions":{"dnsServers":[]},"subnets":[{"properties":{"routeTable":{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mockrg/providers/Microsoft.Network/routeTables/routetable1","tags":null}},"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-cluster/providers/Microsoft.Network/virtualNetworks/test-vnet/subnets/master"}]},"id":"/subscriptions/id","type":"Microsoft.Network/virtualNetworks"},{"ID":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mockrg/providers/Microsoft.Network/routeTables/routetable1","Properties":null,"Etag":null,"name":"routetable1"},{"properties":{"provisioningState":"Succeeded"},"id":"/subscriptions/id","type":"Microsoft.Compute/virtualMachines"},{"id":"/subscriptions/id","name":"storage","type":"Microsoft.Storage/storageAccounts","location":"eastus"}]`), }, { name: "vnet get error", //Get resources should continue on error from virtualNetworks.Get() - mocks: func(virtualNetworks *mock_network.MockVirtualNetworksClient, routeTables *mock_network.MockRouteTablesClient, diskEncryptionSets *mock_compute.MockDiskEncryptionSetsClient) { + mocks: func(virtualNetworks *mock_network.MockVirtualNetworksClient, routeTables *mock_armnetwork.MockRouteTablesClient, diskEncryptionSets *mock_compute.MockDiskEncryptionSetsClient) { // Fail virtualNetworks with a GET error virtualNetworks.EXPECT().Get(gomock.Any(), "test-cluster", "test-vnet", "").Return(mgmtnetwork.VirtualNetwork{}, fmt.Errorf("Any error during Get, expecting a permissions error")) }, @@ -121,23 +125,23 @@ func TestResourcesList(t *testing.T) { }, { name: "enabled diskencryptionsets", - mocks: func(virtualNetworks *mock_network.MockVirtualNetworksClient, routeTables *mock_network.MockRouteTablesClient, diskEncryptionSets *mock_compute.MockDiskEncryptionSetsClient) { + mocks: func(virtualNetworks *mock_network.MockVirtualNetworksClient, routeTables *mock_armnetwork.MockRouteTablesClient, diskEncryptionSets *mock_compute.MockDiskEncryptionSetsClient) { validVirtualNetworksMock(virtualNetworks, routeTables, mockSubID) validDiskEncryptionSetsMock(diskEncryptionSets) }, diskEncryptionSetId: fmt.Sprintf("/subscriptions/%s/resourceGroups/test-cluster/providers/Microsoft.Compute/diskEncryptionSets/test-cluster-des", mockSubID), - wantResponse: []byte(`[{"properties":{"dhcpOptions":{"dnsServers":[]},"subnets":[{"properties":{"routeTable":{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mockrg/providers/Microsoft.Network/routeTables/routetable1","tags":null}},"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-cluster/providers/Microsoft.Network/virtualNetworks/test-vnet/subnets/master"}]},"id":"/subscriptions/id","type":"Microsoft.Network/virtualNetworks"},{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mockrg/providers/Microsoft.Network/routeTables/routetable1","name":"routetable1"},{"id":"/subscriptions/id","type":"Microsoft.Compute/diskEncryptionSets"},{"properties":{"provisioningState":"Succeeded"},"id":"/subscriptions/id","type":"Microsoft.Compute/virtualMachines"},{"id":"/subscriptions/id","name":"storage","type":"Microsoft.Storage/storageAccounts","location":"eastus"}]`), + wantResponse: []byte(`[{"properties":{"dhcpOptions":{"dnsServers":[]},"subnets":[{"properties":{"routeTable":{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mockrg/providers/Microsoft.Network/routeTables/routetable1","tags":null}},"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-cluster/providers/Microsoft.Network/virtualNetworks/test-vnet/subnets/master"}]},"id":"/subscriptions/id","type":"Microsoft.Network/virtualNetworks"},{"ID":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mockrg/providers/Microsoft.Network/routeTables/routetable1","Properties":null,"Etag":null,"name":"routetable1"},{"id":"/subscriptions/id","type":"Microsoft.Compute/diskEncryptionSets"},{"properties":{"provisioningState":"Succeeded"},"id":"/subscriptions/id","type":"Microsoft.Compute/virtualMachines"},{"id":"/subscriptions/id","name":"storage","type":"Microsoft.Storage/storageAccounts","location":"eastus"}]`), }, { name: "error getting diskencryptionsets", - mocks: func(virtualNetworks *mock_network.MockVirtualNetworksClient, routeTables *mock_network.MockRouteTablesClient, diskEncryptionSets *mock_compute.MockDiskEncryptionSetsClient) { + mocks: func(virtualNetworks *mock_network.MockVirtualNetworksClient, routeTables *mock_armnetwork.MockRouteTablesClient, diskEncryptionSets *mock_compute.MockDiskEncryptionSetsClient) { validVirtualNetworksMock(virtualNetworks, routeTables, mockSubID) // Fail diskEncryptionSets with a GET error diskEncryptionSets.EXPECT().Get(gomock.Any(), "test-cluster", "test-cluster-des").Return(mgmtcompute.DiskEncryptionSet{}, fmt.Errorf("Any error during Get, expecting a permissions error")) }, diskEncryptionSetId: fmt.Sprintf("/subscriptions/%s/resourceGroups/test-cluster/providers/Microsoft.Compute/diskEncryptionSets/test-cluster-des", mockSubID), - wantResponse: []byte(`[{"properties":{"dhcpOptions":{"dnsServers":[]},"subnets":[{"properties":{"routeTable":{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mockrg/providers/Microsoft.Network/routeTables/routetable1","tags":null}},"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-cluster/providers/Microsoft.Network/virtualNetworks/test-vnet/subnets/master"}]},"id":"/subscriptions/id","type":"Microsoft.Network/virtualNetworks"},{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mockrg/providers/Microsoft.Network/routeTables/routetable1","name":"routetable1"},{"properties":{"provisioningState":"Succeeded"},"id":"/subscriptions/id","type":"Microsoft.Compute/virtualMachines"},{"id":"/subscriptions/id","name":"storage","type":"Microsoft.Storage/storageAccounts","location":"eastus"}]`), + wantResponse: []byte(`[{"properties":{"dhcpOptions":{"dnsServers":[]},"subnets":[{"properties":{"routeTable":{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mockrg/providers/Microsoft.Network/routeTables/routetable1","tags":null}},"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-cluster/providers/Microsoft.Network/virtualNetworks/test-vnet/subnets/master"}]},"id":"/subscriptions/id","type":"Microsoft.Network/virtualNetworks"},{"ID":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mockrg/providers/Microsoft.Network/routeTables/routetable1","Properties":null,"Etag":null,"name":"routetable1"},{"properties":{"provisioningState":"Succeeded"},"id":"/subscriptions/id","type":"Microsoft.Compute/virtualMachines"},{"id":"/subscriptions/id","name":"storage","type":"Microsoft.Storage/storageAccounts","location":"eastus"}]`), }, } { t.Run(tt.name, func(t *testing.T) { @@ -150,7 +154,7 @@ func TestResourcesList(t *testing.T) { resources := mock_features.NewMockResourcesClient(controller) virtualMachines := mock_compute.NewMockVirtualMachinesClient(controller) virtualNetworks := mock_network.NewMockVirtualNetworksClient(controller) - routeTables := mock_network.NewMockRouteTablesClient(controller) + routeTables := mock_armnetwork.NewMockRouteTablesClient(controller) diskEncryptionSets := mock_compute.NewMockDiskEncryptionSetsClient(controller) validListByResourceGroupMock(resources) diff --git a/pkg/util/azureclient/azuresdk/armnetwork/generate.go b/pkg/util/azureclient/azuresdk/armnetwork/generate.go index 48215a47500..eda5e295fde 100644 --- a/pkg/util/azureclient/azuresdk/armnetwork/generate.go +++ b/pkg/util/azureclient/azuresdk/armnetwork/generate.go @@ -4,5 +4,5 @@ package armnetwork // Licensed under the Apache License 2.0. //go:generate rm -rf ../../../../util/mocks/$GOPACKAGE -//go:generate mockgen -destination=../../../../util/mocks/azureclient/azuresdk/$GOPACKAGE/$GOPACKAGE.go github.com/Azure/ARO-RP/pkg/util/azureclient/azuresdk/$GOPACKAGE InterfacesClient,LoadBalancersClient,LoadBalancerBackendAddressPoolsClient,PrivateEndpointsClient,PrivateLinkServicesClient,PublicIPAddressesClient,SecurityGroupsClient,SubnetsClient +//go:generate mockgen -destination=../../../../util/mocks/azureclient/azuresdk/$GOPACKAGE/$GOPACKAGE.go github.com/Azure/ARO-RP/pkg/util/azureclient/azuresdk/$GOPACKAGE InterfacesClient,LoadBalancersClient,LoadBalancerBackendAddressPoolsClient,PrivateEndpointsClient,PrivateLinkServicesClient,PublicIPAddressesClient,RouteTablesClient,SecurityGroupsClient,SubnetsClient //go:generate goimports -local=github.com/Azure/ARO-RP -e -w ../../../../util/mocks/azureclient/azuresdk/$GOPACKAGE/$GOPACKAGE.go diff --git a/pkg/util/azureclient/mgmt/network/generate.go b/pkg/util/azureclient/mgmt/network/generate.go index 8f32bf26402..39d2fc24150 100644 --- a/pkg/util/azureclient/mgmt/network/generate.go +++ b/pkg/util/azureclient/mgmt/network/generate.go @@ -4,5 +4,5 @@ package network // Licensed under the Apache License 2.0. //go:generate rm -rf ../../../../util/mocks/$GOPACKAGE -//go:generate mockgen -destination=../../../../util/mocks/azureclient/mgmt/$GOPACKAGE/$GOPACKAGE.go github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/$GOPACKAGE InterfacesClient,LoadBalancersClient,PrivateEndpointsClient,PublicIPAddressesClient,LoadBalancerBackendAddressPoolsClient,RouteTablesClient,SubnetsClient,VirtualNetworksClient,UsageClient,FlowLogsClient +//go:generate mockgen -destination=../../../../util/mocks/azureclient/mgmt/$GOPACKAGE/$GOPACKAGE.go github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/$GOPACKAGE InterfacesClient,LoadBalancersClient,PrivateEndpointsClient,PublicIPAddressesClient,LoadBalancerBackendAddressPoolsClient,SubnetsClient,VirtualNetworksClient,UsageClient,FlowLogsClient //go:generate goimports -local=github.com/Azure/ARO-RP -e -w ../../../../util/mocks/azureclient/mgmt/$GOPACKAGE/$GOPACKAGE.go diff --git a/pkg/util/azureclient/mgmt/network/routetable.go b/pkg/util/azureclient/mgmt/network/routetable.go deleted file mode 100644 index 623fed159cb..00000000000 --- a/pkg/util/azureclient/mgmt/network/routetable.go +++ /dev/null @@ -1,36 +0,0 @@ -package network - -// Copyright (c) Microsoft Corporation. -// Licensed under the Apache License 2.0. - -import ( - "context" - - mgmtnetwork "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-08-01/network" - "github.com/Azure/go-autorest/autorest" - - "github.com/Azure/ARO-RP/pkg/util/azureclient" -) - -// RouteTablesClient is a minimal interface for azure RouteTablesClient -type RouteTablesClient interface { - Get(ctx context.Context, resourceGroupName string, routeTableName string, expand string) (result mgmtnetwork.RouteTable, err error) - RouteTablesClientAddons -} - -type routeTablesClient struct { - mgmtnetwork.RouteTablesClient -} - -var _ RouteTablesClient = &routeTablesClient{} - -// NewRouteTablesClient creates a new RouteTablesClient -func NewRouteTablesClient(environment *azureclient.AROEnvironment, subscriptionID string, authorizer autorest.Authorizer) RouteTablesClient { - client := mgmtnetwork.NewRouteTablesClientWithBaseURI(environment.ResourceManagerEndpoint, subscriptionID) - client.Authorizer = authorizer - client.Sender = azureclient.DecorateSenderWithLogging(client.Sender) - - return &routeTablesClient{ - RouteTablesClient: client, - } -} diff --git a/pkg/util/azureclient/mgmt/network/routetable_addons.go b/pkg/util/azureclient/mgmt/network/routetable_addons.go deleted file mode 100644 index 54aa0b80c02..00000000000 --- a/pkg/util/azureclient/mgmt/network/routetable_addons.go +++ /dev/null @@ -1,22 +0,0 @@ -package network - -// Copyright (c) Microsoft Corporation. -// Licensed under the Apache License 2.0. - -import ( - "context" -) - -// RouteTablesClientAddons contains addons for RouteTablesClient -type RouteTablesClientAddons interface { - DeleteAndWait(ctx context.Context, resourceGroupName string, routeTableName string) error -} - -func (c *routeTablesClient) DeleteAndWait(ctx context.Context, resourceGroupName string, routeTableName string) error { - future, err := c.RouteTablesClient.Delete(ctx, resourceGroupName, routeTableName) - if err != nil { - return err - } - - return future.WaitForCompletionRef(ctx, c.Client) -} diff --git a/pkg/util/mocks/azureclient/azuresdk/armnetwork/armnetwork.go b/pkg/util/mocks/azureclient/azuresdk/armnetwork/armnetwork.go index a9b96b77b08..935a6237ac1 100644 --- a/pkg/util/mocks/azureclient/azuresdk/armnetwork/armnetwork.go +++ b/pkg/util/mocks/azureclient/azuresdk/armnetwork/armnetwork.go @@ -1,9 +1,9 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/Azure/ARO-RP/pkg/util/azureclient/azuresdk/armnetwork (interfaces: InterfacesClient,LoadBalancersClient,LoadBalancerBackendAddressPoolsClient,PrivateEndpointsClient,PrivateLinkServicesClient,PublicIPAddressesClient,SecurityGroupsClient,SubnetsClient) +// Source: github.com/Azure/ARO-RP/pkg/util/azureclient/azuresdk/armnetwork (interfaces: InterfacesClient,LoadBalancersClient,LoadBalancerBackendAddressPoolsClient,PrivateEndpointsClient,PrivateLinkServicesClient,PublicIPAddressesClient,RouteTablesClient,SecurityGroupsClient,SubnetsClient) // // Generated by this command: // -// mockgen -destination=../../../../util/mocks/azureclient/azuresdk/armnetwork/armnetwork.go github.com/Azure/ARO-RP/pkg/util/azureclient/azuresdk/armnetwork InterfacesClient,LoadBalancersClient,LoadBalancerBackendAddressPoolsClient,PrivateEndpointsClient,PrivateLinkServicesClient,PublicIPAddressesClient,SecurityGroupsClient,SubnetsClient +// mockgen -destination=../../../../util/mocks/azureclient/azuresdk/armnetwork/armnetwork.go github.com/Azure/ARO-RP/pkg/util/azureclient/azuresdk/armnetwork InterfacesClient,LoadBalancersClient,LoadBalancerBackendAddressPoolsClient,PrivateEndpointsClient,PrivateLinkServicesClient,PublicIPAddressesClient,RouteTablesClient,SecurityGroupsClient,SubnetsClient // // Package mock_armnetwork is a generated GoMock package. @@ -402,6 +402,58 @@ func (mr *MockPublicIPAddressesClientMockRecorder) List(arg0, arg1, arg2 any) *g return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockPublicIPAddressesClient)(nil).List), arg0, arg1, arg2) } +// MockRouteTablesClient is a mock of RouteTablesClient interface. +type MockRouteTablesClient struct { + ctrl *gomock.Controller + recorder *MockRouteTablesClientMockRecorder +} + +// MockRouteTablesClientMockRecorder is the mock recorder for MockRouteTablesClient. +type MockRouteTablesClientMockRecorder struct { + mock *MockRouteTablesClient +} + +// NewMockRouteTablesClient creates a new mock instance. +func NewMockRouteTablesClient(ctrl *gomock.Controller) *MockRouteTablesClient { + mock := &MockRouteTablesClient{ctrl: ctrl} + mock.recorder = &MockRouteTablesClientMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockRouteTablesClient) EXPECT() *MockRouteTablesClientMockRecorder { + return m.recorder +} + +// DeleteAndWait mocks base method. +func (m *MockRouteTablesClient) DeleteAndWait(arg0 context.Context, arg1, arg2 string, arg3 *armnetwork.RouteTablesClientBeginDeleteOptions) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DeleteAndWait", arg0, arg1, arg2, arg3) + ret0, _ := ret[0].(error) + return ret0 +} + +// DeleteAndWait indicates an expected call of DeleteAndWait. +func (mr *MockRouteTablesClientMockRecorder) DeleteAndWait(arg0, arg1, arg2, arg3 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteAndWait", reflect.TypeOf((*MockRouteTablesClient)(nil).DeleteAndWait), arg0, arg1, arg2, arg3) +} + +// Get mocks base method. +func (m *MockRouteTablesClient) Get(arg0 context.Context, arg1, arg2 string, arg3 *armnetwork.RouteTablesClientGetOptions) (armnetwork.RouteTablesClientGetResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Get", arg0, arg1, arg2, arg3) + ret0, _ := ret[0].(armnetwork.RouteTablesClientGetResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Get indicates an expected call of Get. +func (mr *MockRouteTablesClientMockRecorder) Get(arg0, arg1, arg2, arg3 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockRouteTablesClient)(nil).Get), arg0, arg1, arg2, arg3) +} + // MockSecurityGroupsClient is a mock of SecurityGroupsClient interface. type MockSecurityGroupsClient struct { ctrl *gomock.Controller diff --git a/pkg/util/mocks/azureclient/mgmt/network/network.go b/pkg/util/mocks/azureclient/mgmt/network/network.go index 5515a6ca80a..fecd8597993 100644 --- a/pkg/util/mocks/azureclient/mgmt/network/network.go +++ b/pkg/util/mocks/azureclient/mgmt/network/network.go @@ -1,9 +1,9 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/network (interfaces: InterfacesClient,LoadBalancersClient,PrivateEndpointsClient,PublicIPAddressesClient,LoadBalancerBackendAddressPoolsClient,RouteTablesClient,SubnetsClient,VirtualNetworksClient,UsageClient,FlowLogsClient) +// Source: github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/network (interfaces: InterfacesClient,LoadBalancersClient,PrivateEndpointsClient,PublicIPAddressesClient,LoadBalancerBackendAddressPoolsClient,SubnetsClient,VirtualNetworksClient,UsageClient,FlowLogsClient) // // Generated by this command: // -// mockgen -destination=../../../../util/mocks/azureclient/mgmt/network/network.go github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/network InterfacesClient,LoadBalancersClient,PrivateEndpointsClient,PublicIPAddressesClient,LoadBalancerBackendAddressPoolsClient,RouteTablesClient,SubnetsClient,VirtualNetworksClient,UsageClient,FlowLogsClient +// mockgen -destination=../../../../util/mocks/azureclient/mgmt/network/network.go github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/network InterfacesClient,LoadBalancersClient,PrivateEndpointsClient,PublicIPAddressesClient,LoadBalancerBackendAddressPoolsClient,SubnetsClient,VirtualNetworksClient,UsageClient,FlowLogsClient // // Package mock_network is a generated GoMock package. @@ -320,58 +320,6 @@ func (mr *MockLoadBalancerBackendAddressPoolsClientMockRecorder) Get(arg0, arg1, return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockLoadBalancerBackendAddressPoolsClient)(nil).Get), arg0, arg1, arg2, arg3) } -// MockRouteTablesClient is a mock of RouteTablesClient interface. -type MockRouteTablesClient struct { - ctrl *gomock.Controller - recorder *MockRouteTablesClientMockRecorder -} - -// MockRouteTablesClientMockRecorder is the mock recorder for MockRouteTablesClient. -type MockRouteTablesClientMockRecorder struct { - mock *MockRouteTablesClient -} - -// NewMockRouteTablesClient creates a new mock instance. -func NewMockRouteTablesClient(ctrl *gomock.Controller) *MockRouteTablesClient { - mock := &MockRouteTablesClient{ctrl: ctrl} - mock.recorder = &MockRouteTablesClientMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockRouteTablesClient) EXPECT() *MockRouteTablesClientMockRecorder { - return m.recorder -} - -// DeleteAndWait mocks base method. -func (m *MockRouteTablesClient) DeleteAndWait(arg0 context.Context, arg1, arg2 string) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "DeleteAndWait", arg0, arg1, arg2) - ret0, _ := ret[0].(error) - return ret0 -} - -// DeleteAndWait indicates an expected call of DeleteAndWait. -func (mr *MockRouteTablesClientMockRecorder) DeleteAndWait(arg0, arg1, arg2 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteAndWait", reflect.TypeOf((*MockRouteTablesClient)(nil).DeleteAndWait), arg0, arg1, arg2) -} - -// Get mocks base method. -func (m *MockRouteTablesClient) Get(arg0 context.Context, arg1, arg2, arg3 string) (network.RouteTable, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Get", arg0, arg1, arg2, arg3) - ret0, _ := ret[0].(network.RouteTable) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Get indicates an expected call of Get. -func (mr *MockRouteTablesClientMockRecorder) Get(arg0, arg1, arg2, arg3 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockRouteTablesClient)(nil).Get), arg0, arg1, arg2, arg3) -} - // MockSubnetsClient is a mock of SubnetsClient interface. type MockSubnetsClient struct { ctrl *gomock.Controller From 8d0ccb65b664452b8c1c4f7fcc268535eda14364 Mon Sep 17 00:00:00 2001 From: Ayato Tokubi Date: Tue, 8 Oct 2024 12:27:48 +0100 Subject: [PATCH 2/2] replace old virtual networks sdk to the new one --- pkg/frontend/adminactions/azureactions.go | 9 ++- pkg/frontend/adminactions/resources_list.go | 16 +++--- .../adminactions/resources_list_test.go | 57 ++++++++++--------- .../azuresdk/armnetwork/generate.go | 2 +- .../azuresdk/armnetwork/armnetwork.go | 42 +++++++++++++- 5 files changed, 85 insertions(+), 41 deletions(-) diff --git a/pkg/frontend/adminactions/azureactions.go b/pkg/frontend/adminactions/azureactions.go index da4c5296fd5..042834d6b88 100644 --- a/pkg/frontend/adminactions/azureactions.go +++ b/pkg/frontend/adminactions/azureactions.go @@ -47,7 +47,7 @@ type azureActions struct { resources features.ResourcesClient resourceSkus compute.ResourceSkusClient virtualMachines compute.VirtualMachinesClient - virtualNetworks network.VirtualNetworksClient + virtualNetworks armnetwork.VirtualNetworksClient diskEncryptionSets compute.DiskEncryptionSetsClient routeTables armnetwork.RouteTablesClient storageAccounts storage.AccountsClient @@ -76,6 +76,11 @@ func NewAzureActions(log *logrus.Entry, env env.Interface, oc *api.OpenShiftClus return nil, err } + virtualNetworks, err := armnetwork.NewVirtualNetworksClient(subscriptionDoc.ID, credential, options) + if err != nil { + return nil, err + } + return &azureActions{ log: log, env: env, @@ -84,7 +89,7 @@ func NewAzureActions(log *logrus.Entry, env env.Interface, oc *api.OpenShiftClus resources: features.NewResourcesClient(env.Environment(), subscriptionDoc.ID, fpAuth), resourceSkus: compute.NewResourceSkusClient(env.Environment(), subscriptionDoc.ID, fpAuth), virtualMachines: compute.NewVirtualMachinesClient(env.Environment(), subscriptionDoc.ID, fpAuth), - virtualNetworks: network.NewVirtualNetworksClient(env.Environment(), subscriptionDoc.ID, fpAuth), + virtualNetworks: virtualNetworks, diskEncryptionSets: compute.NewDiskEncryptionSetsClient(env.Environment(), subscriptionDoc.ID, fpAuth), routeTables: routeTables, storageAccounts: storage.NewAccountsClient(env.Environment(), subscriptionDoc.ID, fpAuth), diff --git a/pkg/frontend/adminactions/resources_list.go b/pkg/frontend/adminactions/resources_list.go index bd5c970c564..e7a046cce4d 100644 --- a/pkg/frontend/adminactions/resources_list.go +++ b/pkg/frontend/adminactions/resources_list.go @@ -124,15 +124,15 @@ func (a *azureActions) appendAzureNetworkResources(ctx context.Context, armResou return armResources, err } - vnet, err := a.virtualNetworks.Get(ctx, r.ResourceGroup, r.ResourceName, "") + vnet, err := a.virtualNetworks.Get(ctx, r.ResourceGroup, r.ResourceName, nil) if err != nil { return armResources, err } armResources = append(armResources, arm.Resource{ - Resource: vnet, + Resource: vnet.VirtualNetwork, }) - if vnet.Subnets != nil { - for _, snet := range *vnet.Subnets { + if vnet.Properties.Subnets != nil { + for _, snet := range vnet.Properties.Subnets { //we already have the VNet resource, filtering subnets instead of fetching them individually with a SubnetClient interestingSubnet := (*snet.ID == a.oc.Properties.MasterProfile.SubnetID) workerProfiles, _ := api.GetEnrichedWorkerProfiles(a.oc.Properties) @@ -144,15 +144,15 @@ func (a *azureActions) appendAzureNetworkResources(ctx context.Context, armResou continue } //by this time the snet subnet is used in a Master or Worker profile - if snet.RouteTable != nil { - r, err := azure.ParseResourceID(*snet.RouteTable.ID) + if snet.Properties.RouteTable != nil { + r, err := azure.ParseResourceID(*snet.Properties.RouteTable.ID) if err != nil { - a.log.Warnf("skipping route table '%s' due to ID parse error: %s", *snet.RouteTable.ID, err) + a.log.Warnf("skipping route table '%s' due to ID parse error: %s", *snet.Properties.RouteTable.ID, err) continue } rt, err := a.routeTables.Get(ctx, r.ResourceGroup, r.ResourceName, nil) if err != nil { - a.log.Warnf("skipping route table '%s' due to Get error: %s", *snet.RouteTable.ID, err) + a.log.Warnf("skipping route table '%s' due to Get error: %s", *snet.Properties.RouteTable.ID, err) continue } armResources = append(armResources, arm.Resource{ diff --git a/pkg/frontend/adminactions/resources_list_test.go b/pkg/frontend/adminactions/resources_list_test.go index 2a79ff7c7d9..3942a737561 100644 --- a/pkg/frontend/adminactions/resources_list_test.go +++ b/pkg/frontend/adminactions/resources_list_test.go @@ -12,18 +12,17 @@ import ( sdknetwork "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v2" mgmtcompute "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2020-06-01/compute" - mgmtnetwork "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-08-01/network" mgmtfeatures "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2019-07-01/features" "github.com/Azure/go-autorest/autorest/to" "github.com/sirupsen/logrus" "go.uber.org/mock/gomock" + "k8s.io/utils/ptr" "github.com/Azure/ARO-RP/pkg/api" "github.com/Azure/ARO-RP/pkg/util/azureclient" mock_armnetwork "github.com/Azure/ARO-RP/pkg/util/mocks/azureclient/azuresdk/armnetwork" mock_compute "github.com/Azure/ARO-RP/pkg/util/mocks/azureclient/mgmt/compute" mock_features "github.com/Azure/ARO-RP/pkg/util/mocks/azureclient/mgmt/features" - mock_network "github.com/Azure/ARO-RP/pkg/util/mocks/azureclient/mgmt/network" mock_env "github.com/Azure/ARO-RP/pkg/util/mocks/env" ) @@ -59,20 +58,22 @@ func validVirtualMachinesMock(virtualMachines *mock_compute.MockVirtualMachinesC }, nil).AnyTimes() } -func validVirtualNetworksMock(virtualNetworks *mock_network.MockVirtualNetworksClient, routeTables *mock_armnetwork.MockRouteTablesClient, mockSubID string) { - virtualNetworks.EXPECT().Get(gomock.Any(), "test-cluster", "test-vnet", "").Return(mgmtnetwork.VirtualNetwork{ - ID: to.StringPtr("/subscriptions/id"), - Type: to.StringPtr("Microsoft.Network/virtualNetworks"), - VirtualNetworkPropertiesFormat: &mgmtnetwork.VirtualNetworkPropertiesFormat{ - DhcpOptions: &mgmtnetwork.DhcpOptions{ - DNSServers: &[]string{}, - }, - Subnets: &[]mgmtnetwork.Subnet{ - { - ID: to.StringPtr(fmt.Sprintf("/subscriptions/%s/resourceGroups/test-cluster/providers/Microsoft.Network/virtualNetworks/test-vnet/subnets/master", mockSubID)), - SubnetPropertiesFormat: &mgmtnetwork.SubnetPropertiesFormat{ - RouteTable: &mgmtnetwork.RouteTable{ - ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mockrg/providers/Microsoft.Network/routeTables/routetable1"), +func validVirtualNetworksMock(virtualNetworks *mock_armnetwork.MockVirtualNetworksClient, routeTables *mock_armnetwork.MockRouteTablesClient, mockSubID string) { + virtualNetworks.EXPECT().Get(gomock.Any(), "test-cluster", "test-vnet", nil).Return(sdknetwork.VirtualNetworksClientGetResponse{ + VirtualNetwork: sdknetwork.VirtualNetwork{ + ID: ptr.To("/subscriptions/id"), + Type: ptr.To("Microsoft.Network/virtualNetworks"), + Properties: &sdknetwork.VirtualNetworkPropertiesFormat{ + DhcpOptions: &sdknetwork.DhcpOptions{ + DNSServers: []*string{}, + }, + Subnets: []*sdknetwork.Subnet{ + { + ID: ptr.To(fmt.Sprintf("/subscriptions/%s/resourceGroups/test-cluster/providers/Microsoft.Network/virtualNetworks/test-vnet/subnets/master", mockSubID)), + Properties: &sdknetwork.SubnetPropertiesFormat{ + RouteTable: &sdknetwork.RouteTable{ + ID: ptr.To("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mockrg/providers/Microsoft.Network/routeTables/routetable1"), + }, }, }, }, @@ -82,8 +83,8 @@ func validVirtualNetworksMock(virtualNetworks *mock_network.MockVirtualNetworksC routeTables.EXPECT().Get(gomock.Any(), "mockrg", "routetable1", nil).Return(sdknetwork.RouteTablesClientGetResponse{ RouteTable: sdknetwork.RouteTable{ - ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mockrg/providers/Microsoft.Network/routeTables/routetable1"), - Name: to.StringPtr("routetable1"), + ID: ptr.To("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mockrg/providers/Microsoft.Network/routeTables/routetable1"), + Name: ptr.To("routetable1"), }, }, nil) } @@ -101,7 +102,7 @@ func TestResourcesList(t *testing.T) { type test struct { name string - mocks func(*mock_network.MockVirtualNetworksClient, *mock_armnetwork.MockRouteTablesClient, *mock_compute.MockDiskEncryptionSetsClient) + mocks func(*mock_armnetwork.MockVirtualNetworksClient, *mock_armnetwork.MockRouteTablesClient, *mock_compute.MockDiskEncryptionSetsClient) wantResponse []byte wantError string diskEncryptionSetId string @@ -110,38 +111,38 @@ func TestResourcesList(t *testing.T) { for _, tt := range []*test{ { name: "basic coverage", - mocks: func(virtualNetworks *mock_network.MockVirtualNetworksClient, routeTables *mock_armnetwork.MockRouteTablesClient, diskEncryptionSets *mock_compute.MockDiskEncryptionSetsClient) { + mocks: func(virtualNetworks *mock_armnetwork.MockVirtualNetworksClient, routeTables *mock_armnetwork.MockRouteTablesClient, diskEncryptionSets *mock_compute.MockDiskEncryptionSetsClient) { validVirtualNetworksMock(virtualNetworks, routeTables, mockSubID) }, - wantResponse: []byte(`[{"properties":{"dhcpOptions":{"dnsServers":[]},"subnets":[{"properties":{"routeTable":{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mockrg/providers/Microsoft.Network/routeTables/routetable1","tags":null}},"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-cluster/providers/Microsoft.Network/virtualNetworks/test-vnet/subnets/master"}]},"id":"/subscriptions/id","type":"Microsoft.Network/virtualNetworks"},{"ID":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mockrg/providers/Microsoft.Network/routeTables/routetable1","Properties":null,"Etag":null,"name":"routetable1"},{"properties":{"provisioningState":"Succeeded"},"id":"/subscriptions/id","type":"Microsoft.Compute/virtualMachines"},{"id":"/subscriptions/id","name":"storage","type":"Microsoft.Storage/storageAccounts","location":"eastus"}]`), + wantResponse: []byte(`[{"ExtendedLocation":null,"ID":"/subscriptions/id","Properties":{"AddressSpace":null,"BgpCommunities":null,"DdosProtectionPlan":null,"DhcpOptions":{"DNSServers":[]},"EnableDdosProtection":null,"EnableVMProtection":null,"Encryption":null,"FlowTimeoutInMinutes":null,"IPAllocations":null,"Subnets":[{"ID":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-cluster/providers/Microsoft.Network/virtualNetworks/test-vnet/subnets/master","Name":null,"Properties":{"AddressPrefix":null,"AddressPrefixes":null,"ApplicationGatewayIPConfigurations":null,"Delegations":null,"IPAllocations":null,"NatGateway":null,"NetworkSecurityGroup":null,"PrivateEndpointNetworkPolicies":null,"PrivateLinkServiceNetworkPolicies":null,"RouteTable":{"ID":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mockrg/providers/Microsoft.Network/routeTables/routetable1","Location":null,"Properties":null,"Tags":null,"Etag":null,"Name":null,"Type":null},"ServiceEndpointPolicies":null,"ServiceEndpoints":null,"IPConfigurationProfiles":null,"IPConfigurations":null,"PrivateEndpoints":null,"ProvisioningState":null,"Purpose":null,"ResourceNavigationLinks":null,"ServiceAssociationLinks":null},"Type":null,"Etag":null}],"VirtualNetworkPeerings":null,"FlowLogs":null,"ProvisioningState":null,"ResourceGUID":null},"Etag":null,"type":"Microsoft.Network/virtualNetworks"},{"ID":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mockrg/providers/Microsoft.Network/routeTables/routetable1","Properties":null,"Etag":null,"name":"routetable1"},{"properties":{"provisioningState":"Succeeded"},"id":"/subscriptions/id","type":"Microsoft.Compute/virtualMachines"},{"id":"/subscriptions/id","name":"storage","type":"Microsoft.Storage/storageAccounts","location":"eastus"}]`), }, { name: "vnet get error", //Get resources should continue on error from virtualNetworks.Get() - mocks: func(virtualNetworks *mock_network.MockVirtualNetworksClient, routeTables *mock_armnetwork.MockRouteTablesClient, diskEncryptionSets *mock_compute.MockDiskEncryptionSetsClient) { + mocks: func(virtualNetworks *mock_armnetwork.MockVirtualNetworksClient, routeTables *mock_armnetwork.MockRouteTablesClient, diskEncryptionSets *mock_compute.MockDiskEncryptionSetsClient) { // Fail virtualNetworks with a GET error - virtualNetworks.EXPECT().Get(gomock.Any(), "test-cluster", "test-vnet", "").Return(mgmtnetwork.VirtualNetwork{}, fmt.Errorf("Any error during Get, expecting a permissions error")) + virtualNetworks.EXPECT().Get(gomock.Any(), "test-cluster", "test-vnet", nil).Return(sdknetwork.VirtualNetworksClientGetResponse{}, fmt.Errorf("Any error during Get, expecting a permissions error")) }, wantResponse: []byte(`[{"properties":{"provisioningState":"Succeeded"},"id":"/subscriptions/id","type":"Microsoft.Compute/virtualMachines"},{"id":"/subscriptions/id","name":"storage","type":"Microsoft.Storage/storageAccounts","location":"eastus"}]`), }, { name: "enabled diskencryptionsets", - mocks: func(virtualNetworks *mock_network.MockVirtualNetworksClient, routeTables *mock_armnetwork.MockRouteTablesClient, diskEncryptionSets *mock_compute.MockDiskEncryptionSetsClient) { + mocks: func(virtualNetworks *mock_armnetwork.MockVirtualNetworksClient, routeTables *mock_armnetwork.MockRouteTablesClient, diskEncryptionSets *mock_compute.MockDiskEncryptionSetsClient) { validVirtualNetworksMock(virtualNetworks, routeTables, mockSubID) validDiskEncryptionSetsMock(diskEncryptionSets) }, diskEncryptionSetId: fmt.Sprintf("/subscriptions/%s/resourceGroups/test-cluster/providers/Microsoft.Compute/diskEncryptionSets/test-cluster-des", mockSubID), - wantResponse: []byte(`[{"properties":{"dhcpOptions":{"dnsServers":[]},"subnets":[{"properties":{"routeTable":{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mockrg/providers/Microsoft.Network/routeTables/routetable1","tags":null}},"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-cluster/providers/Microsoft.Network/virtualNetworks/test-vnet/subnets/master"}]},"id":"/subscriptions/id","type":"Microsoft.Network/virtualNetworks"},{"ID":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mockrg/providers/Microsoft.Network/routeTables/routetable1","Properties":null,"Etag":null,"name":"routetable1"},{"id":"/subscriptions/id","type":"Microsoft.Compute/diskEncryptionSets"},{"properties":{"provisioningState":"Succeeded"},"id":"/subscriptions/id","type":"Microsoft.Compute/virtualMachines"},{"id":"/subscriptions/id","name":"storage","type":"Microsoft.Storage/storageAccounts","location":"eastus"}]`), + wantResponse: []byte(`[{"ExtendedLocation":null,"ID":"/subscriptions/id","Properties":{"AddressSpace":null,"BgpCommunities":null,"DdosProtectionPlan":null,"DhcpOptions":{"DNSServers":[]},"EnableDdosProtection":null,"EnableVMProtection":null,"Encryption":null,"FlowTimeoutInMinutes":null,"IPAllocations":null,"Subnets":[{"ID":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-cluster/providers/Microsoft.Network/virtualNetworks/test-vnet/subnets/master","Name":null,"Properties":{"AddressPrefix":null,"AddressPrefixes":null,"ApplicationGatewayIPConfigurations":null,"Delegations":null,"IPAllocations":null,"NatGateway":null,"NetworkSecurityGroup":null,"PrivateEndpointNetworkPolicies":null,"PrivateLinkServiceNetworkPolicies":null,"RouteTable":{"ID":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mockrg/providers/Microsoft.Network/routeTables/routetable1","Location":null,"Properties":null,"Tags":null,"Etag":null,"Name":null,"Type":null},"ServiceEndpointPolicies":null,"ServiceEndpoints":null,"IPConfigurationProfiles":null,"IPConfigurations":null,"PrivateEndpoints":null,"ProvisioningState":null,"Purpose":null,"ResourceNavigationLinks":null,"ServiceAssociationLinks":null},"Type":null,"Etag":null}],"VirtualNetworkPeerings":null,"FlowLogs":null,"ProvisioningState":null,"ResourceGUID":null},"Etag":null,"type":"Microsoft.Network/virtualNetworks"},{"ID":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mockrg/providers/Microsoft.Network/routeTables/routetable1","Properties":null,"Etag":null,"name":"routetable1"},{"id":"/subscriptions/id","type":"Microsoft.Compute/diskEncryptionSets"},{"properties":{"provisioningState":"Succeeded"},"id":"/subscriptions/id","type":"Microsoft.Compute/virtualMachines"},{"id":"/subscriptions/id","name":"storage","type":"Microsoft.Storage/storageAccounts","location":"eastus"}]`), }, { name: "error getting diskencryptionsets", - mocks: func(virtualNetworks *mock_network.MockVirtualNetworksClient, routeTables *mock_armnetwork.MockRouteTablesClient, diskEncryptionSets *mock_compute.MockDiskEncryptionSetsClient) { + mocks: func(virtualNetworks *mock_armnetwork.MockVirtualNetworksClient, routeTables *mock_armnetwork.MockRouteTablesClient, diskEncryptionSets *mock_compute.MockDiskEncryptionSetsClient) { validVirtualNetworksMock(virtualNetworks, routeTables, mockSubID) // Fail diskEncryptionSets with a GET error diskEncryptionSets.EXPECT().Get(gomock.Any(), "test-cluster", "test-cluster-des").Return(mgmtcompute.DiskEncryptionSet{}, fmt.Errorf("Any error during Get, expecting a permissions error")) }, diskEncryptionSetId: fmt.Sprintf("/subscriptions/%s/resourceGroups/test-cluster/providers/Microsoft.Compute/diskEncryptionSets/test-cluster-des", mockSubID), - wantResponse: []byte(`[{"properties":{"dhcpOptions":{"dnsServers":[]},"subnets":[{"properties":{"routeTable":{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mockrg/providers/Microsoft.Network/routeTables/routetable1","tags":null}},"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-cluster/providers/Microsoft.Network/virtualNetworks/test-vnet/subnets/master"}]},"id":"/subscriptions/id","type":"Microsoft.Network/virtualNetworks"},{"ID":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mockrg/providers/Microsoft.Network/routeTables/routetable1","Properties":null,"Etag":null,"name":"routetable1"},{"properties":{"provisioningState":"Succeeded"},"id":"/subscriptions/id","type":"Microsoft.Compute/virtualMachines"},{"id":"/subscriptions/id","name":"storage","type":"Microsoft.Storage/storageAccounts","location":"eastus"}]`), + wantResponse: []byte(`[{"ExtendedLocation":null,"ID":"/subscriptions/id","Properties":{"AddressSpace":null,"BgpCommunities":null,"DdosProtectionPlan":null,"DhcpOptions":{"DNSServers":[]},"EnableDdosProtection":null,"EnableVMProtection":null,"Encryption":null,"FlowTimeoutInMinutes":null,"IPAllocations":null,"Subnets":[{"ID":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-cluster/providers/Microsoft.Network/virtualNetworks/test-vnet/subnets/master","Name":null,"Properties":{"AddressPrefix":null,"AddressPrefixes":null,"ApplicationGatewayIPConfigurations":null,"Delegations":null,"IPAllocations":null,"NatGateway":null,"NetworkSecurityGroup":null,"PrivateEndpointNetworkPolicies":null,"PrivateLinkServiceNetworkPolicies":null,"RouteTable":{"ID":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mockrg/providers/Microsoft.Network/routeTables/routetable1","Location":null,"Properties":null,"Tags":null,"Etag":null,"Name":null,"Type":null},"ServiceEndpointPolicies":null,"ServiceEndpoints":null,"IPConfigurationProfiles":null,"IPConfigurations":null,"PrivateEndpoints":null,"ProvisioningState":null,"Purpose":null,"ResourceNavigationLinks":null,"ServiceAssociationLinks":null},"Type":null,"Etag":null}],"VirtualNetworkPeerings":null,"FlowLogs":null,"ProvisioningState":null,"ResourceGUID":null},"Etag":null,"type":"Microsoft.Network/virtualNetworks"},{"ID":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mockrg/providers/Microsoft.Network/routeTables/routetable1","Properties":null,"Etag":null,"name":"routetable1"},{"properties":{"provisioningState":"Succeeded"},"id":"/subscriptions/id","type":"Microsoft.Compute/virtualMachines"},{"id":"/subscriptions/id","name":"storage","type":"Microsoft.Storage/storageAccounts","location":"eastus"}]`), }, } { t.Run(tt.name, func(t *testing.T) { @@ -153,7 +154,7 @@ func TestResourcesList(t *testing.T) { resources := mock_features.NewMockResourcesClient(controller) virtualMachines := mock_compute.NewMockVirtualMachinesClient(controller) - virtualNetworks := mock_network.NewMockVirtualNetworksClient(controller) + virtualNetworks := mock_armnetwork.NewMockVirtualNetworksClient(controller) routeTables := mock_armnetwork.NewMockRouteTablesClient(controller) diskEncryptionSets := mock_compute.NewMockDiskEncryptionSetsClient(controller) diff --git a/pkg/util/azureclient/azuresdk/armnetwork/generate.go b/pkg/util/azureclient/azuresdk/armnetwork/generate.go index eda5e295fde..bd57d444d94 100644 --- a/pkg/util/azureclient/azuresdk/armnetwork/generate.go +++ b/pkg/util/azureclient/azuresdk/armnetwork/generate.go @@ -4,5 +4,5 @@ package armnetwork // Licensed under the Apache License 2.0. //go:generate rm -rf ../../../../util/mocks/$GOPACKAGE -//go:generate mockgen -destination=../../../../util/mocks/azureclient/azuresdk/$GOPACKAGE/$GOPACKAGE.go github.com/Azure/ARO-RP/pkg/util/azureclient/azuresdk/$GOPACKAGE InterfacesClient,LoadBalancersClient,LoadBalancerBackendAddressPoolsClient,PrivateEndpointsClient,PrivateLinkServicesClient,PublicIPAddressesClient,RouteTablesClient,SecurityGroupsClient,SubnetsClient +//go:generate mockgen -destination=../../../../util/mocks/azureclient/azuresdk/$GOPACKAGE/$GOPACKAGE.go github.com/Azure/ARO-RP/pkg/util/azureclient/azuresdk/$GOPACKAGE InterfacesClient,LoadBalancersClient,LoadBalancerBackendAddressPoolsClient,PrivateEndpointsClient,PrivateLinkServicesClient,PublicIPAddressesClient,RouteTablesClient,SecurityGroupsClient,SubnetsClient,VirtualNetworksClient //go:generate goimports -local=github.com/Azure/ARO-RP -e -w ../../../../util/mocks/azureclient/azuresdk/$GOPACKAGE/$GOPACKAGE.go diff --git a/pkg/util/mocks/azureclient/azuresdk/armnetwork/armnetwork.go b/pkg/util/mocks/azureclient/azuresdk/armnetwork/armnetwork.go index 935a6237ac1..8d9f547e201 100644 --- a/pkg/util/mocks/azureclient/azuresdk/armnetwork/armnetwork.go +++ b/pkg/util/mocks/azureclient/azuresdk/armnetwork/armnetwork.go @@ -1,9 +1,9 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/Azure/ARO-RP/pkg/util/azureclient/azuresdk/armnetwork (interfaces: InterfacesClient,LoadBalancersClient,LoadBalancerBackendAddressPoolsClient,PrivateEndpointsClient,PrivateLinkServicesClient,PublicIPAddressesClient,RouteTablesClient,SecurityGroupsClient,SubnetsClient) +// Source: github.com/Azure/ARO-RP/pkg/util/azureclient/azuresdk/armnetwork (interfaces: InterfacesClient,LoadBalancersClient,LoadBalancerBackendAddressPoolsClient,PrivateEndpointsClient,PrivateLinkServicesClient,PublicIPAddressesClient,RouteTablesClient,SecurityGroupsClient,SubnetsClient,VirtualNetworksClient) // // Generated by this command: // -// mockgen -destination=../../../../util/mocks/azureclient/azuresdk/armnetwork/armnetwork.go github.com/Azure/ARO-RP/pkg/util/azureclient/azuresdk/armnetwork InterfacesClient,LoadBalancersClient,LoadBalancerBackendAddressPoolsClient,PrivateEndpointsClient,PrivateLinkServicesClient,PublicIPAddressesClient,RouteTablesClient,SecurityGroupsClient,SubnetsClient +// mockgen -destination=../../../../util/mocks/azureclient/azuresdk/armnetwork/armnetwork.go github.com/Azure/ARO-RP/pkg/util/azureclient/azuresdk/armnetwork InterfacesClient,LoadBalancersClient,LoadBalancerBackendAddressPoolsClient,PrivateEndpointsClient,PrivateLinkServicesClient,PublicIPAddressesClient,RouteTablesClient,SecurityGroupsClient,SubnetsClient,VirtualNetworksClient // // Package mock_armnetwork is a generated GoMock package. @@ -615,3 +615,41 @@ func (mr *MockSubnetsClientMockRecorder) List(arg0, arg1, arg2, arg3 any) *gomoc mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockSubnetsClient)(nil).List), arg0, arg1, arg2, arg3) } + +// MockVirtualNetworksClient is a mock of VirtualNetworksClient interface. +type MockVirtualNetworksClient struct { + ctrl *gomock.Controller + recorder *MockVirtualNetworksClientMockRecorder +} + +// MockVirtualNetworksClientMockRecorder is the mock recorder for MockVirtualNetworksClient. +type MockVirtualNetworksClientMockRecorder struct { + mock *MockVirtualNetworksClient +} + +// NewMockVirtualNetworksClient creates a new mock instance. +func NewMockVirtualNetworksClient(ctrl *gomock.Controller) *MockVirtualNetworksClient { + mock := &MockVirtualNetworksClient{ctrl: ctrl} + mock.recorder = &MockVirtualNetworksClientMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockVirtualNetworksClient) EXPECT() *MockVirtualNetworksClientMockRecorder { + return m.recorder +} + +// Get mocks base method. +func (m *MockVirtualNetworksClient) Get(arg0 context.Context, arg1, arg2 string, arg3 *armnetwork.VirtualNetworksClientGetOptions) (armnetwork.VirtualNetworksClientGetResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Get", arg0, arg1, arg2, arg3) + ret0, _ := ret[0].(armnetwork.VirtualNetworksClientGetResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Get indicates an expected call of Get. +func (mr *MockVirtualNetworksClientMockRecorder) Get(arg0, arg1, arg2, arg3 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockVirtualNetworksClient)(nil).Get), arg0, arg1, arg2, arg3) +}