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

update SDK to track2 in ensureGatewayCreate #3616

Merged
merged 2 commits into from
Sep 20, 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
10 changes: 0 additions & 10 deletions pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ type manager struct {
armPublicIPAddresses armnetwork.PublicIPAddressesClient
loadBalancers network.LoadBalancersClient // TODO: use armLoadBalancers instead.
armLoadBalancers armnetwork.LoadBalancersClient
privateEndpoints network.PrivateEndpointsClient // TODO: use armPrivateEndpoints instead.
tiguelu marked this conversation as resolved.
Show resolved Hide resolved
armPrivateEndpoints armnetwork.PrivateEndpointsClient
securityGroups network.SecurityGroupsClient // TODO: use armSecurityGroups instead.
armSecurityGroups armnetwork.SecurityGroupsClient
Expand All @@ -94,7 +93,6 @@ type manager struct {
denyAssignments authorization.DenyAssignmentClient
fpPrivateEndpoints network.PrivateEndpointsClient // TODO: use armFPPrivateEndpoints instead.
armFPPrivateEndpoints armnetwork.PrivateEndpointsClient
rpPrivateLinkServices network.PrivateLinkServicesClient // TODO: use armRPPrivateLinkServices instead.
tiguelu marked this conversation as resolved.
Show resolved Hide resolved
armRPPrivateLinkServices armnetwork.PrivateLinkServicesClient

dns dns.Manager
Expand Down Expand Up @@ -162,12 +160,6 @@ func New(ctx context.Context, log *logrus.Entry, _env env.Interface, db database
return nil, err
}

// TODO: Delete once the replacement to track2 is done.
msiAuthorizer, err := _env.NewMSIAuthorizer(_env.Environment().ResourceManagerScope)
if err != nil {
return nil, err
}

storage := storage.NewManager(_env, r.SubscriptionID, fpAuthorizer)

installViaHive, err := _env.LiveConfig().InstallViaHive(ctx)
Expand Down Expand Up @@ -247,7 +239,6 @@ func New(ctx context.Context, log *logrus.Entry, _env env.Interface, db database
armPublicIPAddresses: armPublicIPAddressesClient,
loadBalancers: network.NewLoadBalancersClient(_env.Environment(), r.SubscriptionID, fpAuthorizer),
armLoadBalancers: armLoadBalancersClient,
privateEndpoints: network.NewPrivateEndpointsClient(_env.Environment(), r.SubscriptionID, fpAuthorizer),
armPrivateEndpoints: armPrivateEndpoints,
securityGroups: network.NewSecurityGroupsClient(_env.Environment(), r.SubscriptionID, fpAuthorizer),
armSecurityGroups: armSecurityGroupsClient,
Expand All @@ -261,7 +252,6 @@ func New(ctx context.Context, log *logrus.Entry, _env env.Interface, db database
denyAssignments: authorization.NewDenyAssignmentsClient(_env.Environment(), r.SubscriptionID, fpAuthorizer),
fpPrivateEndpoints: network.NewPrivateEndpointsClient(_env.Environment(), _env.SubscriptionID(), localFPAuthorizer),
armFPPrivateEndpoints: armFPPrivateEndpoints,
rpPrivateLinkServices: network.NewPrivateLinkServicesClient(_env.Environment(), _env.SubscriptionID(), msiAuthorizer),
armRPPrivateLinkServices: armRPPrivateLinkServices,

dns: dns.NewManager(_env, localFPAuthorizer),
Expand Down
22 changes: 12 additions & 10 deletions pkg/cluster/ipaddresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import (
"net/http"
"strings"

"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v2"
mgmtnetwork "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-08-01/network"
"github.com/Azure/go-autorest/autorest/to"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"

"github.com/Azure/ARO-RP/pkg/api"
"github.com/Azure/ARO-RP/pkg/database/cosmosdb"
Expand Down Expand Up @@ -212,12 +214,12 @@ func (m *manager) ensureGatewayCreate(ctx context.Context) error {

resourceGroup := stringutils.LastTokenByte(m.doc.OpenShiftCluster.Properties.ClusterProfile.ResourceGroupID, '/')

pe, err := m.privateEndpoints.Get(ctx, resourceGroup, infraID+"-pe", "networkInterfaces")
pe, err := m.armPrivateEndpoints.Get(ctx, resourceGroup, infraID+"-pe", &armnetwork.PrivateEndpointsClientGetOptions{Expand: ptr.To("networkInterfaces")})
if err != nil {
return err
}

pls, err := m.rpPrivateLinkServices.Get(ctx, m.env.GatewayResourceGroup(), "gateway-pls-001", "")
pls, err := m.armRPPrivateLinkServices.Get(ctx, m.env.GatewayResourceGroup(), "gateway-pls-001", nil)
if err != nil {
return err
}
Expand All @@ -227,18 +229,18 @@ func (m *manager) ensureGatewayCreate(ctx context.Context) error {
// call to the resource graph service, but it's not worth the effort to do
// that here.
var linkIdentifier string
for _, conn := range *pls.PrivateEndpointConnections {
if !strings.EqualFold(*conn.PrivateEndpoint.ID, *pe.ID) {
for _, conn := range pls.Properties.PrivateEndpointConnections {
if !strings.EqualFold(*conn.Properties.PrivateEndpoint.ID, *pe.ID) {
continue
}

linkIdentifier = *conn.LinkIdentifier
linkIdentifier = *conn.Properties.LinkIdentifier

if !strings.EqualFold(*conn.PrivateLinkServiceConnectionState.Status, "Approved") {
conn.PrivateLinkServiceConnectionState.Status = to.StringPtr("Approved")
conn.PrivateLinkServiceConnectionState.Description = to.StringPtr("Approved")
if !strings.EqualFold(*conn.Properties.PrivateLinkServiceConnectionState.Status, "Approved") {
conn.Properties.PrivateLinkServiceConnectionState.Status = to.StringPtr("Approved")
conn.Properties.PrivateLinkServiceConnectionState.Description = to.StringPtr("Approved")

_, err = m.rpPrivateLinkServices.UpdatePrivateEndpointConnection(ctx, m.env.GatewayResourceGroup(), "gateway-pls-001", *conn.Name, conn)
_, err = m.armRPPrivateLinkServices.UpdatePrivateEndpointConnection(ctx, m.env.GatewayResourceGroup(), "gateway-pls-001", *conn.Name, *conn, nil)
if err != nil {
return err
}
Expand Down Expand Up @@ -280,7 +282,7 @@ func (m *manager) ensureGatewayCreate(ctx context.Context) error {
}

m.doc, err = m.db.PatchWithLease(ctx, m.doc.Key, func(doc *api.OpenShiftClusterDocument) error {
doc.OpenShiftCluster.Properties.NetworkProfile.GatewayPrivateEndpointIP = *(*(*pe.PrivateEndpointProperties.NetworkInterfaces)[0].IPConfigurations)[0].PrivateIPAddress
doc.OpenShiftCluster.Properties.NetworkProfile.GatewayPrivateEndpointIP = *pe.Properties.NetworkInterfaces[0].Properties.IPConfigurations[0].Properties.PrivateIPAddress
doc.OpenShiftCluster.Properties.NetworkProfile.GatewayPrivateLinkID = linkIdentifier
return nil
})
Expand Down
112 changes: 60 additions & 52 deletions pkg/cluster/ipaddresses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ func TestEnsureGatewayCreate(t *testing.T) {

for _, tt := range []struct {
name string
mocks func(*mock_env.MockInterface, *mock_network.MockPrivateEndpointsClient, *mock_network.MockPrivateLinkServicesClient)
tiguelu marked this conversation as resolved.
Show resolved Hide resolved
mocks func(*mock_env.MockInterface, *mock_armnetwork.MockPrivateEndpointsClient, *mock_armnetwork.MockPrivateLinkServicesClient)
fixture func(*testdatabase.Fixture)
checker func(*testdatabase.Checker)
gatewayEnabled bool
Expand All @@ -723,29 +723,33 @@ func TestEnsureGatewayCreate(t *testing.T) {
},
{
name: "error: private endpoint connection not found",
mocks: func(env *mock_env.MockInterface, privateEndpoints *mock_network.MockPrivateEndpointsClient, rpPrivateLinkServices *mock_network.MockPrivateLinkServicesClient) {
mocks: func(env *mock_env.MockInterface, privateEndpoints *mock_armnetwork.MockPrivateEndpointsClient, rpPrivateLinkServices *mock_armnetwork.MockPrivateLinkServicesClient) {
env.EXPECT().GatewayResourceGroup().AnyTimes().Return("gatewayResourceGroup")
privateEndpoints.EXPECT().Get(ctx, "clusterResourceGroup", "infra-pe", "networkInterfaces").Return(mgmtnetwork.PrivateEndpoint{
PrivateEndpointProperties: &mgmtnetwork.PrivateEndpointProperties{
NetworkInterfaces: &[]mgmtnetwork.Interface{
{
InterfacePropertiesFormat: &mgmtnetwork.InterfacePropertiesFormat{
IPConfigurations: &[]mgmtnetwork.InterfaceIPConfiguration{
{
InterfaceIPConfigurationPropertiesFormat: &mgmtnetwork.InterfaceIPConfigurationPropertiesFormat{
PrivateIPAddress: to.StringPtr(privateIP),
privateEndpoints.EXPECT().Get(ctx, "clusterResourceGroup", "infra-pe", &armnetwork.PrivateEndpointsClientGetOptions{Expand: to.StringPtr("networkInterfaces")}).Return(armnetwork.PrivateEndpointsClientGetResponse{
PrivateEndpoint: armnetwork.PrivateEndpoint{
Properties: &armnetwork.PrivateEndpointProperties{
NetworkInterfaces: []*armnetwork.Interface{
{
Properties: &armnetwork.InterfacePropertiesFormat{
IPConfigurations: []*armnetwork.InterfaceIPConfiguration{
{
Properties: &armnetwork.InterfaceIPConfigurationPropertiesFormat{
PrivateIPAddress: to.StringPtr(privateIP),
},
},
},
},
},
},
},
ID: to.StringPtr("peID"),
},
ID: to.StringPtr("peID"),
}, nil)
rpPrivateLinkServices.EXPECT().Get(ctx, "gatewayResourceGroup", "gateway-pls-001", "").Return(mgmtnetwork.PrivateLinkService{
PrivateLinkServiceProperties: &mgmtnetwork.PrivateLinkServiceProperties{
PrivateEndpointConnections: &[]mgmtnetwork.PrivateEndpointConnection{},
rpPrivateLinkServices.EXPECT().Get(ctx, "gatewayResourceGroup", "gateway-pls-001", nil).Return(armnetwork.PrivateLinkServicesClientGetResponse{
PrivateLinkService: armnetwork.PrivateLinkService{
Properties: &armnetwork.PrivateLinkServiceProperties{
PrivateEndpointConnections: []*armnetwork.PrivateEndpointConnection{},
},
},
}, nil)
},
Expand All @@ -754,64 +758,68 @@ func TestEnsureGatewayCreate(t *testing.T) {
},
{
name: "ok",
mocks: func(env *mock_env.MockInterface, privateEndpoints *mock_network.MockPrivateEndpointsClient, rpPrivateLinkServices *mock_network.MockPrivateLinkServicesClient) {
mocks: func(env *mock_env.MockInterface, privateEndpoints *mock_armnetwork.MockPrivateEndpointsClient, rpPrivateLinkServices *mock_armnetwork.MockPrivateLinkServicesClient) {
env.EXPECT().GatewayResourceGroup().AnyTimes().Return("gatewayResourceGroup")
privateEndpoints.EXPECT().Get(ctx, "clusterResourceGroup", "infra-pe", "networkInterfaces").Return(mgmtnetwork.PrivateEndpoint{
PrivateEndpointProperties: &mgmtnetwork.PrivateEndpointProperties{
NetworkInterfaces: &[]mgmtnetwork.Interface{
{
InterfacePropertiesFormat: &mgmtnetwork.InterfacePropertiesFormat{
IPConfigurations: &[]mgmtnetwork.InterfaceIPConfiguration{
{
InterfaceIPConfigurationPropertiesFormat: &mgmtnetwork.InterfaceIPConfigurationPropertiesFormat{
PrivateIPAddress: to.StringPtr(privateIP),
privateEndpoints.EXPECT().Get(ctx, "clusterResourceGroup", "infra-pe", &armnetwork.PrivateEndpointsClientGetOptions{Expand: to.StringPtr("networkInterfaces")}).Return(armnetwork.PrivateEndpointsClientGetResponse{
PrivateEndpoint: armnetwork.PrivateEndpoint{
Properties: &armnetwork.PrivateEndpointProperties{
NetworkInterfaces: []*armnetwork.Interface{
{
Properties: &armnetwork.InterfacePropertiesFormat{
IPConfigurations: []*armnetwork.InterfaceIPConfiguration{
{
Properties: &armnetwork.InterfaceIPConfigurationPropertiesFormat{
PrivateIPAddress: to.StringPtr(privateIP),
},
},
},
},
},
},
},
ID: to.StringPtr("peID"),
},
ID: to.StringPtr("peID"),
}, nil)
rpPrivateLinkServices.EXPECT().Get(ctx, "gatewayResourceGroup", "gateway-pls-001", "").Return(mgmtnetwork.PrivateLinkService{
PrivateLinkServiceProperties: &mgmtnetwork.PrivateLinkServiceProperties{
PrivateEndpointConnections: &[]mgmtnetwork.PrivateEndpointConnection{
{
PrivateEndpointConnectionProperties: &mgmtnetwork.PrivateEndpointConnectionProperties{
PrivateEndpoint: &mgmtnetwork.PrivateEndpoint{
ID: to.StringPtr("otherPeID"),
rpPrivateLinkServices.EXPECT().Get(ctx, "gatewayResourceGroup", "gateway-pls-001", nil).Return(armnetwork.PrivateLinkServicesClientGetResponse{
PrivateLinkService: armnetwork.PrivateLinkService{
Properties: &armnetwork.PrivateLinkServiceProperties{
PrivateEndpointConnections: []*armnetwork.PrivateEndpointConnection{
{
Properties: &armnetwork.PrivateEndpointConnectionProperties{
PrivateEndpoint: &armnetwork.PrivateEndpoint{
ID: to.StringPtr("otherPeID"),
},
},
},
},
{
PrivateEndpointConnectionProperties: &mgmtnetwork.PrivateEndpointConnectionProperties{
PrivateEndpoint: &mgmtnetwork.PrivateEndpoint{
ID: to.StringPtr("peID"),
},
PrivateLinkServiceConnectionState: &mgmtnetwork.PrivateLinkServiceConnectionState{
Status: to.StringPtr(""),
{
Properties: &armnetwork.PrivateEndpointConnectionProperties{
PrivateEndpoint: &armnetwork.PrivateEndpoint{
ID: to.StringPtr("peID"),
},
PrivateLinkServiceConnectionState: &armnetwork.PrivateLinkServiceConnectionState{
Status: to.StringPtr(""),
},
LinkIdentifier: to.StringPtr("1234"),
},
LinkIdentifier: to.StringPtr("1234"),
Name: to.StringPtr("conn"),
},
Name: to.StringPtr("conn"),
},
},
},
}, nil)
rpPrivateLinkServices.EXPECT().UpdatePrivateEndpointConnection(ctx, "gatewayResourceGroup", "gateway-pls-001", "conn", mgmtnetwork.PrivateEndpointConnection{
PrivateEndpointConnectionProperties: &mgmtnetwork.PrivateEndpointConnectionProperties{
PrivateEndpoint: &mgmtnetwork.PrivateEndpoint{
rpPrivateLinkServices.EXPECT().UpdatePrivateEndpointConnection(ctx, "gatewayResourceGroup", "gateway-pls-001", "conn", armnetwork.PrivateEndpointConnection{
Properties: &armnetwork.PrivateEndpointConnectionProperties{
PrivateEndpoint: &armnetwork.PrivateEndpoint{
ID: to.StringPtr("peID"),
},
PrivateLinkServiceConnectionState: &mgmtnetwork.PrivateLinkServiceConnectionState{
PrivateLinkServiceConnectionState: &armnetwork.PrivateLinkServiceConnectionState{
Status: to.StringPtr("Approved"),
Description: to.StringPtr("Approved"),
},
LinkIdentifier: to.StringPtr("1234"),
},
Name: to.StringPtr("conn"),
}).Return(mgmtnetwork.PrivateEndpointConnection{}, nil)
}, nil).Return(armnetwork.PrivateLinkServicesClientUpdatePrivateEndpointConnectionResponse{}, nil)
},
fixture: func(f *testdatabase.Fixture) {
f.AddOpenShiftClusterDocuments(&api.OpenShiftClusterDocument{
Expand Down Expand Up @@ -851,8 +859,8 @@ func TestEnsureGatewayCreate(t *testing.T) {
defer controller.Finish()

env := mock_env.NewMockInterface(controller)
privateEndpoints := mock_network.NewMockPrivateEndpointsClient(controller)
rpPrivateLinkServices := mock_network.NewMockPrivateLinkServicesClient(controller)
privateEndpoints := mock_armnetwork.NewMockPrivateEndpointsClient(controller)
rpPrivateLinkServices := mock_armnetwork.NewMockPrivateLinkServicesClient(controller)

dbOpenShiftClusters, clientOpenShiftClusters := testdatabase.NewFakeOpenShiftClusters()
dbGateway, clientGateway := testdatabase.NewFakeGateway()
Expand Down Expand Up @@ -893,8 +901,8 @@ func TestEnsureGatewayCreate(t *testing.T) {
},
},
},
privateEndpoints: privateEndpoints,
rpPrivateLinkServices: rpPrivateLinkServices,
armPrivateEndpoints: privateEndpoints,
armRPPrivateLinkServices: rpPrivateLinkServices,
}

err = m.ensureGatewayCreate(ctx)
Expand Down
Loading