Skip to content

Commit

Permalink
subnets
Browse files Browse the repository at this point in the history
  • Loading branch information
bitoku committed Jul 12, 2024
1 parent 367a479 commit 1a55353
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 14 deletions.
3 changes: 1 addition & 2 deletions pkg/api/util/subnet/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ func Split(subnetID string) (string, string, error) {
return strings.Join(parts[:len(parts)-2], "/"), parts[len(parts)-1], nil
}

// NetworkSecurityGroupID returns the NetworkSecurityGroup ID for a given subnet
// ID
// NetworkSecurityGroupID returns the NetworkSecurityGroup ID for a given subnet ID
func NetworkSecurityGroupID(oc *api.OpenShiftCluster, subnetID string) (string, error) {
infraID := oc.Properties.InfraID
if infraID == "" {
Expand Down
9 changes: 8 additions & 1 deletion pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,11 @@ type manager struct {
armFPPrivateEndpoints armnetwork.PrivateEndpointsClient
rpPrivateLinkServices network.PrivateLinkServicesClient // TODO: use armRPPrivateLinkServices instead.
armRPPrivateLinkServices armnetwork.PrivateLinkServicesClient
armSubnets armnetwork.SubnetsClient

dns dns.Manager
storage storage.Manager
subnet subnet.Manager
subnet subnet.Manager // TODO: use armSubnet instead.
graph graph.Manager
rpBlob azblob.Manager

Expand Down Expand Up @@ -227,6 +228,11 @@ func New(ctx context.Context, log *logrus.Entry, _env env.Interface, db database
return nil, err
}

armSubnetsClient, err := armnetwork.NewSubnetsClient(r.SubscriptionID, fpCredClusterTenant, &clientOptions)
if err != nil {
return nil, err
}

return &manager{
log: log,
env: _env,
Expand Down Expand Up @@ -263,6 +269,7 @@ func New(ctx context.Context, log *logrus.Entry, _env env.Interface, db database
armFPPrivateEndpoints: armFPPrivateEndpoints,
rpPrivateLinkServices: network.NewPrivateLinkServicesClient(_env.Environment(), _env.SubscriptionID(), msiAuthorizer),
armRPPrivateLinkServices: armRPPrivateLinkServices,
armSubnets: armSubnetsClient,

dns: dns.NewManager(_env, localFPAuthorizer),
storage: storage,
Expand Down
9 changes: 6 additions & 3 deletions pkg/monitor/azure/nsg/nsg.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,13 @@ func NewMonitor(log *logrus.Entry, oc *api.OpenShiftCluster, e env.Interface, su
return &monitoring.NoOpMonitor{Wg: wg}
}

options := arm.ClientOptions{
ClientOptions: e.Environment().ClientCertificateCredentialOptions().ClientOptions,
clientOptions := arm.ClientOptions{
ClientOptions: azcore.ClientOptions{
Cloud: e.Environment().Cloud,
},
}
client, err := armnetwork.NewSubnetsClient(subscriptionID, token, &options)

client, err := sdknetwork.NewSubnetsClient(subscriptionID, token, &clientOptions)
if err != nil {
log.Error("Unable to create the subnet client for NSG monitoring", err)
emitter.EmitGauge(MetricFailedNSGMonitorCreation, int64(1), dims)
Expand Down
17 changes: 9 additions & 8 deletions pkg/util/azureclient/azuresdk/armnetwork/subnets.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,25 @@ import (
"context"

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

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

// SubnetsClient is a minimal interface for azure-sdk-for-go subnets client
type SubnetsClient interface {
Get(ctx context.Context, resourceGroupName, virtualNetworkName, subnetName string, options *sdknetwork.SubnetsClientGetOptions) (sdknetwork.SubnetsClientGetResponse, error)
Get(ctx context.Context, resourceGroupName, virtualNetworkName, subnetName string, options *armnetwork.SubnetsClientGetOptions) (armnetwork.SubnetsClientGetResponse, error)
SubnetsClientAddons
}

type subnetsClient struct {
*sdknetwork.SubnetsClient
*armnetwork.SubnetsClient
}

var _ SubnetsClient = (*subnetsClient)(nil)

func NewSubnetsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (SubnetsClient, error) {
client, err := sdknetwork.NewSubnetsClient(subscriptionID, credential, options)

return subnetsClient{client}, err
clientFactory, err := armnetwork.NewClientFactory(subscriptionID, credential, options)
if err != nil {
return nil, err
}
return &subnetsClient{clientFactory.NewSubnetsClient()}, err
}
34 changes: 34 additions & 0 deletions pkg/util/azureclient/azuresdk/armnetwork/subnets_addons.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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"
)

// SubnetsClientAddons contains addons for SubnetsClient
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
}

func (c *subnetsClient) CreateOrUpdateAndWait(ctx context.Context, resourceGroupName, virtualNetworkName, subnetName string, subnetParameters armnetwork.Subnet, options *armnetwork.SubnetsClientBeginCreateOrUpdateOptions) error {
poller, err := c.SubnetsClient.BeginCreateOrUpdate(ctx, resourceGroupName, virtualNetworkName, subnetName, subnetParameters, options)
if err != nil {
return err
}
_, err = poller.PollUntilDone(ctx, nil)
return err
}

func (c *subnetsClient) DeleteAndWait(ctx context.Context, resourceGroupName, virtualNetworkName, subnetName string, options *armnetwork.SubnetsClientBeginDeleteOptions) error {
poller, err := c.SubnetsClient.BeginDelete(ctx, resourceGroupName, virtualNetworkName, subnetName, options)
if err != nil {
return err
}
_, err = poller.PollUntilDone(ctx, nil)
return err
}

0 comments on commit 1a55353

Please sign in to comment.