Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK2: Replace old network SDK in ListResources Admin API #3890

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions pkg/frontend/adminactions/azureactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -46,9 +47,9 @@ type azureActions struct {
resources features.ResourcesClient
resourceSkus compute.ResourceSkusClient
virtualMachines compute.VirtualMachinesClient
virtualNetworks network.VirtualNetworksClient
virtualNetworks armnetwork.VirtualNetworksClient
diskEncryptionSets compute.DiskEncryptionSetsClient
routeTables network.RouteTablesClient
routeTables armnetwork.RouteTablesClient
storageAccounts storage.AccountsClient
networkInterfaces network.InterfacesClient
loadBalancers network.LoadBalancersClient
Expand All @@ -63,6 +64,23 @@ 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
}

virtualNetworks, err := armnetwork.NewVirtualNetworksClient(subscriptionDoc.ID, credential, options)
if err != nil {
return nil, err
}

return &azureActions{
log: log,
env: env,
Expand All @@ -71,9 +89,9 @@ 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: 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),
Expand Down
20 changes: 10 additions & 10 deletions pkg/frontend/adminactions/resources_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -144,19 +144,19 @@ 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, "")
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{
Resource: rt,
Resource: rt.RouteTable,
})
}
}
Expand Down
65 changes: 35 additions & 30 deletions pkg/frontend/adminactions/resources_list_test.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/util/azureclient/azuresdk/armnetwork/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,VirtualNetworksClient
//go:generate goimports -local=github.com/Azure/ARO-RP -e -w ../../../../util/mocks/azureclient/azuresdk/$GOPACKAGE/$GOPACKAGE.go
2 changes: 1 addition & 1 deletion pkg/util/azureclient/mgmt/network/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
36 changes: 0 additions & 36 deletions pkg/util/azureclient/mgmt/network/routetable.go

This file was deleted.

22 changes: 0 additions & 22 deletions pkg/util/azureclient/mgmt/network/routetable_addons.go

This file was deleted.

94 changes: 92 additions & 2 deletions pkg/util/mocks/azureclient/azuresdk/armnetwork/armnetwork.go

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

56 changes: 2 additions & 54 deletions pkg/util/mocks/azureclient/mgmt/network/network.go

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

Loading