Use track2 SDK in updateAPIIPEarly (#3638)

This commit is contained in:
Ayato Tokubi 2024-06-28 16:41:20 +01:00 коммит произвёл GitHub
Родитель ae26d7660c
Коммит ce6152db5b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
3 изменённых файлов: 75 добавлений и 60 удалений

Просмотреть файл

@ -141,7 +141,7 @@ func New(ctx context.Context, log *logrus.Entry, _env env.Interface, db database
return nil, err
}
fpCredential, err := _env.FPNewClientCertificateCredential(_env.TenantID())
fpCredClusterTenant, err := _env.FPNewClientCertificateCredential(subscriptionDoc.Subscription.Properties.TenantID)
if err != nil {
return nil, err
}
@ -170,17 +170,17 @@ func New(ctx context.Context, log *logrus.Entry, _env env.Interface, db database
},
}
armLoadBalancersClient, err := armnetwork.NewLoadBalancersClient(r.SubscriptionID, fpCredential, &clientOptions)
armLoadBalancersClient, err := armnetwork.NewLoadBalancersClient(r.SubscriptionID, fpCredClusterTenant, &clientOptions)
if err != nil {
return nil, err
}
armInterfacesClient, err := armnetwork.NewInterfacesClient(r.SubscriptionID, fpCredential, &clientOptions)
armInterfacesClient, err := armnetwork.NewInterfacesClient(r.SubscriptionID, fpCredClusterTenant, &clientOptions)
if err != nil {
return nil, err
}
armPublicIPAddressesClient, err := armnetwork.NewPublicIPAddressesClient(r.SubscriptionID, fpCredential, &clientOptions)
armPublicIPAddressesClient, err := armnetwork.NewPublicIPAddressesClient(r.SubscriptionID, fpCredClusterTenant, &clientOptions)
if err != nil {
return nil, err
}

Просмотреть файл

@ -164,25 +164,27 @@ func (m *manager) populateDatabaseIntIP(ctx context.Context) error {
return err
}
// this function can only be called on create - not on update - because it
// updateAPIIPEarly updates the `doc` with the public and private IP of the API server,
// and updates the DNS record of the API server according to the API server visibility.
// This function can only be called on create - not on update - because it
// refers to -pip-v4, which doesn't exist on pre-DNS change clusters.
func (m *manager) updateAPIIPEarly(ctx context.Context) error {
infraID := m.doc.OpenShiftCluster.Properties.InfraID
resourceGroup := stringutils.LastTokenByte(m.doc.OpenShiftCluster.Properties.ClusterProfile.ResourceGroupID, '/')
lb, err := m.loadBalancers.Get(ctx, resourceGroup, infraID+"-internal", "")
lb, err := m.armLoadBalancers.Get(ctx, resourceGroup, infraID+"-internal", nil)
if err != nil {
return err
}
intIPAddress := *((*lb.FrontendIPConfigurations)[0].PrivateIPAddress)
intIPAddress := *lb.Properties.FrontendIPConfigurations[0].Properties.PrivateIPAddress
ipAddress := intIPAddress
if m.doc.OpenShiftCluster.Properties.APIServerProfile.Visibility == api.VisibilityPublic {
ip, err := m.publicIPAddresses.Get(ctx, resourceGroup, infraID+"-pip-v4", "")
ip, err := m.armPublicIPAddresses.Get(ctx, resourceGroup, infraID+"-pip-v4", nil)
if err != nil {
return err
}
ipAddress = *ip.IPAddress
ipAddress = *ip.Properties.IPAddress
}
err = m.dns.Update(ctx, m.doc.OpenShiftCluster, ipAddress)

Просмотреть файл

@ -8,6 +8,7 @@ import (
"strings"
"testing"
"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"
"github.com/golang/mock/gomock"
@ -18,6 +19,7 @@ import (
"github.com/Azure/ARO-RP/pkg/api"
"github.com/Azure/ARO-RP/pkg/database/cosmosdb"
mock_armnetwork "github.com/Azure/ARO-RP/pkg/util/mocks/azureclient/azuresdk/armnetwork"
mock_network "github.com/Azure/ARO-RP/pkg/util/mocks/azureclient/mgmt/network"
mock_dns "github.com/Azure/ARO-RP/pkg/util/mocks/dns"
mock_env "github.com/Azure/ARO-RP/pkg/util/mocks/env"
@ -26,6 +28,11 @@ import (
utilerror "github.com/Azure/ARO-RP/test/util/error"
)
const (
privateIP = "10.0.0.1"
publicIP = "1.2.3.4"
)
func TestCreateOrUpdateRouterIPFromCluster(t *testing.T) {
ctx := context.Background()
@ -61,7 +68,7 @@ func TestCreateOrUpdateRouterIPFromCluster(t *testing.T) {
fixture.AddOpenShiftClusterDocuments(doc)
doc.Dequeues = 1
doc.OpenShiftCluster.Properties.IngressProfiles[0].IP = "1.2.3.4"
doc.OpenShiftCluster.Properties.IngressProfiles[0].IP = publicIP
checker.AddOpenShiftClusterDocuments(doc)
},
mocks: func(dns *mock_dns.MockManager) {
@ -77,7 +84,7 @@ func TestCreateOrUpdateRouterIPFromCluster(t *testing.T) {
Status: corev1.ServiceStatus{
LoadBalancer: corev1.LoadBalancerStatus{
Ingress: []corev1.LoadBalancerIngress{{
IP: "1.2.3.4",
IP: publicIP,
}},
},
},
@ -217,7 +224,7 @@ func TestCreateOrUpdateRouterIPEarly(t *testing.T) {
fixture.AddOpenShiftClusterDocuments(doc)
doc.Dequeues = 1
doc.OpenShiftCluster.Properties.IngressProfiles[0].IP = "1.2.3.4"
doc.OpenShiftCluster.Properties.IngressProfiles[0].IP = publicIP
checker.AddOpenShiftClusterDocuments(doc)
},
mocks: func(publicIPAddresses *mock_network.MockPublicIPAddressesClient, dns *mock_dns.MockManager, subnet *mock_subnet.MockManager) {
@ -225,7 +232,7 @@ func TestCreateOrUpdateRouterIPEarly(t *testing.T) {
Get(gomock.Any(), "clusterResourceGroup", "infra-default-v4", "").
Return(mgmtnetwork.PublicIPAddress{
PublicIPAddressPropertiesFormat: &mgmtnetwork.PublicIPAddressPropertiesFormat{
IPAddress: to.StringPtr("1.2.3.4"),
IPAddress: to.StringPtr(publicIP),
},
}, nil)
dns.EXPECT().
@ -262,13 +269,13 @@ func TestCreateOrUpdateRouterIPEarly(t *testing.T) {
fixture.AddOpenShiftClusterDocuments(doc)
doc.Dequeues = 1
doc.OpenShiftCluster.Properties.IngressProfiles[0].IP = "1.2.3.4"
doc.OpenShiftCluster.Properties.IngressProfiles[0].IP = publicIP
checker.AddOpenShiftClusterDocuments(doc)
},
mocks: func(publicIPAddresses *mock_network.MockPublicIPAddressesClient, dns *mock_dns.MockManager, subnet *mock_subnet.MockManager) {
subnet.EXPECT().
GetHighestFreeIP(gomock.Any(), "subnetid").
Return("1.2.3.4", nil)
Return(publicIP, nil)
dns.EXPECT().
CreateOrUpdateRouter(gomock.Any(), gomock.Any(), gomock.Any()).
Return(nil)
@ -308,13 +315,13 @@ func TestCreateOrUpdateRouterIPEarly(t *testing.T) {
fixture.AddOpenShiftClusterDocuments(doc)
doc.Dequeues = 1
doc.OpenShiftCluster.Properties.IngressProfiles[0].IP = "1.2.3.4"
doc.OpenShiftCluster.Properties.IngressProfiles[0].IP = publicIP
checker.AddOpenShiftClusterDocuments(doc)
},
mocks: func(publicIPAddresses *mock_network.MockPublicIPAddressesClient, dns *mock_dns.MockManager, subnet *mock_subnet.MockManager) {
subnet.EXPECT().
GetHighestFreeIP(gomock.Any(), "enricheWPsubnetid").
Return("1.2.3.4", nil)
Return(publicIP, nil)
dns.EXPECT().
CreateOrUpdateRouter(gomock.Any(), gomock.Any(), gomock.Any()).
Return(nil)
@ -402,7 +409,7 @@ func TestPopulateDatabaseIntIP(t *testing.T) {
fixture.AddOpenShiftClusterDocuments(doc)
doc.Dequeues = 1
doc.OpenShiftCluster.Properties.APIServerProfile.IntIP = "10.0.0.1"
doc.OpenShiftCluster.Properties.APIServerProfile.IntIP = privateIP
checker.AddOpenShiftClusterDocuments(doc)
},
mocks: func(loadBalancers *mock_network.MockLoadBalancersClient) {
@ -413,7 +420,7 @@ func TestPopulateDatabaseIntIP(t *testing.T) {
FrontendIPConfigurations: &[]mgmtnetwork.FrontendIPConfiguration{
{
FrontendIPConfigurationPropertiesFormat: &mgmtnetwork.FrontendIPConfigurationPropertiesFormat{
PrivateIPAddress: to.StringPtr("10.0.0.1"),
PrivateIPAddress: to.StringPtr(privateIP),
},
},
},
@ -441,7 +448,7 @@ func TestPopulateDatabaseIntIP(t *testing.T) {
fixture.AddOpenShiftClusterDocuments(doc)
doc.Dequeues = 1
doc.OpenShiftCluster.Properties.APIServerProfile.IntIP = "10.0.0.1"
doc.OpenShiftCluster.Properties.APIServerProfile.IntIP = privateIP
checker.AddOpenShiftClusterDocuments(doc)
},
mocks: func(loadBalancers *mock_network.MockLoadBalancersClient) {
@ -452,7 +459,7 @@ func TestPopulateDatabaseIntIP(t *testing.T) {
FrontendIPConfigurations: &[]mgmtnetwork.FrontendIPConfiguration{
{
FrontendIPConfigurationPropertiesFormat: &mgmtnetwork.FrontendIPConfigurationPropertiesFormat{
PrivateIPAddress: to.StringPtr("10.0.0.1"),
PrivateIPAddress: to.StringPtr(privateIP),
},
},
},
@ -472,7 +479,7 @@ func TestPopulateDatabaseIntIP(t *testing.T) {
ResourceGroupID: resourceGroupID,
},
APIServerProfile: api.APIServerProfile{
IntIP: "10.0.0.1",
IntIP: privateIP,
},
ProvisioningState: api.ProvisioningStateCreating,
InfraID: "infra",
@ -540,7 +547,7 @@ func TestUpdateAPIIPEarly(t *testing.T) {
for _, tt := range []struct {
name string
fixtureChecker func(*testdatabase.Fixture, *testdatabase.Checker, *cosmosdb.FakeOpenShiftClusterDocumentClient)
mocks func(*mock_network.MockLoadBalancersClient, *mock_network.MockPublicIPAddressesClient, *mock_dns.MockManager)
mocks func(*mock_armnetwork.MockLoadBalancersClient, *mock_armnetwork.MockPublicIPAddressesClient, *mock_dns.MockManager)
wantErr string
}{
{
@ -565,33 +572,37 @@ func TestUpdateAPIIPEarly(t *testing.T) {
fixture.AddOpenShiftClusterDocuments(doc)
doc.Dequeues = 1
doc.OpenShiftCluster.Properties.APIServerProfile.IP = "1.2.3.4"
doc.OpenShiftCluster.Properties.APIServerProfile.IntIP = "10.0.0.1"
doc.OpenShiftCluster.Properties.APIServerProfile.IP = publicIP
doc.OpenShiftCluster.Properties.APIServerProfile.IntIP = privateIP
checker.AddOpenShiftClusterDocuments(doc)
},
mocks: func(loadBalancers *mock_network.MockLoadBalancersClient, publicIPAddresses *mock_network.MockPublicIPAddressesClient, dns *mock_dns.MockManager) {
mocks: func(loadBalancers *mock_armnetwork.MockLoadBalancersClient, publicIPAddresses *mock_armnetwork.MockPublicIPAddressesClient, dns *mock_dns.MockManager) {
loadBalancers.EXPECT().
Get(gomock.Any(), "clusterResourceGroup", "infra-internal", "").
Return(mgmtnetwork.LoadBalancer{
LoadBalancerPropertiesFormat: &mgmtnetwork.LoadBalancerPropertiesFormat{
FrontendIPConfigurations: &[]mgmtnetwork.FrontendIPConfiguration{
{
FrontendIPConfigurationPropertiesFormat: &mgmtnetwork.FrontendIPConfigurationPropertiesFormat{
PrivateIPAddress: to.StringPtr("10.0.0.1"),
Get(gomock.Any(), "clusterResourceGroup", "infra-internal", nil).
Return(armnetwork.LoadBalancersClientGetResponse{
LoadBalancer: armnetwork.LoadBalancer{
Properties: &armnetwork.LoadBalancerPropertiesFormat{
FrontendIPConfigurations: []*armnetwork.FrontendIPConfiguration{
{
Properties: &armnetwork.FrontendIPConfigurationPropertiesFormat{
PrivateIPAddress: to.StringPtr(privateIP),
},
},
},
},
},
}, nil)
publicIPAddresses.EXPECT().
Get(gomock.Any(), "clusterResourceGroup", "infra-pip-v4", "").
Return(mgmtnetwork.PublicIPAddress{
PublicIPAddressPropertiesFormat: &mgmtnetwork.PublicIPAddressPropertiesFormat{
IPAddress: to.StringPtr("1.2.3.4"),
Get(gomock.Any(), "clusterResourceGroup", "infra-pip-v4", nil).
Return(armnetwork.PublicIPAddressesClientGetResponse{
PublicIPAddress: armnetwork.PublicIPAddress{
Properties: &armnetwork.PublicIPAddressPropertiesFormat{
IPAddress: to.StringPtr(publicIP),
},
},
}, nil)
dns.EXPECT().
Update(gomock.Any(), gomock.Any(), gomock.Any()).
Update(gomock.Any(), gomock.Any(), publicIP).
Return(nil)
},
},
@ -617,26 +628,28 @@ func TestUpdateAPIIPEarly(t *testing.T) {
fixture.AddOpenShiftClusterDocuments(doc)
doc.Dequeues = 1
doc.OpenShiftCluster.Properties.APIServerProfile.IP = "10.0.0.1"
doc.OpenShiftCluster.Properties.APIServerProfile.IntIP = "10.0.0.1"
doc.OpenShiftCluster.Properties.APIServerProfile.IP = privateIP
doc.OpenShiftCluster.Properties.APIServerProfile.IntIP = privateIP
checker.AddOpenShiftClusterDocuments(doc)
},
mocks: func(loadBalancers *mock_network.MockLoadBalancersClient, publicIPAddresses *mock_network.MockPublicIPAddressesClient, dns *mock_dns.MockManager) {
mocks: func(loadBalancers *mock_armnetwork.MockLoadBalancersClient, publicIPAddresses *mock_armnetwork.MockPublicIPAddressesClient, dns *mock_dns.MockManager) {
loadBalancers.EXPECT().
Get(gomock.Any(), "clusterResourceGroup", "infra-internal", "").
Return(mgmtnetwork.LoadBalancer{
LoadBalancerPropertiesFormat: &mgmtnetwork.LoadBalancerPropertiesFormat{
FrontendIPConfigurations: &[]mgmtnetwork.FrontendIPConfiguration{
{
FrontendIPConfigurationPropertiesFormat: &mgmtnetwork.FrontendIPConfigurationPropertiesFormat{
PrivateIPAddress: to.StringPtr("10.0.0.1"),
Get(gomock.Any(), "clusterResourceGroup", "infra-internal", nil).
Return(armnetwork.LoadBalancersClientGetResponse{
LoadBalancer: armnetwork.LoadBalancer{
Properties: &armnetwork.LoadBalancerPropertiesFormat{
FrontendIPConfigurations: []*armnetwork.FrontendIPConfiguration{
{
Properties: &armnetwork.FrontendIPConfigurationPropertiesFormat{
PrivateIPAddress: to.StringPtr(privateIP),
},
},
},
},
},
}, nil)
dns.EXPECT().
Update(gomock.Any(), gomock.Any(), gomock.Any()).
Update(gomock.Any(), gomock.Any(), privateIP).
Return(nil)
},
},
@ -645,8 +658,8 @@ func TestUpdateAPIIPEarly(t *testing.T) {
controller := gomock.NewController(t)
defer controller.Finish()
loadBalancers := mock_network.NewMockLoadBalancersClient(controller)
publicIPAddresses := mock_network.NewMockPublicIPAddressesClient(controller)
loadBalancers := mock_armnetwork.NewMockLoadBalancersClient(controller)
publicIPAddresses := mock_armnetwork.NewMockPublicIPAddressesClient(controller)
dns := mock_dns.NewMockManager(controller)
if tt.mocks != nil {
tt.mocks(loadBalancers, publicIPAddresses, dns)
@ -671,11 +684,11 @@ func TestUpdateAPIIPEarly(t *testing.T) {
}
m := &manager{
doc: doc,
db: dbOpenShiftClusters,
publicIPAddresses: publicIPAddresses,
loadBalancers: loadBalancers,
dns: dns,
doc: doc,
db: dbOpenShiftClusters,
armPublicIPAddresses: publicIPAddresses,
armLoadBalancers: loadBalancers,
dns: dns,
}
err = m.updateAPIIPEarly(ctx)
@ -706,7 +719,7 @@ func TestEnsureGatewayCreate(t *testing.T) {
},
{
name: "noop: IP set",
gatewayPrivateEndpointIP: "1.2.3.4",
gatewayPrivateEndpointIP: privateIP,
},
{
name: "error: private endpoint connection not found",
@ -720,7 +733,7 @@ func TestEnsureGatewayCreate(t *testing.T) {
IPConfigurations: &[]mgmtnetwork.InterfaceIPConfiguration{
{
InterfaceIPConfigurationPropertiesFormat: &mgmtnetwork.InterfaceIPConfigurationPropertiesFormat{
PrivateIPAddress: to.StringPtr("1.2.3.4"),
PrivateIPAddress: to.StringPtr(privateIP),
},
},
},
@ -751,7 +764,7 @@ func TestEnsureGatewayCreate(t *testing.T) {
IPConfigurations: &[]mgmtnetwork.InterfaceIPConfiguration{
{
InterfaceIPConfigurationPropertiesFormat: &mgmtnetwork.InterfaceIPConfigurationPropertiesFormat{
PrivateIPAddress: to.StringPtr("1.2.3.4"),
PrivateIPAddress: to.StringPtr(privateIP),
},
},
},
@ -815,7 +828,7 @@ func TestEnsureGatewayCreate(t *testing.T) {
ID: resourceID,
Properties: api.OpenShiftClusterProperties{
NetworkProfile: api.NetworkProfile{
GatewayPrivateEndpointIP: "1.2.3.4",
GatewayPrivateEndpointIP: privateIP,
GatewayPrivateLinkID: "1234",
},
},