Skip to content

Commit

Permalink
SDK2: Replace SDK to new one in util/cluster (#3884)
Browse files Browse the repository at this point in the history
* add subnets.List

* remove deprecated nsg & subnets client from util/cluster

* add routetable client

* remove deprecated route tables client from util/cluster

* add virtual network peerings client

* remove deprecated virtual network peerings from util/cluster

* remove the rest usage of mgmt network sdk

* remove unused sdk wrappers
  • Loading branch information
bitoku authored Oct 4, 2024
1 parent 1a51bf4 commit 69378fb
Show file tree
Hide file tree
Showing 13 changed files with 217 additions and 379 deletions.
32 changes: 32 additions & 0 deletions pkg/util/azureclient/azuresdk/armnetwork/routetable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package armnetwork

// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.

import (
"context"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v2"

"github.com/Azure/ARO-RP/pkg/util/azureclient/azuresdk/azcore"
)

// RouteTablesClient is a minimal interface for azure RouteTablesClient
type RouteTablesClient interface {
Get(ctx context.Context, resourceGroupName string, routeTableName string, options *armnetwork.RouteTablesClientGetOptions) (result armnetwork.RouteTablesClientGetResponse, err error)
RouteTablesClientAddons
}

type routeTablesClient struct {
*armnetwork.RouteTablesClient
}

// NewRouteTablesClient creates a new RouteTablesClient
func NewRouteTablesClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (RouteTablesClient, error) {
clientFactory, err := armnetwork.NewClientFactory(subscriptionID, credential, options)
if err != nil {
return nil, err
}
return &routeTablesClient{clientFactory.NewRouteTablesClient()}, err
}
24 changes: 24 additions & 0 deletions pkg/util/azureclient/azuresdk/armnetwork/routetable_addons.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package armnetwork

// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.

import (
"context"

"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v2"
)

// RouteTablesClientAddons contains addons for RouteTablesClient
type RouteTablesClientAddons interface {
DeleteAndWait(ctx context.Context, resourceGroupName string, routeTableName string, options *armnetwork.RouteTablesClientBeginDeleteOptions) error
}

func (c *routeTablesClient) DeleteAndWait(ctx context.Context, resourceGroupName string, routeTableName string, options *armnetwork.RouteTablesClientBeginDeleteOptions) error {
poller, err := c.RouteTablesClient.BeginDelete(ctx, resourceGroupName, routeTableName, options)
if err != nil {
return err
}
_, err = poller.PollUntilDone(ctx, nil)
return err
}
14 changes: 14 additions & 0 deletions pkg/util/azureclient/azuresdk/armnetwork/subnets_addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
type SubnetsClientAddons interface {
CreateOrUpdateAndWait(ctx context.Context, resourceGroupName, virtualNetworkName, subnetName string, subnetParameters armnetwork.Subnet, options *armnetwork.SubnetsClientBeginCreateOrUpdateOptions) (err error)
DeleteAndWait(ctx context.Context, resourceGroupName, virtualNetworkName, subnetName string, options *armnetwork.SubnetsClientBeginDeleteOptions) error
List(ctx context.Context, resourceGroupName, virtualNetworkName string, options *armnetwork.SubnetsClientListOptions) ([]*armnetwork.Subnet, error)
}

func (c *subnetsClient) CreateOrUpdateAndWait(ctx context.Context, resourceGroupName, virtualNetworkName, subnetName string, subnetParameters armnetwork.Subnet, options *armnetwork.SubnetsClientBeginCreateOrUpdateOptions) error {
Expand All @@ -32,3 +33,16 @@ func (c *subnetsClient) DeleteAndWait(ctx context.Context, resourceGroupName, vi
_, err = poller.PollUntilDone(ctx, nil)
return err
}

func (c *subnetsClient) List(ctx context.Context, resourceGroupName, virtualNetworkName string, options *armnetwork.SubnetsClientListOptions) (result []*armnetwork.Subnet, err error) {
pager := c.SubnetsClient.NewListPager(resourceGroupName, virtualNetworkName, options)

for pager.More() {
page, err := pager.NextPage(ctx)
if err != nil {
return nil, err
}
result = append(result, page.Value...)
}
return result, nil
}
28 changes: 28 additions & 0 deletions pkg/util/azureclient/azuresdk/armnetwork/virtualnetworkpeerings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package armnetwork

// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.

import (
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v2"

"github.com/Azure/ARO-RP/pkg/util/azureclient/azuresdk/azcore"
)

type VirtualNetworkPeeringsClient interface {
VirtualNetworkPeeringsAddons
}

type virtualNetworkPeeringsClient struct {
*armnetwork.VirtualNetworkPeeringsClient
}

// NewVirtualNetworkPeeringsClient creates a new VirtualNetworkPeeringsClient
func NewVirtualNetworkPeeringsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (VirtualNetworkPeeringsClient, error) {
clientFactory, err := armnetwork.NewClientFactory(subscriptionID, credential, options)
if err != nil {
return nil, err
}
return &virtualNetworkPeeringsClient{clientFactory.NewVirtualNetworkPeeringsClient()}, err
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package armnetwork

// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.

import (
"context"

"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v2"
)

type VirtualNetworkPeeringsAddons interface {
CreateOrUpdateAndWait(ctx context.Context, resourceGroupName string, virtualNetworkName string, virtualNetworkPeeringName string, virtualNetworkPeeringParameters armnetwork.VirtualNetworkPeering, options *armnetwork.VirtualNetworkPeeringsClientBeginCreateOrUpdateOptions) (err error)
DeleteAndWait(ctx context.Context, resourceGroupName string, virtualNetworkName string, virtualNetworkPeeringName string, options *armnetwork.VirtualNetworkPeeringsClientBeginDeleteOptions) (err error)
}

func (c *virtualNetworkPeeringsClient) CreateOrUpdateAndWait(ctx context.Context, resourceGroupName string, virtualNetworkName string, virtualNetworkPeeringName string, virtualNetworkPeeringParameters armnetwork.VirtualNetworkPeering, options *armnetwork.VirtualNetworkPeeringsClientBeginCreateOrUpdateOptions) (err error) {
poller, err := c.VirtualNetworkPeeringsClient.BeginCreateOrUpdate(ctx, resourceGroupName, virtualNetworkName, virtualNetworkPeeringName, virtualNetworkPeeringParameters, options)
if err != nil {
return err
}
_, err = poller.PollUntilDone(ctx, nil)
return err
}

func (c *virtualNetworkPeeringsClient) DeleteAndWait(ctx context.Context, resourceGroupName string, virtualNetworkName string, virtualNetworkPeeringName string, options *armnetwork.VirtualNetworkPeeringsClientBeginDeleteOptions) (err error) {
poller, err := c.VirtualNetworkPeeringsClient.BeginDelete(ctx, resourceGroupName, virtualNetworkName, virtualNetworkPeeringName, options)
if err != nil {
return err
}
_, err = poller.PollUntilDone(ctx, nil)
return err
}
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,SecurityGroupsClient,VirtualNetworkPeeringsClient,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,RouteTablesClient,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/securitygroups.go

This file was deleted.

50 changes: 0 additions & 50 deletions pkg/util/azureclient/mgmt/network/securitygroups_addons.go

This file was deleted.

36 changes: 0 additions & 36 deletions pkg/util/azureclient/mgmt/network/virtualnetworkpeerings.go

This file was deleted.

33 changes: 0 additions & 33 deletions pkg/util/azureclient/mgmt/network/virtualnetworkpeerings_addons.go

This file was deleted.

Loading

0 comments on commit 69378fb

Please sign in to comment.