зеркало из https://github.com/Azure/ARO-RP.git
SDK2: Replace old SDK in reconcile load balancer profile (#3923)
* migrate network sdk2 in loadbalancerprofile * refactor comments * fix "Could not find member 'Etag' on object of type 'TemplateResource'" error
This commit is contained in:
Родитель
a0ecfcfb9a
Коммит
f22bef042e
|
@ -7,10 +7,12 @@ import (
|
|||
"fmt"
|
||||
"strings"
|
||||
|
||||
sdknetwork "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"
|
||||
mgmtauthorization "github.com/Azure/azure-sdk-for-go/services/preview/authorization/mgmt/2018-09-01-preview/authorization"
|
||||
mgmtstorage "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2021-09-01/storage"
|
||||
"github.com/Azure/go-autorest/autorest/to"
|
||||
"k8s.io/utils/ptr"
|
||||
|
||||
"github.com/Azure/ARO-RP/pkg/api"
|
||||
"github.com/Azure/ARO-RP/pkg/util/arm"
|
||||
|
@ -531,87 +533,87 @@ func (m *manager) networkInternalLoadBalancer(azureRegion string) *arm.Resource
|
|||
}
|
||||
|
||||
func (m *manager) networkPublicLoadBalancer(azureRegion string, outboundIPs []api.ResourceReference) *arm.Resource {
|
||||
lb := &mgmtnetwork.LoadBalancer{
|
||||
Sku: &mgmtnetwork.LoadBalancerSku{
|
||||
Name: mgmtnetwork.LoadBalancerSkuNameStandard,
|
||||
lb := &sdknetwork.LoadBalancer{
|
||||
SKU: &sdknetwork.LoadBalancerSKU{
|
||||
Name: ptr.To(sdknetwork.LoadBalancerSKUNameStandard),
|
||||
},
|
||||
LoadBalancerPropertiesFormat: &mgmtnetwork.LoadBalancerPropertiesFormat{
|
||||
FrontendIPConfigurations: &[]mgmtnetwork.FrontendIPConfiguration{},
|
||||
BackendAddressPools: &[]mgmtnetwork.BackendAddressPool{
|
||||
Properties: &sdknetwork.LoadBalancerPropertiesFormat{
|
||||
FrontendIPConfigurations: []*sdknetwork.FrontendIPConfiguration{},
|
||||
BackendAddressPools: []*sdknetwork.BackendAddressPool{
|
||||
{
|
||||
Name: to.StringPtr(m.doc.OpenShiftCluster.Properties.InfraID),
|
||||
Name: ptr.To(m.doc.OpenShiftCluster.Properties.InfraID),
|
||||
},
|
||||
},
|
||||
LoadBalancingRules: &[]mgmtnetwork.LoadBalancingRule{}, //required to override default LB rules for port 80 and 443
|
||||
Probes: &[]mgmtnetwork.Probe{}, //required to override default LB rules for port 80 and 443
|
||||
OutboundRules: &[]mgmtnetwork.OutboundRule{
|
||||
LoadBalancingRules: []*sdknetwork.LoadBalancingRule{}, //required to override default LB rules for port 80 and 443
|
||||
Probes: []*sdknetwork.Probe{}, //required to override default LB rules for port 80 and 443
|
||||
OutboundRules: []*sdknetwork.OutboundRule{
|
||||
{
|
||||
OutboundRulePropertiesFormat: &mgmtnetwork.OutboundRulePropertiesFormat{
|
||||
FrontendIPConfigurations: &[]mgmtnetwork.SubResource{},
|
||||
BackendAddressPool: &mgmtnetwork.SubResource{
|
||||
ID: to.StringPtr(fmt.Sprintf("[resourceId('Microsoft.Network/loadBalancers/backendAddressPools', '%s', '%[1]s')]", m.doc.OpenShiftCluster.Properties.InfraID)),
|
||||
Properties: &sdknetwork.OutboundRulePropertiesFormat{
|
||||
FrontendIPConfigurations: []*sdknetwork.SubResource{},
|
||||
BackendAddressPool: &sdknetwork.SubResource{
|
||||
ID: ptr.To(fmt.Sprintf("[resourceId('Microsoft.Network/loadBalancers/backendAddressPools', '%s', '%[1]s')]", m.doc.OpenShiftCluster.Properties.InfraID)),
|
||||
},
|
||||
Protocol: mgmtnetwork.LoadBalancerOutboundRuleProtocolAll,
|
||||
IdleTimeoutInMinutes: to.Int32Ptr(30),
|
||||
Protocol: ptr.To(sdknetwork.LoadBalancerOutboundRuleProtocolAll),
|
||||
IdleTimeoutInMinutes: ptr.To(int32(30)),
|
||||
},
|
||||
Name: to.StringPtr("outbound-rule-v4"),
|
||||
Name: ptr.To("outbound-rule-v4"),
|
||||
},
|
||||
},
|
||||
},
|
||||
Name: &m.doc.OpenShiftCluster.Properties.InfraID,
|
||||
Type: to.StringPtr("Microsoft.Network/loadBalancers"),
|
||||
Type: ptr.To("Microsoft.Network/loadBalancers"),
|
||||
Location: &azureRegion,
|
||||
}
|
||||
|
||||
if m.doc.OpenShiftCluster.Properties.APIServerProfile.Visibility == api.VisibilityPublic {
|
||||
*lb.FrontendIPConfigurations = append(*lb.FrontendIPConfigurations, mgmtnetwork.FrontendIPConfiguration{
|
||||
FrontendIPConfigurationPropertiesFormat: &mgmtnetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
PublicIPAddress: &mgmtnetwork.PublicIPAddress{
|
||||
ID: to.StringPtr("[resourceId('Microsoft.Network/publicIPAddresses', '" + m.doc.OpenShiftCluster.Properties.InfraID + "-pip-v4')]"),
|
||||
lb.Properties.FrontendIPConfigurations = append(lb.Properties.FrontendIPConfigurations, &sdknetwork.FrontendIPConfiguration{
|
||||
Properties: &sdknetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
PublicIPAddress: &sdknetwork.PublicIPAddress{
|
||||
ID: ptr.To("[resourceId('Microsoft.Network/publicIPAddresses', '" + m.doc.OpenShiftCluster.Properties.InfraID + "-pip-v4')]"),
|
||||
},
|
||||
},
|
||||
Name: to.StringPtr("public-lb-ip-v4"),
|
||||
Name: ptr.To("public-lb-ip-v4"),
|
||||
})
|
||||
|
||||
*lb.LoadBalancingRules = append(*lb.LoadBalancingRules, mgmtnetwork.LoadBalancingRule{
|
||||
LoadBalancingRulePropertiesFormat: &mgmtnetwork.LoadBalancingRulePropertiesFormat{
|
||||
FrontendIPConfiguration: &mgmtnetwork.SubResource{
|
||||
ID: to.StringPtr(fmt.Sprintf("[resourceId('Microsoft.Network/loadBalancers/frontendIPConfigurations', '%s', 'public-lb-ip-v4')]", m.doc.OpenShiftCluster.Properties.InfraID)),
|
||||
lb.Properties.LoadBalancingRules = append(lb.Properties.LoadBalancingRules, &sdknetwork.LoadBalancingRule{
|
||||
Properties: &sdknetwork.LoadBalancingRulePropertiesFormat{
|
||||
FrontendIPConfiguration: &sdknetwork.SubResource{
|
||||
ID: ptr.To(fmt.Sprintf("[resourceId('Microsoft.Network/loadBalancers/frontendIPConfigurations', '%s', 'public-lb-ip-v4')]", m.doc.OpenShiftCluster.Properties.InfraID)),
|
||||
},
|
||||
BackendAddressPool: &mgmtnetwork.SubResource{
|
||||
ID: to.StringPtr(fmt.Sprintf("[resourceId('Microsoft.Network/loadBalancers/backendAddressPools', '%s', '%[1]s')]", m.doc.OpenShiftCluster.Properties.InfraID)),
|
||||
BackendAddressPool: &sdknetwork.SubResource{
|
||||
ID: ptr.To(fmt.Sprintf("[resourceId('Microsoft.Network/loadBalancers/backendAddressPools', '%s', '%[1]s')]", m.doc.OpenShiftCluster.Properties.InfraID)),
|
||||
},
|
||||
Probe: &mgmtnetwork.SubResource{
|
||||
ID: to.StringPtr(fmt.Sprintf("[resourceId('Microsoft.Network/loadBalancers/probes', '%s', 'api-internal-probe')]", m.doc.OpenShiftCluster.Properties.InfraID)),
|
||||
Probe: &sdknetwork.SubResource{
|
||||
ID: ptr.To(fmt.Sprintf("[resourceId('Microsoft.Network/loadBalancers/probes', '%s', 'api-internal-probe')]", m.doc.OpenShiftCluster.Properties.InfraID)),
|
||||
},
|
||||
Protocol: mgmtnetwork.TransportProtocolTCP,
|
||||
LoadDistribution: mgmtnetwork.LoadDistributionDefault,
|
||||
FrontendPort: to.Int32Ptr(6443),
|
||||
BackendPort: to.Int32Ptr(6443),
|
||||
IdleTimeoutInMinutes: to.Int32Ptr(30),
|
||||
DisableOutboundSnat: to.BoolPtr(true),
|
||||
Protocol: ptr.To(sdknetwork.TransportProtocolTCP),
|
||||
LoadDistribution: ptr.To(sdknetwork.LoadDistributionDefault),
|
||||
FrontendPort: ptr.To(int32(6443)),
|
||||
BackendPort: ptr.To(int32(6443)),
|
||||
IdleTimeoutInMinutes: ptr.To(int32(30)),
|
||||
DisableOutboundSnat: ptr.To(true),
|
||||
},
|
||||
Name: to.StringPtr("api-internal-v4"),
|
||||
Name: ptr.To("api-internal-v4"),
|
||||
})
|
||||
|
||||
*lb.Probes = append(*lb.Probes, mgmtnetwork.Probe{
|
||||
ProbePropertiesFormat: &mgmtnetwork.ProbePropertiesFormat{
|
||||
Protocol: mgmtnetwork.ProbeProtocolHTTPS,
|
||||
Port: to.Int32Ptr(6443),
|
||||
IntervalInSeconds: to.Int32Ptr(5),
|
||||
NumberOfProbes: to.Int32Ptr(2),
|
||||
RequestPath: to.StringPtr("/readyz"),
|
||||
lb.Properties.Probes = append(lb.Properties.Probes, &sdknetwork.Probe{
|
||||
Properties: &sdknetwork.ProbePropertiesFormat{
|
||||
Protocol: ptr.To(sdknetwork.ProbeProtocolHTTPS),
|
||||
Port: ptr.To(int32(6443)),
|
||||
IntervalInSeconds: ptr.To(int32(5)),
|
||||
NumberOfProbes: ptr.To(int32(2)),
|
||||
RequestPath: ptr.To("/readyz"),
|
||||
},
|
||||
Name: to.StringPtr("api-internal-probe"),
|
||||
Name: ptr.To("api-internal-probe"),
|
||||
})
|
||||
}
|
||||
|
||||
if m.doc.OpenShiftCluster.Properties.NetworkProfile.LoadBalancerProfile.ManagedOutboundIPs != nil {
|
||||
for i := len(*lb.FrontendIPConfigurations); i < m.doc.OpenShiftCluster.Properties.NetworkProfile.LoadBalancerProfile.ManagedOutboundIPs.Count; i++ {
|
||||
for i := len(lb.Properties.FrontendIPConfigurations); i < m.doc.OpenShiftCluster.Properties.NetworkProfile.LoadBalancerProfile.ManagedOutboundIPs.Count; i++ {
|
||||
resourceGroupID := m.doc.OpenShiftCluster.Properties.ClusterProfile.ResourceGroupID
|
||||
frontendIPConfigName := stringutils.LastTokenByte(outboundIPs[i].ID, '/')
|
||||
frontendConfigID := fmt.Sprintf("%s/providers/Microsoft.Network/loadBalancers/%s/frontendIPConfigurations/%s", resourceGroupID, *lb.Name, frontendIPConfigName)
|
||||
*lb.FrontendIPConfigurations = append(*lb.FrontendIPConfigurations, newFrontendIPConfig(frontendIPConfigName, frontendConfigID, outboundIPs[i].ID))
|
||||
lb.Properties.FrontendIPConfigurations = append(lb.Properties.FrontendIPConfigurations, newFrontendIPConfig(frontendIPConfigName, frontendConfigID, outboundIPs[i].ID))
|
||||
}
|
||||
|
||||
for i := 0; i < m.doc.OpenShiftCluster.Properties.NetworkProfile.LoadBalancerProfile.ManagedOutboundIPs.Count; i++ {
|
||||
|
@ -619,12 +621,12 @@ func (m *manager) networkPublicLoadBalancer(azureRegion string, outboundIPs []ap
|
|||
if i == 0 && m.doc.OpenShiftCluster.Properties.APIServerProfile.Visibility == api.VisibilityPublic {
|
||||
frontendIPConfigName := "public-lb-ip-v4"
|
||||
frontendConfigID := fmt.Sprintf("%s/providers/Microsoft.Network/loadBalancers/%s/frontendIPConfigurations/%s", resourceGroupID, *lb.Name, frontendIPConfigName)
|
||||
*(*lb.OutboundRules)[0].FrontendIPConfigurations = append(*(*lb.OutboundRules)[0].FrontendIPConfigurations, newOutboundRuleFrontendIPConfig(frontendConfigID))
|
||||
lb.Properties.OutboundRules[0].Properties.FrontendIPConfigurations = append(lb.Properties.OutboundRules[0].Properties.FrontendIPConfigurations, newOutboundRuleFrontendIPConfig(frontendConfigID))
|
||||
continue
|
||||
}
|
||||
frontendIPConfigName := stringutils.LastTokenByte(outboundIPs[i].ID, '/')
|
||||
frontendConfigID := fmt.Sprintf("%s/providers/Microsoft.Network/loadBalancers/%s/frontendIPConfigurations/%s", resourceGroupID, *lb.Name, frontendIPConfigName)
|
||||
*(*lb.OutboundRules)[0].FrontendIPConfigurations = append(*(*lb.OutboundRules)[0].FrontendIPConfigurations, newOutboundRuleFrontendIPConfig(frontendConfigID))
|
||||
lb.Properties.OutboundRules[0].Properties.FrontendIPConfigurations = append(lb.Properties.OutboundRules[0].Properties.FrontendIPConfigurations, newOutboundRuleFrontendIPConfig(frontendConfigID))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
sdknetwork "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v2"
|
||||
azstorage "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage"
|
||||
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
|
||||
mgmtnetwork "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-08-01/network"
|
||||
|
@ -906,40 +907,40 @@ func TestNewPublicLoadBalancer(t *testing.T) {
|
|||
APIVersion: azureclient.APIVersion("Microsoft.Network"),
|
||||
},
|
||||
{
|
||||
Resource: &mgmtnetwork.LoadBalancer{
|
||||
Sku: &mgmtnetwork.LoadBalancerSku{
|
||||
Name: mgmtnetwork.LoadBalancerSkuNameStandard,
|
||||
Resource: &sdknetwork.LoadBalancer{
|
||||
SKU: &sdknetwork.LoadBalancerSKU{
|
||||
Name: ptr.To(sdknetwork.LoadBalancerSKUNameStandard),
|
||||
},
|
||||
LoadBalancerPropertiesFormat: &mgmtnetwork.LoadBalancerPropertiesFormat{
|
||||
FrontendIPConfigurations: &[]mgmtnetwork.FrontendIPConfiguration{
|
||||
Properties: &sdknetwork.LoadBalancerPropertiesFormat{
|
||||
FrontendIPConfigurations: []*sdknetwork.FrontendIPConfiguration{
|
||||
{
|
||||
FrontendIPConfigurationPropertiesFormat: &mgmtnetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
PublicIPAddress: &mgmtnetwork.PublicIPAddress{
|
||||
Properties: &sdknetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
PublicIPAddress: &sdknetwork.PublicIPAddress{
|
||||
ID: to.StringPtr("[resourceId('Microsoft.Network/publicIPAddresses', '" + infraID + "-pip-v4')]"),
|
||||
},
|
||||
},
|
||||
Name: to.StringPtr("public-lb-ip-v4"),
|
||||
},
|
||||
},
|
||||
BackendAddressPools: &[]mgmtnetwork.BackendAddressPool{
|
||||
BackendAddressPools: []*sdknetwork.BackendAddressPool{
|
||||
{
|
||||
Name: to.StringPtr(infraID),
|
||||
},
|
||||
},
|
||||
LoadBalancingRules: &[]mgmtnetwork.LoadBalancingRule{
|
||||
LoadBalancingRules: []*sdknetwork.LoadBalancingRule{
|
||||
{
|
||||
LoadBalancingRulePropertiesFormat: &mgmtnetwork.LoadBalancingRulePropertiesFormat{
|
||||
FrontendIPConfiguration: &mgmtnetwork.SubResource{
|
||||
Properties: &sdknetwork.LoadBalancingRulePropertiesFormat{
|
||||
FrontendIPConfiguration: &sdknetwork.SubResource{
|
||||
ID: to.StringPtr(fmt.Sprintf("[resourceId('Microsoft.Network/loadBalancers/frontendIPConfigurations', '%s', 'public-lb-ip-v4')]", infraID)),
|
||||
},
|
||||
BackendAddressPool: &mgmtnetwork.SubResource{
|
||||
BackendAddressPool: &sdknetwork.SubResource{
|
||||
ID: to.StringPtr(fmt.Sprintf("[resourceId('Microsoft.Network/loadBalancers/backendAddressPools', '%s', '%[1]s')]", infraID)),
|
||||
},
|
||||
Probe: &mgmtnetwork.SubResource{
|
||||
Probe: &sdknetwork.SubResource{
|
||||
ID: to.StringPtr(fmt.Sprintf("[resourceId('Microsoft.Network/loadBalancers/probes', '%s', 'api-internal-probe')]", infraID)),
|
||||
},
|
||||
Protocol: mgmtnetwork.TransportProtocolTCP,
|
||||
LoadDistribution: mgmtnetwork.LoadDistributionDefault,
|
||||
Protocol: ptr.To(sdknetwork.TransportProtocolTCP),
|
||||
LoadDistribution: ptr.To(sdknetwork.LoadDistributionDefault),
|
||||
FrontendPort: to.Int32Ptr(6443),
|
||||
BackendPort: to.Int32Ptr(6443),
|
||||
IdleTimeoutInMinutes: to.Int32Ptr(30),
|
||||
|
@ -948,10 +949,10 @@ func TestNewPublicLoadBalancer(t *testing.T) {
|
|||
Name: to.StringPtr("api-internal-v4"),
|
||||
},
|
||||
},
|
||||
Probes: &[]mgmtnetwork.Probe{
|
||||
Probes: []*sdknetwork.Probe{
|
||||
{
|
||||
ProbePropertiesFormat: &mgmtnetwork.ProbePropertiesFormat{
|
||||
Protocol: mgmtnetwork.ProbeProtocolHTTPS,
|
||||
Properties: &sdknetwork.ProbePropertiesFormat{
|
||||
Protocol: ptr.To(sdknetwork.ProbeProtocolHTTPS),
|
||||
Port: to.Int32Ptr(6443),
|
||||
IntervalInSeconds: to.Int32Ptr(5),
|
||||
NumberOfProbes: to.Int32Ptr(2),
|
||||
|
@ -960,18 +961,18 @@ func TestNewPublicLoadBalancer(t *testing.T) {
|
|||
Name: to.StringPtr("api-internal-probe"),
|
||||
},
|
||||
},
|
||||
OutboundRules: &[]mgmtnetwork.OutboundRule{
|
||||
OutboundRules: []*sdknetwork.OutboundRule{
|
||||
{
|
||||
OutboundRulePropertiesFormat: &mgmtnetwork.OutboundRulePropertiesFormat{
|
||||
FrontendIPConfigurations: &[]mgmtnetwork.SubResource{
|
||||
Properties: &sdknetwork.OutboundRulePropertiesFormat{
|
||||
FrontendIPConfigurations: []*sdknetwork.SubResource{
|
||||
{
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/public-lb-ip-v4"),
|
||||
},
|
||||
},
|
||||
BackendAddressPool: &mgmtnetwork.SubResource{
|
||||
BackendAddressPool: &sdknetwork.SubResource{
|
||||
ID: to.StringPtr(fmt.Sprintf("[resourceId('Microsoft.Network/loadBalancers/backendAddressPools', '%s', '%[1]s')]", infraID)),
|
||||
},
|
||||
Protocol: mgmtnetwork.LoadBalancerOutboundRuleProtocolAll,
|
||||
Protocol: ptr.To(sdknetwork.LoadBalancerOutboundRuleProtocolAll),
|
||||
IdleTimeoutInMinutes: to.Int32Ptr(30),
|
||||
},
|
||||
Name: to.StringPtr("outbound-rule-v4"),
|
||||
|
@ -1054,15 +1055,15 @@ func TestNewPublicLoadBalancer(t *testing.T) {
|
|||
APIVersion: azureclient.APIVersion("Microsoft.Network"),
|
||||
},
|
||||
{
|
||||
Resource: &mgmtnetwork.LoadBalancer{
|
||||
Sku: &mgmtnetwork.LoadBalancerSku{
|
||||
Name: mgmtnetwork.LoadBalancerSkuNameStandard,
|
||||
Resource: &sdknetwork.LoadBalancer{
|
||||
SKU: &sdknetwork.LoadBalancerSKU{
|
||||
Name: ptr.To(sdknetwork.LoadBalancerSKUNameStandard),
|
||||
},
|
||||
LoadBalancerPropertiesFormat: &mgmtnetwork.LoadBalancerPropertiesFormat{
|
||||
FrontendIPConfigurations: &[]mgmtnetwork.FrontendIPConfiguration{
|
||||
Properties: &sdknetwork.LoadBalancerPropertiesFormat{
|
||||
FrontendIPConfigurations: []*sdknetwork.FrontendIPConfiguration{
|
||||
{
|
||||
FrontendIPConfigurationPropertiesFormat: &mgmtnetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
PublicIPAddress: &mgmtnetwork.PublicIPAddress{
|
||||
Properties: &sdknetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
PublicIPAddress: &sdknetwork.PublicIPAddress{
|
||||
ID: to.StringPtr("[resourceId('Microsoft.Network/publicIPAddresses', '" + infraID + "-pip-v4')]"),
|
||||
},
|
||||
},
|
||||
|
@ -1070,33 +1071,33 @@ func TestNewPublicLoadBalancer(t *testing.T) {
|
|||
},
|
||||
{
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/uuid1-outbound-pip-v4"),
|
||||
FrontendIPConfigurationPropertiesFormat: &mgmtnetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
PublicIPAddress: &mgmtnetwork.PublicIPAddress{
|
||||
Properties: &sdknetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
PublicIPAddress: &sdknetwork.PublicIPAddress{
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/publicIPAddresses/uuid1-outbound-pip-v4"),
|
||||
},
|
||||
},
|
||||
Name: to.StringPtr("uuid1-outbound-pip-v4"),
|
||||
},
|
||||
},
|
||||
BackendAddressPools: &[]mgmtnetwork.BackendAddressPool{
|
||||
BackendAddressPools: []*sdknetwork.BackendAddressPool{
|
||||
{
|
||||
Name: to.StringPtr(infraID),
|
||||
},
|
||||
},
|
||||
LoadBalancingRules: &[]mgmtnetwork.LoadBalancingRule{
|
||||
LoadBalancingRules: []*sdknetwork.LoadBalancingRule{
|
||||
{
|
||||
LoadBalancingRulePropertiesFormat: &mgmtnetwork.LoadBalancingRulePropertiesFormat{
|
||||
FrontendIPConfiguration: &mgmtnetwork.SubResource{
|
||||
Properties: &sdknetwork.LoadBalancingRulePropertiesFormat{
|
||||
FrontendIPConfiguration: &sdknetwork.SubResource{
|
||||
ID: to.StringPtr(fmt.Sprintf("[resourceId('Microsoft.Network/loadBalancers/frontendIPConfigurations', '%s', 'public-lb-ip-v4')]", infraID)),
|
||||
},
|
||||
BackendAddressPool: &mgmtnetwork.SubResource{
|
||||
BackendAddressPool: &sdknetwork.SubResource{
|
||||
ID: to.StringPtr(fmt.Sprintf("[resourceId('Microsoft.Network/loadBalancers/backendAddressPools', '%s', '%[1]s')]", infraID)),
|
||||
},
|
||||
Probe: &mgmtnetwork.SubResource{
|
||||
Probe: &sdknetwork.SubResource{
|
||||
ID: to.StringPtr(fmt.Sprintf("[resourceId('Microsoft.Network/loadBalancers/probes', '%s', 'api-internal-probe')]", infraID)),
|
||||
},
|
||||
Protocol: mgmtnetwork.TransportProtocolTCP,
|
||||
LoadDistribution: mgmtnetwork.LoadDistributionDefault,
|
||||
Protocol: ptr.To(sdknetwork.TransportProtocolTCP),
|
||||
LoadDistribution: ptr.To(sdknetwork.LoadDistributionDefault),
|
||||
FrontendPort: to.Int32Ptr(6443),
|
||||
BackendPort: to.Int32Ptr(6443),
|
||||
IdleTimeoutInMinutes: to.Int32Ptr(30),
|
||||
|
@ -1105,10 +1106,10 @@ func TestNewPublicLoadBalancer(t *testing.T) {
|
|||
Name: to.StringPtr("api-internal-v4"),
|
||||
},
|
||||
},
|
||||
Probes: &[]mgmtnetwork.Probe{
|
||||
Probes: []*sdknetwork.Probe{
|
||||
{
|
||||
ProbePropertiesFormat: &mgmtnetwork.ProbePropertiesFormat{
|
||||
Protocol: mgmtnetwork.ProbeProtocolHTTPS,
|
||||
Properties: &sdknetwork.ProbePropertiesFormat{
|
||||
Protocol: ptr.To(sdknetwork.ProbeProtocolHTTPS),
|
||||
Port: to.Int32Ptr(6443),
|
||||
IntervalInSeconds: to.Int32Ptr(5),
|
||||
NumberOfProbes: to.Int32Ptr(2),
|
||||
|
@ -1117,10 +1118,10 @@ func TestNewPublicLoadBalancer(t *testing.T) {
|
|||
Name: to.StringPtr("api-internal-probe"),
|
||||
},
|
||||
},
|
||||
OutboundRules: &[]mgmtnetwork.OutboundRule{
|
||||
OutboundRules: []*sdknetwork.OutboundRule{
|
||||
{
|
||||
OutboundRulePropertiesFormat: &mgmtnetwork.OutboundRulePropertiesFormat{
|
||||
FrontendIPConfigurations: &[]mgmtnetwork.SubResource{
|
||||
Properties: &sdknetwork.OutboundRulePropertiesFormat{
|
||||
FrontendIPConfigurations: []*sdknetwork.SubResource{
|
||||
{
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/public-lb-ip-v4"),
|
||||
},
|
||||
|
@ -1128,10 +1129,10 @@ func TestNewPublicLoadBalancer(t *testing.T) {
|
|||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/uuid1-outbound-pip-v4"),
|
||||
},
|
||||
},
|
||||
BackendAddressPool: &mgmtnetwork.SubResource{
|
||||
BackendAddressPool: &sdknetwork.SubResource{
|
||||
ID: to.StringPtr(fmt.Sprintf("[resourceId('Microsoft.Network/loadBalancers/backendAddressPools', '%s', '%[1]s')]", infraID)),
|
||||
},
|
||||
Protocol: mgmtnetwork.LoadBalancerOutboundRuleProtocolAll,
|
||||
Protocol: ptr.To(sdknetwork.LoadBalancerOutboundRuleProtocolAll),
|
||||
IdleTimeoutInMinutes: to.Int32Ptr(30),
|
||||
},
|
||||
Name: to.StringPtr("outbound-rule-v4"),
|
||||
|
@ -1201,41 +1202,41 @@ func TestNewPublicLoadBalancer(t *testing.T) {
|
|||
APIVersion: azureclient.APIVersion("Microsoft.Network"),
|
||||
},
|
||||
{
|
||||
Resource: &mgmtnetwork.LoadBalancer{
|
||||
Sku: &mgmtnetwork.LoadBalancerSku{
|
||||
Name: mgmtnetwork.LoadBalancerSkuNameStandard,
|
||||
Resource: &sdknetwork.LoadBalancer{
|
||||
SKU: &sdknetwork.LoadBalancerSKU{
|
||||
Name: ptr.To(sdknetwork.LoadBalancerSKUNameStandard),
|
||||
},
|
||||
LoadBalancerPropertiesFormat: &mgmtnetwork.LoadBalancerPropertiesFormat{
|
||||
FrontendIPConfigurations: &[]mgmtnetwork.FrontendIPConfiguration{
|
||||
Properties: &sdknetwork.LoadBalancerPropertiesFormat{
|
||||
FrontendIPConfigurations: []*sdknetwork.FrontendIPConfiguration{
|
||||
{
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/uuid1-outbound-pip-v4"),
|
||||
FrontendIPConfigurationPropertiesFormat: &mgmtnetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
PublicIPAddress: &mgmtnetwork.PublicIPAddress{
|
||||
Properties: &sdknetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
PublicIPAddress: &sdknetwork.PublicIPAddress{
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/publicIPAddresses/uuid1-outbound-pip-v4"),
|
||||
},
|
||||
},
|
||||
Name: to.StringPtr("uuid1-outbound-pip-v4"),
|
||||
},
|
||||
},
|
||||
BackendAddressPools: &[]mgmtnetwork.BackendAddressPool{
|
||||
BackendAddressPools: []*sdknetwork.BackendAddressPool{
|
||||
{
|
||||
Name: to.StringPtr(infraID),
|
||||
},
|
||||
},
|
||||
LoadBalancingRules: &[]mgmtnetwork.LoadBalancingRule{},
|
||||
Probes: &[]mgmtnetwork.Probe{},
|
||||
OutboundRules: &[]mgmtnetwork.OutboundRule{
|
||||
LoadBalancingRules: []*sdknetwork.LoadBalancingRule{},
|
||||
Probes: []*sdknetwork.Probe{},
|
||||
OutboundRules: []*sdknetwork.OutboundRule{
|
||||
{
|
||||
OutboundRulePropertiesFormat: &mgmtnetwork.OutboundRulePropertiesFormat{
|
||||
FrontendIPConfigurations: &[]mgmtnetwork.SubResource{
|
||||
Properties: &sdknetwork.OutboundRulePropertiesFormat{
|
||||
FrontendIPConfigurations: []*sdknetwork.SubResource{
|
||||
{
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/uuid1-outbound-pip-v4"),
|
||||
},
|
||||
},
|
||||
BackendAddressPool: &mgmtnetwork.SubResource{
|
||||
BackendAddressPool: &sdknetwork.SubResource{
|
||||
ID: to.StringPtr(fmt.Sprintf("[resourceId('Microsoft.Network/loadBalancers/backendAddressPools', '%s', '%[1]s')]", infraID)),
|
||||
},
|
||||
Protocol: mgmtnetwork.LoadBalancerOutboundRuleProtocolAll,
|
||||
Protocol: ptr.To(sdknetwork.LoadBalancerOutboundRuleProtocolAll),
|
||||
IdleTimeoutInMinutes: to.Int32Ptr(30),
|
||||
},
|
||||
Name: to.StringPtr("outbound-rule-v4"),
|
||||
|
@ -1318,16 +1319,16 @@ func TestNewPublicLoadBalancer(t *testing.T) {
|
|||
APIVersion: azureclient.APIVersion("Microsoft.Network"),
|
||||
},
|
||||
{
|
||||
Resource: &mgmtnetwork.LoadBalancer{
|
||||
Sku: &mgmtnetwork.LoadBalancerSku{
|
||||
Name: mgmtnetwork.LoadBalancerSkuNameStandard,
|
||||
Resource: &sdknetwork.LoadBalancer{
|
||||
SKU: &sdknetwork.LoadBalancerSKU{
|
||||
Name: ptr.To(sdknetwork.LoadBalancerSKUNameStandard),
|
||||
},
|
||||
LoadBalancerPropertiesFormat: &mgmtnetwork.LoadBalancerPropertiesFormat{
|
||||
FrontendIPConfigurations: &[]mgmtnetwork.FrontendIPConfiguration{
|
||||
Properties: &sdknetwork.LoadBalancerPropertiesFormat{
|
||||
FrontendIPConfigurations: []*sdknetwork.FrontendIPConfiguration{
|
||||
{
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/uuid1-outbound-pip-v4"),
|
||||
FrontendIPConfigurationPropertiesFormat: &mgmtnetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
PublicIPAddress: &mgmtnetwork.PublicIPAddress{
|
||||
Properties: &sdknetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
PublicIPAddress: &sdknetwork.PublicIPAddress{
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/publicIPAddresses/uuid1-outbound-pip-v4"),
|
||||
},
|
||||
},
|
||||
|
@ -1335,25 +1336,25 @@ func TestNewPublicLoadBalancer(t *testing.T) {
|
|||
},
|
||||
{
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/uuid2-outbound-pip-v4"),
|
||||
FrontendIPConfigurationPropertiesFormat: &mgmtnetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
PublicIPAddress: &mgmtnetwork.PublicIPAddress{
|
||||
Properties: &sdknetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
PublicIPAddress: &sdknetwork.PublicIPAddress{
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/publicIPAddresses/uuid2-outbound-pip-v4"),
|
||||
},
|
||||
},
|
||||
Name: to.StringPtr("uuid2-outbound-pip-v4"),
|
||||
},
|
||||
},
|
||||
BackendAddressPools: &[]mgmtnetwork.BackendAddressPool{
|
||||
BackendAddressPools: []*sdknetwork.BackendAddressPool{
|
||||
{
|
||||
Name: to.StringPtr(infraID),
|
||||
},
|
||||
},
|
||||
LoadBalancingRules: &[]mgmtnetwork.LoadBalancingRule{},
|
||||
Probes: &[]mgmtnetwork.Probe{},
|
||||
OutboundRules: &[]mgmtnetwork.OutboundRule{
|
||||
LoadBalancingRules: []*sdknetwork.LoadBalancingRule{},
|
||||
Probes: []*sdknetwork.Probe{},
|
||||
OutboundRules: []*sdknetwork.OutboundRule{
|
||||
{
|
||||
OutboundRulePropertiesFormat: &mgmtnetwork.OutboundRulePropertiesFormat{
|
||||
FrontendIPConfigurations: &[]mgmtnetwork.SubResource{
|
||||
Properties: &sdknetwork.OutboundRulePropertiesFormat{
|
||||
FrontendIPConfigurations: []*sdknetwork.SubResource{
|
||||
{
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/uuid1-outbound-pip-v4"),
|
||||
},
|
||||
|
@ -1361,10 +1362,10 @@ func TestNewPublicLoadBalancer(t *testing.T) {
|
|||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/uuid2-outbound-pip-v4"),
|
||||
},
|
||||
},
|
||||
BackendAddressPool: &mgmtnetwork.SubResource{
|
||||
BackendAddressPool: &sdknetwork.SubResource{
|
||||
ID: to.StringPtr(fmt.Sprintf("[resourceId('Microsoft.Network/loadBalancers/backendAddressPools', '%s', '%[1]s')]", infraID)),
|
||||
},
|
||||
Protocol: mgmtnetwork.LoadBalancerOutboundRuleProtocolAll,
|
||||
Protocol: ptr.To(sdknetwork.LoadBalancerOutboundRuleProtocolAll),
|
||||
IdleTimeoutInMinutes: to.Int32Ptr(30),
|
||||
},
|
||||
Name: to.StringPtr("outbound-rule-v4"),
|
||||
|
|
|
@ -10,7 +10,8 @@ import (
|
|||
"sort"
|
||||
"strings"
|
||||
|
||||
mgmtnetwork "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-08-01/network"
|
||||
sdknetwork "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v2"
|
||||
"k8s.io/utils/ptr"
|
||||
|
||||
"github.com/Azure/ARO-RP/pkg/api"
|
||||
"github.com/Azure/ARO-RP/pkg/util/stringutils"
|
||||
|
@ -25,10 +26,11 @@ type deleteIPResult struct {
|
|||
}
|
||||
|
||||
type createIPResult struct {
|
||||
ip mgmtnetwork.PublicIPAddress
|
||||
ip sdknetwork.PublicIPAddress
|
||||
err error
|
||||
}
|
||||
|
||||
// reconcileLoadBalancerProfile reconciles the outbound IPs of the public load balancer.
|
||||
func (m *manager) reconcileLoadBalancerProfile(ctx context.Context) error {
|
||||
if m.doc.OpenShiftCluster.Properties.NetworkProfile.OutboundType != api.OutboundTypeLoadbalancer || m.doc.OpenShiftCluster.Properties.ArchitectureVersion == api.ArchitectureVersionV1 {
|
||||
return nil
|
||||
|
@ -37,12 +39,12 @@ func (m *manager) reconcileLoadBalancerProfile(ctx context.Context) error {
|
|||
resourceGroupName := stringutils.LastTokenByte(m.doc.OpenShiftCluster.Properties.ClusterProfile.ResourceGroupID, '/')
|
||||
infraID := m.doc.OpenShiftCluster.Properties.InfraID
|
||||
|
||||
lb, err := m.loadBalancers.Get(ctx, resourceGroupName, infraID, "")
|
||||
lb, err := m.armLoadBalancers.Get(ctx, resourceGroupName, infraID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = m.reconcileOutboundRuleV4IPs(ctx, lb)
|
||||
err = m.reconcileOutboundRuleV4IPs(ctx, lb.LoadBalancer)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -50,7 +52,7 @@ func (m *manager) reconcileLoadBalancerProfile(ctx context.Context) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (m *manager) reconcileOutboundRuleV4IPs(ctx context.Context, lb mgmtnetwork.LoadBalancer) error {
|
||||
func (m *manager) reconcileOutboundRuleV4IPs(ctx context.Context, lb sdknetwork.LoadBalancer) error {
|
||||
err := m.reconcileOutboundRuleV4IPsInner(ctx, lb)
|
||||
|
||||
cleanupError := m.deleteUnusedManagedIPs(ctx)
|
||||
|
@ -64,7 +66,7 @@ func (m *manager) reconcileOutboundRuleV4IPs(ctx context.Context, lb mgmtnetwork
|
|||
return err
|
||||
}
|
||||
|
||||
func (m *manager) reconcileOutboundRuleV4IPsInner(ctx context.Context, lb mgmtnetwork.LoadBalancer) error {
|
||||
func (m *manager) reconcileOutboundRuleV4IPsInner(ctx context.Context, lb sdknetwork.LoadBalancer) error {
|
||||
m.log.Info("reconciling outbound-rule-v4")
|
||||
|
||||
resourceGroupName := stringutils.LastTokenByte(m.doc.OpenShiftCluster.Properties.ClusterProfile.ResourceGroupID, '/')
|
||||
|
@ -91,7 +93,7 @@ func (m *manager) reconcileOutboundRuleV4IPsInner(ctx context.Context, lb mgmtne
|
|||
removeOutboundIPsFromLB(lb)
|
||||
addOutboundIPsToLB(m.doc.OpenShiftCluster.Properties.ClusterProfile.ResourceGroupID, lb, desiredOutboundIPs)
|
||||
|
||||
err = m.loadBalancers.CreateOrUpdateAndWait(ctx, resourceGroupName, infraID, lb)
|
||||
err = m.armLoadBalancers.CreateOrUpdateAndWait(ctx, resourceGroupName, infraID, lb, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -105,36 +107,34 @@ func (m *manager) reconcileOutboundRuleV4IPsInner(ctx context.Context, lb mgmtne
|
|||
return nil
|
||||
}
|
||||
|
||||
// Remove outbound-rule-v4 IPs and corresponding frontendIPConfig from load balancer
|
||||
func removeOutboundIPsFromLB(lb mgmtnetwork.LoadBalancer) {
|
||||
// removeOutboundIPsFromLB removes outbound-rule-v4 IPs and corresponding frontendIPConfig from load balancer
|
||||
func removeOutboundIPsFromLB(lb sdknetwork.LoadBalancer) {
|
||||
removeOutboundRuleV4FrontendIPConfig(lb)
|
||||
setOutboundRuleV4(lb, []mgmtnetwork.SubResource{})
|
||||
setOutboundRuleV4(lb, []*sdknetwork.SubResource{})
|
||||
}
|
||||
|
||||
func removeOutboundRuleV4FrontendIPConfig(lb mgmtnetwork.LoadBalancer) {
|
||||
var savedFIPConfig = make([]mgmtnetwork.FrontendIPConfiguration, 0, len(*lb.LoadBalancerPropertiesFormat.FrontendIPConfigurations))
|
||||
func removeOutboundRuleV4FrontendIPConfig(lb sdknetwork.LoadBalancer) {
|
||||
var savedFIPConfig = make([]*sdknetwork.FrontendIPConfiguration, 0, len(lb.Properties.FrontendIPConfigurations))
|
||||
var outboundRuleFrontendConfig = getOutboundRuleV4FIPConfigs(lb)
|
||||
|
||||
for i := 0; i < len(*lb.LoadBalancerPropertiesFormat.FrontendIPConfigurations); i++ {
|
||||
fipConfigID := *(*lb.LoadBalancerPropertiesFormat.FrontendIPConfigurations)[i].ID
|
||||
fipConfig := (*lb.LoadBalancerPropertiesFormat.FrontendIPConfigurations)[i]
|
||||
hasLBRules := (*lb.LoadBalancerPropertiesFormat.FrontendIPConfigurations)[i].LoadBalancingRules != nil
|
||||
for _, fipConfig := range lb.Properties.FrontendIPConfigurations {
|
||||
fipConfigID := *fipConfig.ID
|
||||
hasLBRules := fipConfig.Properties.LoadBalancingRules != nil
|
||||
if _, ok := outboundRuleFrontendConfig[fipConfigID]; ok && !hasLBRules {
|
||||
continue
|
||||
}
|
||||
savedFIPConfig = append(savedFIPConfig, fipConfig)
|
||||
}
|
||||
lb.LoadBalancerPropertiesFormat.FrontendIPConfigurations = &savedFIPConfig
|
||||
lb.Properties.FrontendIPConfigurations = savedFIPConfig
|
||||
}
|
||||
|
||||
func getOutboundRuleV4FIPConfigs(lb mgmtnetwork.LoadBalancer) map[string]mgmtnetwork.SubResource {
|
||||
var obRuleV4FIPConfigs = make(map[string]mgmtnetwork.SubResource)
|
||||
for _, obRule := range *lb.LoadBalancerPropertiesFormat.OutboundRules {
|
||||
func getOutboundRuleV4FIPConfigs(lb sdknetwork.LoadBalancer) map[string]sdknetwork.SubResource {
|
||||
var obRuleV4FIPConfigs = make(map[string]sdknetwork.SubResource)
|
||||
for _, obRule := range lb.Properties.OutboundRules {
|
||||
if *obRule.Name == outboundRuleV4 {
|
||||
for i := 0; i < len(*obRule.OutboundRulePropertiesFormat.FrontendIPConfigurations); i++ {
|
||||
fipConfigID := *(*obRule.OutboundRulePropertiesFormat.FrontendIPConfigurations)[i].ID
|
||||
fipConfig := (*obRule.OutboundRulePropertiesFormat.FrontendIPConfigurations)[i]
|
||||
obRuleV4FIPConfigs[fipConfigID] = fipConfig
|
||||
for _, fipConfig := range obRule.Properties.FrontendIPConfigurations {
|
||||
fipConfigID := *fipConfig.ID
|
||||
obRuleV4FIPConfigs[fipConfigID] = *fipConfig
|
||||
}
|
||||
break
|
||||
}
|
||||
|
@ -142,25 +142,24 @@ func getOutboundRuleV4FIPConfigs(lb mgmtnetwork.LoadBalancer) map[string]mgmtnet
|
|||
return obRuleV4FIPConfigs
|
||||
}
|
||||
|
||||
// Returns a map of Frontend IP Configurations. Frontend IP Configurations can be looked up by Public IP Address ID or Frontend IP Configuration ID
|
||||
func getFrontendIPConfigs(lb mgmtnetwork.LoadBalancer) map[string]mgmtnetwork.FrontendIPConfiguration {
|
||||
var frontendIPConfigs = make(map[string]mgmtnetwork.FrontendIPConfiguration, len(*lb.LoadBalancerPropertiesFormat.FrontendIPConfigurations))
|
||||
// getFrontendIPConfigs returns a map of Frontend IP Configurations from the given load balancer
|
||||
func getFrontendIPConfigs(lb sdknetwork.LoadBalancer) map[string]sdknetwork.FrontendIPConfiguration {
|
||||
var frontendIPConfigs = make(map[string]sdknetwork.FrontendIPConfiguration, len(lb.Properties.FrontendIPConfigurations))
|
||||
|
||||
for i := 0; i < len(*lb.LoadBalancerPropertiesFormat.FrontendIPConfigurations); i++ {
|
||||
fipConfigID := *(*lb.LoadBalancerPropertiesFormat.FrontendIPConfigurations)[i].ID
|
||||
fipConfigIPAddressID := *(*lb.LoadBalancerPropertiesFormat.FrontendIPConfigurations)[i].FrontendIPConfigurationPropertiesFormat.PublicIPAddress.ID
|
||||
fipConfig := (*lb.LoadBalancerPropertiesFormat.FrontendIPConfigurations)[i]
|
||||
frontendIPConfigs[fipConfigID] = fipConfig
|
||||
frontendIPConfigs[fipConfigIPAddressID] = fipConfig
|
||||
for _, fipConfig := range lb.Properties.FrontendIPConfigurations {
|
||||
fipConfigID := *fipConfig.ID
|
||||
fipConfigIPAddressID := *fipConfig.Properties.PublicIPAddress.ID
|
||||
frontendIPConfigs[fipConfigID] = *fipConfig
|
||||
frontendIPConfigs[fipConfigIPAddressID] = *fipConfig
|
||||
}
|
||||
|
||||
return frontendIPConfigs
|
||||
}
|
||||
|
||||
// Adds IPs or IPPrefixes to the load balancer outbound rule "outbound-rule-v4".
|
||||
func addOutboundIPsToLB(resourceGroupID string, lb mgmtnetwork.LoadBalancer, obIPsOrIPPrefixes []api.ResourceReference) {
|
||||
// addOutboundIPsToLB adds IPs or IPPrefixes to the load balancer outbound rule "outbound-rule-v4".
|
||||
func addOutboundIPsToLB(resourceGroupID string, lb sdknetwork.LoadBalancer, obIPsOrIPPrefixes []api.ResourceReference) {
|
||||
frontendIPConfigs := getFrontendIPConfigs(lb)
|
||||
outboundRuleV4FrontendIPConfig := []mgmtnetwork.SubResource{}
|
||||
var outboundRuleV4FrontendIPConfig []*sdknetwork.SubResource
|
||||
|
||||
// add IP Addresses to frontendConfig
|
||||
for _, obIPOrIPPrefix := range obIPsOrIPPrefixes {
|
||||
|
@ -168,7 +167,7 @@ func addOutboundIPsToLB(resourceGroupID string, lb mgmtnetwork.LoadBalancer, obI
|
|||
if _, ok := frontendIPConfigs[obIPOrIPPrefix.ID]; !ok {
|
||||
frontendIPConfigName := stringutils.LastTokenByte(obIPOrIPPrefix.ID, '/')
|
||||
frontendConfigID := fmt.Sprintf("%s/providers/Microsoft.Network/loadBalancers/%s/frontendIPConfigurations/%s", resourceGroupID, *lb.Name, frontendIPConfigName)
|
||||
*lb.LoadBalancerPropertiesFormat.FrontendIPConfigurations = append(*lb.LoadBalancerPropertiesFormat.FrontendIPConfigurations, newFrontendIPConfig(frontendIPConfigName, frontendConfigID, obIPOrIPPrefix.ID))
|
||||
lb.Properties.FrontendIPConfigurations = append(lb.Properties.FrontendIPConfigurations, newFrontendIPConfig(frontendIPConfigName, frontendConfigID, obIPOrIPPrefix.ID))
|
||||
outboundRuleV4FrontendIPConfig = append(outboundRuleV4FrontendIPConfig, newOutboundRuleFrontendIPConfig(frontendConfigID))
|
||||
} else {
|
||||
// frontendIPConfig already exists and just needs to be added to the outbound rule
|
||||
|
@ -180,16 +179,16 @@ func addOutboundIPsToLB(resourceGroupID string, lb mgmtnetwork.LoadBalancer, obI
|
|||
setOutboundRuleV4(lb, outboundRuleV4FrontendIPConfig)
|
||||
}
|
||||
|
||||
func setOutboundRuleV4(lb mgmtnetwork.LoadBalancer, outboundRuleV4FrontendIPConfig []mgmtnetwork.SubResource) {
|
||||
for _, outboundRule := range *lb.LoadBalancerPropertiesFormat.OutboundRules {
|
||||
func setOutboundRuleV4(lb sdknetwork.LoadBalancer, outboundRuleV4FrontendIPConfig []*sdknetwork.SubResource) {
|
||||
for _, outboundRule := range lb.Properties.OutboundRules {
|
||||
if *outboundRule.Name == outboundRuleV4 {
|
||||
outboundRule.OutboundRulePropertiesFormat.FrontendIPConfigurations = &outboundRuleV4FrontendIPConfig
|
||||
outboundRule.Properties.FrontendIPConfigurations = outboundRuleV4FrontendIPConfig
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Delete all managed outbound IPs that are not in use by the load balancer.
|
||||
// deleteUnusedManagedIPs all managed outbound IPs that are not in use by the load balancer.
|
||||
// The default outbound ip is saved if the api server is public.
|
||||
func (m *manager) deleteUnusedManagedIPs(ctx context.Context) error {
|
||||
resourceGroupName := stringutils.LastTokenByte(m.doc.OpenShiftCluster.Properties.ClusterProfile.ResourceGroupID, '/')
|
||||
|
@ -224,7 +223,7 @@ func (m *manager) deleteUnusedManagedIPs(ctx context.Context) error {
|
|||
|
||||
func (m *manager) deleteIPAddress(ctx context.Context, resourceGroupName string, ipName string, ch chan<- deleteIPResult) {
|
||||
m.log.Infof("deleting managed public IP Address: %s", ipName)
|
||||
err := m.publicIPAddresses.DeleteAndWait(ctx, resourceGroupName, ipName)
|
||||
err := m.armPublicIPAddresses.DeleteAndWait(ctx, resourceGroupName, ipName, nil)
|
||||
ch <- deleteIPResult{
|
||||
name: ipName,
|
||||
err: err,
|
||||
|
@ -240,12 +239,12 @@ func (m *manager) getUnusedManagedIPs(ctx context.Context) ([]string, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
lb, err := m.loadBalancers.Get(ctx, resourceGroupName, infraID, "")
|
||||
lb, err := m.armLoadBalancers.Get(ctx, resourceGroupName, infraID, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
outboundIPs := getOutboundIPsFromLB(lb)
|
||||
outboundIPs := getOutboundIPsFromLB(lb.LoadBalancer)
|
||||
outboundIPMap := make(map[string]api.ResourceReference, len(outboundIPs))
|
||||
for i := 0; i < len(outboundIPs); i++ {
|
||||
outboundIPMap[strings.ToLower(outboundIPs[i].ID)] = outboundIPs[i]
|
||||
|
@ -263,8 +262,8 @@ func (m *manager) getUnusedManagedIPs(ctx context.Context) ([]string, error) {
|
|||
return unusedManagedIPs, nil
|
||||
}
|
||||
|
||||
// Returns the desired RP managed outbound publicIPAddresses. Additional Managed Outbound IPs
|
||||
// will be created as required to satisfy ManagedOutboundIP.Count.
|
||||
// reconcileOutboundIPs returns the desired RP managed outbound publicIPAddresses.
|
||||
// Additional Managed Outbound IPs will be created as required to satisfy ManagedOutboundIP.Count.
|
||||
func (m *manager) reconcileOutboundIPs(ctx context.Context) ([]api.ResourceReference, error) {
|
||||
// Determine source of outbound IPs
|
||||
// TODO: add customer provided ip and ip prefixes
|
||||
|
@ -274,7 +273,7 @@ func (m *manager) reconcileOutboundIPs(ctx context.Context) ([]api.ResourceRefer
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
// Returns RP managed outbound ips to be added to the outbound rule.
|
||||
// reconcileDesiredManagedIPs returns RP managed outbound ips to be added to the outbound rule.
|
||||
// If the default outbound IP is present it will be added to ensure reuse of the ip when the
|
||||
// api server is public. If additional IPs are required they will be created.
|
||||
func (m *manager) reconcileDesiredManagedIPs(ctx context.Context) ([]api.ResourceReference, error) {
|
||||
|
@ -299,9 +298,10 @@ func (m *manager) reconcileDesiredManagedIPs(ctx context.Context) ([]api.Resourc
|
|||
return desiredIPAddresses, nil
|
||||
}
|
||||
|
||||
func getDesiredOutboundIPs(managedOBIPCount int, ipAddresses map[string]mgmtnetwork.PublicIPAddress, infraID string) []api.ResourceReference {
|
||||
// getDesiredOutboundIPs returns the desired outbound IPs to be used by the load balancer.
|
||||
func getDesiredOutboundIPs(managedOBIPCount int, ipAddresses map[string]sdknetwork.PublicIPAddress, infraID string) []api.ResourceReference {
|
||||
desiredIPAddresses := make([]api.ResourceReference, 0, managedOBIPCount)
|
||||
// ensure that when scaling managed ips down the default outbound IP is reused incase the api server visibility is public
|
||||
// ensure that when scaling managed ips down the default outbound IP is reused in case the api server visibility is public
|
||||
desiredCount := 0
|
||||
if defaultIP, ok := ipAddresses[infraID+"-pip-v4"]; ok {
|
||||
desiredIPAddresses = append(desiredIPAddresses, api.ResourceReference{ID: *defaultIP.ID})
|
||||
|
@ -320,7 +320,8 @@ func getDesiredOutboundIPs(managedOBIPCount int, ipAddresses map[string]mgmtnetw
|
|||
return desiredIPAddresses
|
||||
}
|
||||
|
||||
func (m *manager) createPublicIPAddresses(ctx context.Context, ipAddresses map[string]mgmtnetwork.PublicIPAddress, numToCreate int) error {
|
||||
// createPublicIPAddresses creates managed outbound IP Addresses.
|
||||
func (m *manager) createPublicIPAddresses(ctx context.Context, ipAddresses map[string]sdknetwork.PublicIPAddress, numToCreate int) error {
|
||||
ch := make(chan createIPResult)
|
||||
defer close(ch)
|
||||
var errResults []string
|
||||
|
@ -344,21 +345,21 @@ func (m *manager) createPublicIPAddresses(ctx context.Context, ipAddresses map[s
|
|||
return nil
|
||||
}
|
||||
|
||||
// Get all current managed IP Addresses in cluster resource group based on naming convention.
|
||||
func (m *manager) getClusterManagedIPs(ctx context.Context) (map[string]mgmtnetwork.PublicIPAddress, error) {
|
||||
// getClusterManagedIPs gets all current managed IP Addresses in cluster resource group based on naming convention.
|
||||
func (m *manager) getClusterManagedIPs(ctx context.Context) (map[string]sdknetwork.PublicIPAddress, error) {
|
||||
resourceGroupName := stringutils.LastTokenByte(m.doc.OpenShiftCluster.Properties.ClusterProfile.ResourceGroupID, '/')
|
||||
infraID := m.doc.OpenShiftCluster.Properties.InfraID
|
||||
var ipAddresses = make(map[string]mgmtnetwork.PublicIPAddress)
|
||||
var ipAddresses = make(map[string]sdknetwork.PublicIPAddress)
|
||||
|
||||
result, err := m.publicIPAddresses.List(ctx, resourceGroupName)
|
||||
result, err := m.armPublicIPAddresses.List(ctx, resourceGroupName, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for i := 0; i < len(result); i++ {
|
||||
for _, ip := range result {
|
||||
// <infraID>-pip-v4 is the default installed outbound IP
|
||||
if *result[i].Name == infraID+"-pip-v4" || strings.Contains(*result[i].Name, "-outbound-pip-v4") {
|
||||
ipAddresses[*result[i].Name] = result[i]
|
||||
if *ip.Name == infraID+"-pip-v4" || strings.Contains(*ip.Name, "-outbound-pip-v4") {
|
||||
ipAddresses[*ip.Name] = *ip
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -369,7 +370,7 @@ func genManagedOutboundIPName() string {
|
|||
return uuid.DefaultGenerator.Generate() + "-outbound-pip-v4"
|
||||
}
|
||||
|
||||
// Create a managed outbound IP Address.
|
||||
// createPublicIPAddress creates a managed outbound IP Address.
|
||||
func (m *manager) createPublicIPAddress(ctx context.Context, ch chan<- createIPResult) {
|
||||
name := genManagedOutboundIPName()
|
||||
resourceGroupName := stringutils.LastTokenByte(m.doc.OpenShiftCluster.Properties.ClusterProfile.ResourceGroupID, '/')
|
||||
|
@ -377,23 +378,24 @@ func (m *manager) createPublicIPAddress(ctx context.Context, ch chan<- createIPR
|
|||
m.log.Infof("creating public IP Address: %s", name)
|
||||
publicIPAddress := newPublicIPAddress(name, resourceID, m.doc.OpenShiftCluster.Location)
|
||||
|
||||
err := m.publicIPAddresses.CreateOrUpdateAndWait(ctx, resourceGroupName, name, publicIPAddress)
|
||||
err := m.armPublicIPAddresses.CreateOrUpdateAndWait(ctx, resourceGroupName, name, publicIPAddress, nil)
|
||||
ch <- createIPResult{
|
||||
ip: publicIPAddress,
|
||||
err: err,
|
||||
}
|
||||
}
|
||||
|
||||
func getOutboundIPsFromLB(lb mgmtnetwork.LoadBalancer) []api.ResourceReference {
|
||||
// getOutboundIPsFromLB returns the public IP addresses used by the load balancer outbound rule "outbound-rule-v4".
|
||||
func getOutboundIPsFromLB(lb sdknetwork.LoadBalancer) []api.ResourceReference {
|
||||
var outboundIPs []api.ResourceReference
|
||||
fipConfigs := getFrontendIPConfigs(lb)
|
||||
|
||||
for _, obRule := range *lb.LoadBalancerPropertiesFormat.OutboundRules {
|
||||
for _, obRule := range lb.Properties.OutboundRules {
|
||||
if *obRule.Name == outboundRuleV4 {
|
||||
for i := 0; i < len(*obRule.OutboundRulePropertiesFormat.FrontendIPConfigurations); i++ {
|
||||
id := *(*obRule.OutboundRulePropertiesFormat.FrontendIPConfigurations)[i].ID
|
||||
for _, obFipConfig := range obRule.Properties.FrontendIPConfigurations {
|
||||
id := *obFipConfig.ID
|
||||
if fipConfig, ok := fipConfigs[id]; ok {
|
||||
outboundIPs = append(outboundIPs, api.ResourceReference{ID: *fipConfig.PublicIPAddress.ID})
|
||||
outboundIPs = append(outboundIPs, api.ResourceReference{ID: *fipConfig.Properties.PublicIPAddress.ID})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -419,36 +421,36 @@ func (m *manager) patchEffectiveOutboundIPs(ctx context.Context, outboundIPs []a
|
|||
return nil
|
||||
}
|
||||
|
||||
func newPublicIPAddress(name, resourceID, location string) mgmtnetwork.PublicIPAddress {
|
||||
return mgmtnetwork.PublicIPAddress{
|
||||
func newPublicIPAddress(name, resourceID, location string) sdknetwork.PublicIPAddress {
|
||||
return sdknetwork.PublicIPAddress{
|
||||
Name: &name,
|
||||
ID: &resourceID,
|
||||
Location: &location,
|
||||
PublicIPAddressPropertiesFormat: &mgmtnetwork.PublicIPAddressPropertiesFormat{
|
||||
PublicIPAllocationMethod: mgmtnetwork.Static,
|
||||
PublicIPAddressVersion: mgmtnetwork.IPv4,
|
||||
Properties: &sdknetwork.PublicIPAddressPropertiesFormat{
|
||||
PublicIPAllocationMethod: ptr.To(sdknetwork.IPAllocationMethodStatic),
|
||||
PublicIPAddressVersion: ptr.To(sdknetwork.IPVersionIPv4),
|
||||
},
|
||||
Sku: &mgmtnetwork.PublicIPAddressSku{
|
||||
Name: mgmtnetwork.PublicIPAddressSkuNameStandard,
|
||||
SKU: &sdknetwork.PublicIPAddressSKU{
|
||||
Name: ptr.To(sdknetwork.PublicIPAddressSKUNameStandard),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func newFrontendIPConfig(name string, id string, publicIPorIPPrefixID string) mgmtnetwork.FrontendIPConfiguration {
|
||||
func newFrontendIPConfig(name string, id string, publicIPorIPPrefixID string) *sdknetwork.FrontendIPConfiguration {
|
||||
// TODO: add check for publicIPorIPPrefixID
|
||||
return mgmtnetwork.FrontendIPConfiguration{
|
||||
return &sdknetwork.FrontendIPConfiguration{
|
||||
Name: &name,
|
||||
ID: &id,
|
||||
FrontendIPConfigurationPropertiesFormat: &mgmtnetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
PublicIPAddress: &mgmtnetwork.PublicIPAddress{
|
||||
Properties: &sdknetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
PublicIPAddress: &sdknetwork.PublicIPAddress{
|
||||
ID: &publicIPorIPPrefixID,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func newOutboundRuleFrontendIPConfig(id string) mgmtnetwork.SubResource {
|
||||
return mgmtnetwork.SubResource{
|
||||
func newOutboundRuleFrontendIPConfig(id string) *sdknetwork.SubResource {
|
||||
return &sdknetwork.SubResource{
|
||||
ID: &id,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,15 +9,15 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
mgmtnetwork "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-08-01/network"
|
||||
"github.com/Azure/go-autorest/autorest/to"
|
||||
sdknetwork "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v2"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/mock/gomock"
|
||||
"k8s.io/utils/ptr"
|
||||
|
||||
"github.com/Azure/ARO-RP/pkg/api"
|
||||
mock_network "github.com/Azure/ARO-RP/pkg/util/mocks/azureclient/mgmt/network"
|
||||
mock_armnetwork "github.com/Azure/ARO-RP/pkg/util/mocks/azureclient/azuresdk/armnetwork"
|
||||
"github.com/Azure/ARO-RP/pkg/util/uuid"
|
||||
uuidfake "github.com/Azure/ARO-RP/pkg/util/uuid/fake"
|
||||
testdatabase "github.com/Azure/ARO-RP/test/database"
|
||||
|
@ -36,7 +36,7 @@ func TestReconcileOutboundIPs(t *testing.T) {
|
|||
m manager
|
||||
uuids []string
|
||||
mocks func(
|
||||
publicIPAddressClient *mock_network.MockPublicIPAddressesClient,
|
||||
publicIPAddressClient *mock_armnetwork.MockPublicIPAddressesClient,
|
||||
ctx context.Context)
|
||||
expectedOutboundIPS []api.ResourceReference
|
||||
expectedErr error
|
||||
|
@ -65,13 +65,13 @@ func TestReconcileOutboundIPs(t *testing.T) {
|
|||
},
|
||||
uuids: []string{"uuid2"},
|
||||
mocks: func(
|
||||
publicIPAddressClient *mock_network.MockPublicIPAddressesClient,
|
||||
publicIPAddressClient *mock_armnetwork.MockPublicIPAddressesClient,
|
||||
ctx context.Context) {
|
||||
publicIPAddressClient.EXPECT().
|
||||
List(gomock.Any(), clusterRGName).
|
||||
List(gomock.Any(), clusterRGName, nil).
|
||||
Return(getFakePublicIPList(1), nil)
|
||||
publicIPAddressClient.EXPECT().
|
||||
CreateOrUpdateAndWait(ctx, clusterRGName, "uuid2-outbound-pip-v4", getFakePublicIPAddress("uuid2-outbound-pip-v4", location)).
|
||||
CreateOrUpdateAndWait(ctx, clusterRGName, "uuid2-outbound-pip-v4", getFakePublicIPAddress("uuid2-outbound-pip-v4", location), nil).
|
||||
Return(nil)
|
||||
},
|
||||
expectedErr: nil,
|
||||
|
@ -100,10 +100,10 @@ func TestReconcileOutboundIPs(t *testing.T) {
|
|||
},
|
||||
uuids: []string{},
|
||||
mocks: func(
|
||||
publicIPAddressClient *mock_network.MockPublicIPAddressesClient,
|
||||
publicIPAddressClient *mock_armnetwork.MockPublicIPAddressesClient,
|
||||
ctx context.Context) {
|
||||
publicIPAddressClient.EXPECT().
|
||||
List(gomock.Any(), clusterRGName).
|
||||
List(gomock.Any(), clusterRGName, nil).
|
||||
Return(getFakePublicIPList(2), nil)
|
||||
},
|
||||
expectedErr: nil,
|
||||
|
@ -114,12 +114,12 @@ func TestReconcileOutboundIPs(t *testing.T) {
|
|||
uuid.DefaultGenerator = uuidfake.NewGenerator(tt.uuids)
|
||||
controller := gomock.NewController(t)
|
||||
defer controller.Finish()
|
||||
publicIPAddressClient := mock_network.NewMockPublicIPAddressesClient(controller)
|
||||
publicIPAddressClient := mock_armnetwork.NewMockPublicIPAddressesClient(controller)
|
||||
|
||||
if tt.mocks != nil {
|
||||
tt.mocks(publicIPAddressClient, ctx)
|
||||
}
|
||||
tt.m.publicIPAddresses = publicIPAddressClient
|
||||
tt.m.armPublicIPAddresses = publicIPAddressClient
|
||||
|
||||
// Run reconcileOutboundIPs and assert the correct results
|
||||
outboundIPs, err := tt.m.reconcileOutboundIPs(ctx)
|
||||
|
@ -141,10 +141,10 @@ func TestDeleteUnusedManagedIPs(t *testing.T) {
|
|||
name string
|
||||
m manager
|
||||
mocks func(
|
||||
publicIPAddressClient *mock_network.MockPublicIPAddressesClient,
|
||||
loadBalancersClient *mock_network.MockLoadBalancersClient,
|
||||
publicIPAddressClient *mock_armnetwork.MockPublicIPAddressesClient,
|
||||
loadBalancersClient *mock_armnetwork.MockLoadBalancersClient,
|
||||
ctx context.Context)
|
||||
expectedManagedIPs map[string]mgmtnetwork.PublicIPAddress
|
||||
expectedManagedIPs map[string]sdknetwork.PublicIPAddress
|
||||
expectedErr error
|
||||
}{
|
||||
{
|
||||
|
@ -174,16 +174,16 @@ func TestDeleteUnusedManagedIPs(t *testing.T) {
|
|||
},
|
||||
},
|
||||
mocks: func(
|
||||
publicIPAddressClient *mock_network.MockPublicIPAddressesClient,
|
||||
loadBalancersClient *mock_network.MockLoadBalancersClient,
|
||||
publicIPAddressClient *mock_armnetwork.MockPublicIPAddressesClient,
|
||||
loadBalancersClient *mock_armnetwork.MockLoadBalancersClient,
|
||||
ctx context.Context) {
|
||||
publicIPAddressClient.EXPECT().
|
||||
List(gomock.Any(), clusterRGName).
|
||||
List(gomock.Any(), clusterRGName, nil).
|
||||
Return(getFakePublicIPList(1), nil)
|
||||
loadBalancersClient.EXPECT().
|
||||
Get(gomock.Any(), clusterRGName, infraID, "").
|
||||
Return(fakeLoadBalancersGet(0, api.VisibilityPublic), nil)
|
||||
publicIPAddressClient.EXPECT().DeleteAndWait(gomock.Any(), "clusterRG", "uuid1-outbound-pip-v4")
|
||||
Get(gomock.Any(), clusterRGName, infraID, nil).
|
||||
Return(sdknetwork.LoadBalancersClientGetResponse{LoadBalancer: fakeLoadBalancersGet(0, api.VisibilityPublic)}, nil)
|
||||
publicIPAddressClient.EXPECT().DeleteAndWait(gomock.Any(), "clusterRG", "uuid1-outbound-pip-v4", nil)
|
||||
},
|
||||
expectedErr: nil,
|
||||
},
|
||||
|
@ -214,44 +214,46 @@ func TestDeleteUnusedManagedIPs(t *testing.T) {
|
|||
},
|
||||
},
|
||||
mocks: func(
|
||||
publicIPAddressClient *mock_network.MockPublicIPAddressesClient,
|
||||
loadBalancersClient *mock_network.MockLoadBalancersClient,
|
||||
publicIPAddressClient *mock_armnetwork.MockPublicIPAddressesClient,
|
||||
loadBalancersClient *mock_armnetwork.MockLoadBalancersClient,
|
||||
ctx context.Context) {
|
||||
publicIPAddressClient.EXPECT().
|
||||
List(gomock.Any(), clusterRGName).
|
||||
List(gomock.Any(), clusterRGName, nil).
|
||||
Return(getFakePublicIPList(1), nil)
|
||||
loadBalancersClient.EXPECT().
|
||||
Get(gomock.Any(), clusterRGName, infraID, "").
|
||||
Return(mgmtnetwork.LoadBalancer{
|
||||
Name: &infraID,
|
||||
LoadBalancerPropertiesFormat: &mgmtnetwork.LoadBalancerPropertiesFormat{
|
||||
FrontendIPConfigurations: &[]mgmtnetwork.FrontendIPConfiguration{
|
||||
{
|
||||
Name: to.StringPtr("ae3506385907e44eba9ef9bf76eac973"),
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/ae3506385907e44eba9ef9bf76eac973"),
|
||||
FrontendIPConfigurationPropertiesFormat: &mgmtnetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
PublicIPAddress: &mgmtnetwork.PublicIPAddress{
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/publicIPAddresses/infraID-default-v4"),
|
||||
Get(gomock.Any(), clusterRGName, infraID, nil).
|
||||
Return(sdknetwork.LoadBalancersClientGetResponse{
|
||||
LoadBalancer: sdknetwork.LoadBalancer{
|
||||
Name: &infraID,
|
||||
Properties: &sdknetwork.LoadBalancerPropertiesFormat{
|
||||
FrontendIPConfigurations: []*sdknetwork.FrontendIPConfiguration{
|
||||
{
|
||||
Name: ptr.To("ae3506385907e44eba9ef9bf76eac973"),
|
||||
ID: ptr.To("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/ae3506385907e44eba9ef9bf76eac973"),
|
||||
Properties: &sdknetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
PublicIPAddress: &sdknetwork.PublicIPAddress{
|
||||
ID: ptr.To("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/publicIPAddresses/infraID-default-v4"),
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: ptr.To("customer-ip"),
|
||||
ID: ptr.To("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/customerRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/customer-ip"),
|
||||
Properties: &sdknetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
PublicIPAddress: &sdknetwork.PublicIPAddress{
|
||||
ID: ptr.To("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/customerRG/providers/Microsoft.Network/publicIPAddresses/customer-ip"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: to.StringPtr("customer-ip"),
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/customerRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/customer-ip"),
|
||||
FrontendIPConfigurationPropertiesFormat: &mgmtnetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
PublicIPAddress: &mgmtnetwork.PublicIPAddress{
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/customerRG/providers/Microsoft.Network/publicIPAddresses/customer-ip"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
OutboundRules: &[]mgmtnetwork.OutboundRule{
|
||||
{
|
||||
Name: to.StringPtr(outboundRuleV4),
|
||||
OutboundRulePropertiesFormat: &mgmtnetwork.OutboundRulePropertiesFormat{
|
||||
FrontendIPConfigurations: &[]mgmtnetwork.SubResource{
|
||||
{
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/customerRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/customer-ip"),
|
||||
OutboundRules: []*sdknetwork.OutboundRule{
|
||||
{
|
||||
Name: ptr.To(outboundRuleV4),
|
||||
Properties: &sdknetwork.OutboundRulePropertiesFormat{
|
||||
FrontendIPConfigurations: []*sdknetwork.SubResource{
|
||||
{
|
||||
ID: ptr.To("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/customerRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/customer-ip"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -259,8 +261,8 @@ func TestDeleteUnusedManagedIPs(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}, nil)
|
||||
publicIPAddressClient.EXPECT().DeleteAndWait(gomock.Any(), "clusterRG", "infraID-pip-v4")
|
||||
publicIPAddressClient.EXPECT().DeleteAndWait(gomock.Any(), "clusterRG", "uuid1-outbound-pip-v4")
|
||||
publicIPAddressClient.EXPECT().DeleteAndWait(gomock.Any(), "clusterRG", "infraID-pip-v4", nil)
|
||||
publicIPAddressClient.EXPECT().DeleteAndWait(gomock.Any(), "clusterRG", "uuid1-outbound-pip-v4", nil)
|
||||
},
|
||||
expectedErr: nil,
|
||||
},
|
||||
|
@ -270,14 +272,14 @@ func TestDeleteUnusedManagedIPs(t *testing.T) {
|
|||
|
||||
controller := gomock.NewController(t)
|
||||
defer controller.Finish()
|
||||
publicIPAddressClient := mock_network.NewMockPublicIPAddressesClient(controller)
|
||||
loadBalancersClient := mock_network.NewMockLoadBalancersClient(controller)
|
||||
publicIPAddressClient := mock_armnetwork.NewMockPublicIPAddressesClient(controller)
|
||||
loadBalancersClient := mock_armnetwork.NewMockLoadBalancersClient(controller)
|
||||
|
||||
if tt.mocks != nil {
|
||||
tt.mocks(publicIPAddressClient, loadBalancersClient, ctx)
|
||||
}
|
||||
tt.m.publicIPAddresses = publicIPAddressClient
|
||||
tt.m.loadBalancers = loadBalancersClient
|
||||
tt.m.armPublicIPAddresses = publicIPAddressClient
|
||||
tt.m.armLoadBalancers = loadBalancersClient
|
||||
|
||||
// Run deleteUnusedManagedIPs and assert the correct results
|
||||
err := tt.m.deleteUnusedManagedIPs(ctx)
|
||||
|
@ -293,8 +295,8 @@ func TestAddOutboundIPsToLB(t *testing.T) {
|
|||
for _, tt := range []struct {
|
||||
name string
|
||||
desiredOBIPs []api.ResourceReference
|
||||
currentLB mgmtnetwork.LoadBalancer
|
||||
expectedLB mgmtnetwork.LoadBalancer
|
||||
currentLB sdknetwork.LoadBalancer
|
||||
expectedLB sdknetwork.LoadBalancer
|
||||
}{
|
||||
{
|
||||
name: "add default IP to lb",
|
||||
|
@ -304,52 +306,52 @@ func TestAddOutboundIPsToLB(t *testing.T) {
|
|||
},
|
||||
},
|
||||
currentLB: getClearedLB(),
|
||||
expectedLB: mgmtnetwork.LoadBalancer{
|
||||
Name: to.StringPtr("infraID"),
|
||||
LoadBalancerPropertiesFormat: &mgmtnetwork.LoadBalancerPropertiesFormat{
|
||||
FrontendIPConfigurations: &[]mgmtnetwork.FrontendIPConfiguration{
|
||||
expectedLB: sdknetwork.LoadBalancer{
|
||||
Name: ptr.To("infraID"),
|
||||
Properties: &sdknetwork.LoadBalancerPropertiesFormat{
|
||||
FrontendIPConfigurations: []*sdknetwork.FrontendIPConfiguration{
|
||||
{
|
||||
Name: to.StringPtr("ae3506385907e44eba9ef9bf76eac973"),
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/ae3506385907e44eba9ef9bf76eac973"),
|
||||
FrontendIPConfigurationPropertiesFormat: &mgmtnetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
LoadBalancingRules: &[]mgmtnetwork.SubResource{
|
||||
Name: ptr.To("ae3506385907e44eba9ef9bf76eac973"),
|
||||
ID: ptr.To("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/ae3506385907e44eba9ef9bf76eac973"),
|
||||
Properties: &sdknetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
LoadBalancingRules: []*sdknetwork.SubResource{
|
||||
{
|
||||
ID: to.StringPtr("ae3506385907e44eba9ef9bf76eac973-TCP-80"),
|
||||
ID: ptr.To("ae3506385907e44eba9ef9bf76eac973-TCP-80"),
|
||||
},
|
||||
{
|
||||
ID: to.StringPtr("ae3506385907e44eba9ef9bf76eac973-TCP-443"),
|
||||
ID: ptr.To("ae3506385907e44eba9ef9bf76eac973-TCP-443"),
|
||||
},
|
||||
},
|
||||
PublicIPAddress: &mgmtnetwork.PublicIPAddress{
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/publicIPAddresses/infraID-default-v4"),
|
||||
PublicIPAddress: &sdknetwork.PublicIPAddress{
|
||||
ID: ptr.To("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/publicIPAddresses/infraID-default-v4"),
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: to.StringPtr("public-lb-ip-v4"),
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/public-lb-ip-v4"),
|
||||
FrontendIPConfigurationPropertiesFormat: &mgmtnetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
LoadBalancingRules: &[]mgmtnetwork.SubResource{
|
||||
Name: ptr.To("public-lb-ip-v4"),
|
||||
ID: ptr.To("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/public-lb-ip-v4"),
|
||||
Properties: &sdknetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
LoadBalancingRules: []*sdknetwork.SubResource{
|
||||
{
|
||||
ID: to.StringPtr("api-internal-v4"),
|
||||
ID: ptr.To("api-internal-v4"),
|
||||
},
|
||||
},
|
||||
OutboundRules: &[]mgmtnetwork.SubResource{{
|
||||
ID: to.StringPtr(outboundRuleV4),
|
||||
OutboundRules: []*sdknetwork.SubResource{{
|
||||
ID: ptr.To(outboundRuleV4),
|
||||
}},
|
||||
PublicIPAddress: &mgmtnetwork.PublicIPAddress{
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/publicIPAddresses/infraID-pip-v4"),
|
||||
PublicIPAddress: &sdknetwork.PublicIPAddress{
|
||||
ID: ptr.To("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/publicIPAddresses/infraID-pip-v4"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
OutboundRules: &[]mgmtnetwork.OutboundRule{
|
||||
OutboundRules: []*sdknetwork.OutboundRule{
|
||||
{
|
||||
Name: to.StringPtr(outboundRuleV4),
|
||||
OutboundRulePropertiesFormat: &mgmtnetwork.OutboundRulePropertiesFormat{
|
||||
FrontendIPConfigurations: &[]mgmtnetwork.SubResource{
|
||||
Name: ptr.To(outboundRuleV4),
|
||||
Properties: &sdknetwork.OutboundRulePropertiesFormat{
|
||||
FrontendIPConfigurations: []*sdknetwork.SubResource{
|
||||
{
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/public-lb-ip-v4"),
|
||||
ID: ptr.To("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/public-lb-ip-v4"),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -369,64 +371,64 @@ func TestAddOutboundIPsToLB(t *testing.T) {
|
|||
},
|
||||
},
|
||||
currentLB: getClearedLB(),
|
||||
expectedLB: mgmtnetwork.LoadBalancer{
|
||||
Name: to.StringPtr("infraID"),
|
||||
LoadBalancerPropertiesFormat: &mgmtnetwork.LoadBalancerPropertiesFormat{
|
||||
FrontendIPConfigurations: &[]mgmtnetwork.FrontendIPConfiguration{
|
||||
expectedLB: sdknetwork.LoadBalancer{
|
||||
Name: ptr.To("infraID"),
|
||||
Properties: &sdknetwork.LoadBalancerPropertiesFormat{
|
||||
FrontendIPConfigurations: []*sdknetwork.FrontendIPConfiguration{
|
||||
{
|
||||
Name: to.StringPtr("ae3506385907e44eba9ef9bf76eac973"),
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/ae3506385907e44eba9ef9bf76eac973"),
|
||||
FrontendIPConfigurationPropertiesFormat: &mgmtnetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
LoadBalancingRules: &[]mgmtnetwork.SubResource{
|
||||
Name: ptr.To("ae3506385907e44eba9ef9bf76eac973"),
|
||||
ID: ptr.To("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/ae3506385907e44eba9ef9bf76eac973"),
|
||||
Properties: &sdknetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
LoadBalancingRules: []*sdknetwork.SubResource{
|
||||
{
|
||||
ID: to.StringPtr("ae3506385907e44eba9ef9bf76eac973-TCP-80"),
|
||||
ID: ptr.To("ae3506385907e44eba9ef9bf76eac973-TCP-80"),
|
||||
},
|
||||
{
|
||||
ID: to.StringPtr("ae3506385907e44eba9ef9bf76eac973-TCP-443"),
|
||||
ID: ptr.To("ae3506385907e44eba9ef9bf76eac973-TCP-443"),
|
||||
},
|
||||
},
|
||||
PublicIPAddress: &mgmtnetwork.PublicIPAddress{
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/publicIPAddresses/infraID-default-v4"),
|
||||
PublicIPAddress: &sdknetwork.PublicIPAddress{
|
||||
ID: ptr.To("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/publicIPAddresses/infraID-default-v4"),
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: to.StringPtr("public-lb-ip-v4"),
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/public-lb-ip-v4"),
|
||||
FrontendIPConfigurationPropertiesFormat: &mgmtnetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
LoadBalancingRules: &[]mgmtnetwork.SubResource{
|
||||
Name: ptr.To("public-lb-ip-v4"),
|
||||
ID: ptr.To("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/public-lb-ip-v4"),
|
||||
Properties: &sdknetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
LoadBalancingRules: []*sdknetwork.SubResource{
|
||||
{
|
||||
ID: to.StringPtr("api-internal-v4"),
|
||||
ID: ptr.To("api-internal-v4"),
|
||||
},
|
||||
},
|
||||
OutboundRules: &[]mgmtnetwork.SubResource{{
|
||||
ID: to.StringPtr(outboundRuleV4),
|
||||
OutboundRules: []*sdknetwork.SubResource{{
|
||||
ID: ptr.To(outboundRuleV4),
|
||||
}},
|
||||
PublicIPAddress: &mgmtnetwork.PublicIPAddress{
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/publicIPAddresses/infraID-pip-v4"),
|
||||
PublicIPAddress: &sdknetwork.PublicIPAddress{
|
||||
ID: ptr.To("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/publicIPAddresses/infraID-pip-v4"),
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: to.StringPtr("uuid1-outbound-pip-v4"),
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/uuid1-outbound-pip-v4"),
|
||||
FrontendIPConfigurationPropertiesFormat: &mgmtnetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
PublicIPAddress: &mgmtnetwork.PublicIPAddress{
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/publicIPAddresses/uuid1-outbound-pip-v4"),
|
||||
Name: ptr.To("uuid1-outbound-pip-v4"),
|
||||
ID: ptr.To("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/uuid1-outbound-pip-v4"),
|
||||
Properties: &sdknetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
PublicIPAddress: &sdknetwork.PublicIPAddress{
|
||||
ID: ptr.To("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/publicIPAddresses/uuid1-outbound-pip-v4"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
OutboundRules: &[]mgmtnetwork.OutboundRule{
|
||||
OutboundRules: []*sdknetwork.OutboundRule{
|
||||
{
|
||||
Name: to.StringPtr(outboundRuleV4),
|
||||
OutboundRulePropertiesFormat: &mgmtnetwork.OutboundRulePropertiesFormat{
|
||||
FrontendIPConfigurations: &[]mgmtnetwork.SubResource{
|
||||
Name: ptr.To(outboundRuleV4),
|
||||
Properties: &sdknetwork.OutboundRulePropertiesFormat{
|
||||
FrontendIPConfigurations: []*sdknetwork.SubResource{
|
||||
{
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/public-lb-ip-v4"),
|
||||
ID: ptr.To("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/public-lb-ip-v4"),
|
||||
},
|
||||
{
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/uuid1-outbound-pip-v4"),
|
||||
ID: ptr.To("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/uuid1-outbound-pip-v4"),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -448,56 +450,56 @@ func TestRemoveOutboundIPsFromLB(t *testing.T) {
|
|||
// Run tests
|
||||
for _, tt := range []struct {
|
||||
name string
|
||||
currentLB mgmtnetwork.LoadBalancer
|
||||
expectedLB mgmtnetwork.LoadBalancer
|
||||
currentLB sdknetwork.LoadBalancer
|
||||
expectedLB sdknetwork.LoadBalancer
|
||||
}{
|
||||
{
|
||||
name: "remove all outbound-rule-v4 fip config except api server",
|
||||
currentLB: fakeLoadBalancersGet(1, api.VisibilityPublic),
|
||||
expectedLB: mgmtnetwork.LoadBalancer{
|
||||
Name: to.StringPtr("infraID"),
|
||||
LoadBalancerPropertiesFormat: &mgmtnetwork.LoadBalancerPropertiesFormat{
|
||||
FrontendIPConfigurations: &[]mgmtnetwork.FrontendIPConfiguration{
|
||||
expectedLB: sdknetwork.LoadBalancer{
|
||||
Name: ptr.To("infraID"),
|
||||
Properties: &sdknetwork.LoadBalancerPropertiesFormat{
|
||||
FrontendIPConfigurations: []*sdknetwork.FrontendIPConfiguration{
|
||||
{
|
||||
Name: to.StringPtr("ae3506385907e44eba9ef9bf76eac973"),
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/ae3506385907e44eba9ef9bf76eac973"),
|
||||
FrontendIPConfigurationPropertiesFormat: &mgmtnetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
LoadBalancingRules: &[]mgmtnetwork.SubResource{
|
||||
Name: ptr.To("ae3506385907e44eba9ef9bf76eac973"),
|
||||
ID: ptr.To("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/ae3506385907e44eba9ef9bf76eac973"),
|
||||
Properties: &sdknetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
LoadBalancingRules: []*sdknetwork.SubResource{
|
||||
{
|
||||
ID: to.StringPtr("ae3506385907e44eba9ef9bf76eac973-TCP-80"),
|
||||
ID: ptr.To("ae3506385907e44eba9ef9bf76eac973-TCP-80"),
|
||||
},
|
||||
{
|
||||
ID: to.StringPtr("ae3506385907e44eba9ef9bf76eac973-TCP-443"),
|
||||
ID: ptr.To("ae3506385907e44eba9ef9bf76eac973-TCP-443"),
|
||||
},
|
||||
},
|
||||
PublicIPAddress: &mgmtnetwork.PublicIPAddress{
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/publicIPAddresses/infraID-default-v4"),
|
||||
PublicIPAddress: &sdknetwork.PublicIPAddress{
|
||||
ID: ptr.To("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/publicIPAddresses/infraID-default-v4"),
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: to.StringPtr("public-lb-ip-v4"),
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/public-lb-ip-v4"),
|
||||
FrontendIPConfigurationPropertiesFormat: &mgmtnetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
LoadBalancingRules: &[]mgmtnetwork.SubResource{
|
||||
Name: ptr.To("public-lb-ip-v4"),
|
||||
ID: ptr.To("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/public-lb-ip-v4"),
|
||||
Properties: &sdknetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
LoadBalancingRules: []*sdknetwork.SubResource{
|
||||
{
|
||||
ID: to.StringPtr("api-internal-v4"),
|
||||
ID: ptr.To("api-internal-v4"),
|
||||
},
|
||||
},
|
||||
OutboundRules: &[]mgmtnetwork.SubResource{{
|
||||
ID: to.StringPtr(outboundRuleV4),
|
||||
OutboundRules: []*sdknetwork.SubResource{{
|
||||
ID: ptr.To(outboundRuleV4),
|
||||
}},
|
||||
PublicIPAddress: &mgmtnetwork.PublicIPAddress{
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/publicIPAddresses/infraID-pip-v4"),
|
||||
PublicIPAddress: &sdknetwork.PublicIPAddress{
|
||||
ID: ptr.To("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/publicIPAddresses/infraID-pip-v4"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
OutboundRules: &[]mgmtnetwork.OutboundRule{
|
||||
OutboundRules: []*sdknetwork.OutboundRule{
|
||||
{
|
||||
Name: to.StringPtr(outboundRuleV4),
|
||||
OutboundRulePropertiesFormat: &mgmtnetwork.OutboundRulePropertiesFormat{
|
||||
FrontendIPConfigurations: &[]mgmtnetwork.SubResource{},
|
||||
Name: ptr.To(outboundRuleV4),
|
||||
Properties: &sdknetwork.OutboundRulePropertiesFormat{
|
||||
FrontendIPConfigurations: []*sdknetwork.SubResource{},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -507,33 +509,33 @@ func TestRemoveOutboundIPsFromLB(t *testing.T) {
|
|||
{
|
||||
name: "remove all outbound-rule-v4 fip config",
|
||||
currentLB: fakeLoadBalancersGet(1, api.VisibilityPrivate),
|
||||
expectedLB: mgmtnetwork.LoadBalancer{
|
||||
Name: to.StringPtr("infraID"),
|
||||
LoadBalancerPropertiesFormat: &mgmtnetwork.LoadBalancerPropertiesFormat{
|
||||
FrontendIPConfigurations: &[]mgmtnetwork.FrontendIPConfiguration{
|
||||
expectedLB: sdknetwork.LoadBalancer{
|
||||
Name: ptr.To("infraID"),
|
||||
Properties: &sdknetwork.LoadBalancerPropertiesFormat{
|
||||
FrontendIPConfigurations: []*sdknetwork.FrontendIPConfiguration{
|
||||
{
|
||||
Name: to.StringPtr("ae3506385907e44eba9ef9bf76eac973"),
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/ae3506385907e44eba9ef9bf76eac973"),
|
||||
FrontendIPConfigurationPropertiesFormat: &mgmtnetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
LoadBalancingRules: &[]mgmtnetwork.SubResource{
|
||||
Name: ptr.To("ae3506385907e44eba9ef9bf76eac973"),
|
||||
ID: ptr.To("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/ae3506385907e44eba9ef9bf76eac973"),
|
||||
Properties: &sdknetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
LoadBalancingRules: []*sdknetwork.SubResource{
|
||||
{
|
||||
ID: to.StringPtr("ae3506385907e44eba9ef9bf76eac973-TCP-80"),
|
||||
ID: ptr.To("ae3506385907e44eba9ef9bf76eac973-TCP-80"),
|
||||
},
|
||||
{
|
||||
ID: to.StringPtr("ae3506385907e44eba9ef9bf76eac973-TCP-443"),
|
||||
ID: ptr.To("ae3506385907e44eba9ef9bf76eac973-TCP-443"),
|
||||
},
|
||||
},
|
||||
PublicIPAddress: &mgmtnetwork.PublicIPAddress{
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/publicIPAddresses/infraID-default-v4"),
|
||||
PublicIPAddress: &sdknetwork.PublicIPAddress{
|
||||
ID: ptr.To("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/publicIPAddresses/infraID-default-v4"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
OutboundRules: &[]mgmtnetwork.OutboundRule{
|
||||
OutboundRules: []*sdknetwork.OutboundRule{
|
||||
{
|
||||
Name: to.StringPtr(outboundRuleV4),
|
||||
OutboundRulePropertiesFormat: &mgmtnetwork.OutboundRulePropertiesFormat{
|
||||
FrontendIPConfigurations: &[]mgmtnetwork.SubResource{},
|
||||
Name: ptr.To(outboundRuleV4),
|
||||
Properties: &sdknetwork.OutboundRulePropertiesFormat{
|
||||
FrontendIPConfigurations: []*sdknetwork.SubResource{},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -564,12 +566,12 @@ func TestReconcileLoadBalancerProfile(t *testing.T) {
|
|||
for _, tt := range []struct {
|
||||
name string
|
||||
m manager
|
||||
lb mgmtnetwork.LoadBalancer
|
||||
lb sdknetwork.LoadBalancer
|
||||
expectedLoadBalancerProfile *api.LoadBalancerProfile
|
||||
uuids []string
|
||||
mocks func(
|
||||
loadBalancersClient *mock_network.MockLoadBalancersClient,
|
||||
publicIPAddressClient *mock_network.MockPublicIPAddressesClient,
|
||||
loadBalancersClient *mock_armnetwork.MockLoadBalancersClient,
|
||||
publicIPAddressClient *mock_armnetwork.MockPublicIPAddressesClient,
|
||||
ctx context.Context)
|
||||
expectedErr []error
|
||||
}{
|
||||
|
@ -635,21 +637,21 @@ func TestReconcileLoadBalancerProfile(t *testing.T) {
|
|||
},
|
||||
},
|
||||
mocks: func(
|
||||
loadBalancersClient *mock_network.MockLoadBalancersClient,
|
||||
publicIPAddressClient *mock_network.MockPublicIPAddressesClient,
|
||||
loadBalancersClient *mock_armnetwork.MockLoadBalancersClient,
|
||||
publicIPAddressClient *mock_armnetwork.MockPublicIPAddressesClient,
|
||||
ctx context.Context) {
|
||||
publicIPAddressClient.EXPECT().
|
||||
List(gomock.Any(), clusterRGName).
|
||||
List(gomock.Any(), clusterRGName, nil).
|
||||
Return(getFakePublicIPList(0), nil)
|
||||
loadBalancersClient.EXPECT().
|
||||
Get(gomock.Any(), clusterRGName, infraID, "").
|
||||
Return(fakeLoadBalancersGet(0, api.VisibilityPublic), nil)
|
||||
Get(gomock.Any(), clusterRGName, infraID, nil).
|
||||
Return(sdknetwork.LoadBalancersClientGetResponse{LoadBalancer: fakeLoadBalancersGet(0, api.VisibilityPublic)}, nil)
|
||||
publicIPAddressClient.EXPECT().
|
||||
List(gomock.Any(), clusterRGName).
|
||||
List(gomock.Any(), clusterRGName, nil).
|
||||
Return(getFakePublicIPList(0), nil)
|
||||
loadBalancersClient.EXPECT().
|
||||
Get(gomock.Any(), clusterRGName, infraID, "").
|
||||
Return(fakeLoadBalancersGet(0, api.VisibilityPublic), nil)
|
||||
Get(gomock.Any(), clusterRGName, infraID, nil).
|
||||
Return(sdknetwork.LoadBalancersClientGetResponse{LoadBalancer: fakeLoadBalancersGet(0, api.VisibilityPublic)}, nil)
|
||||
},
|
||||
expectedLoadBalancerProfile: &api.LoadBalancerProfile{
|
||||
ManagedOutboundIPs: &api.ManagedOutboundIPs{
|
||||
|
@ -700,21 +702,21 @@ func TestReconcileLoadBalancerProfile(t *testing.T) {
|
|||
},
|
||||
},
|
||||
mocks: func(
|
||||
loadBalancersClient *mock_network.MockLoadBalancersClient,
|
||||
publicIPAddressClient *mock_network.MockPublicIPAddressesClient,
|
||||
loadBalancersClient *mock_armnetwork.MockLoadBalancersClient,
|
||||
publicIPAddressClient *mock_armnetwork.MockPublicIPAddressesClient,
|
||||
ctx context.Context) {
|
||||
publicIPAddressClient.EXPECT().
|
||||
List(gomock.Any(), clusterRGName).
|
||||
List(gomock.Any(), clusterRGName, nil).
|
||||
Return(getFakePublicIPList(1), nil)
|
||||
loadBalancersClient.EXPECT().
|
||||
Get(gomock.Any(), clusterRGName, infraID, "").
|
||||
Return(fakeLoadBalancersGet(1, api.VisibilityPublic), nil)
|
||||
Get(gomock.Any(), clusterRGName, infraID, nil).
|
||||
Return(sdknetwork.LoadBalancersClientGetResponse{LoadBalancer: fakeLoadBalancersGet(1, api.VisibilityPublic)}, nil)
|
||||
publicIPAddressClient.EXPECT().
|
||||
List(gomock.Any(), clusterRGName).
|
||||
List(gomock.Any(), clusterRGName, nil).
|
||||
Return(getFakePublicIPList(1), nil)
|
||||
loadBalancersClient.EXPECT().
|
||||
Get(gomock.Any(), clusterRGName, infraID, "").
|
||||
Return(fakeLoadBalancersGet(1, api.VisibilityPublic), nil)
|
||||
Get(gomock.Any(), clusterRGName, infraID, nil).
|
||||
Return(sdknetwork.LoadBalancersClientGetResponse{LoadBalancer: fakeLoadBalancersGet(1, api.VisibilityPublic)}, nil)
|
||||
},
|
||||
expectedLoadBalancerProfile: &api.LoadBalancerProfile{
|
||||
ManagedOutboundIPs: &api.ManagedOutboundIPs{
|
||||
|
@ -768,25 +770,25 @@ func TestReconcileLoadBalancerProfile(t *testing.T) {
|
|||
},
|
||||
},
|
||||
mocks: func(
|
||||
loadBalancersClient *mock_network.MockLoadBalancersClient,
|
||||
publicIPAddressClient *mock_network.MockPublicIPAddressesClient,
|
||||
loadBalancersClient *mock_armnetwork.MockLoadBalancersClient,
|
||||
publicIPAddressClient *mock_armnetwork.MockPublicIPAddressesClient,
|
||||
ctx context.Context) {
|
||||
publicIPAddressClient.EXPECT().
|
||||
List(gomock.Any(), clusterRGName).
|
||||
List(gomock.Any(), clusterRGName, nil).
|
||||
Return(getFakePublicIPList(0), nil)
|
||||
publicIPAddressClient.EXPECT().
|
||||
CreateOrUpdateAndWait(ctx, clusterRGName, "uuid1-outbound-pip-v4", getFakePublicIPAddress("uuid1-outbound-pip-v4", location)).Return(nil)
|
||||
CreateOrUpdateAndWait(ctx, clusterRGName, "uuid1-outbound-pip-v4", getFakePublicIPAddress("uuid1-outbound-pip-v4", location), nil).Return(nil)
|
||||
loadBalancersClient.EXPECT().
|
||||
Get(gomock.Any(), clusterRGName, infraID, "").
|
||||
Return(fakeLoadBalancersGet(0, api.VisibilityPublic), nil)
|
||||
Get(gomock.Any(), clusterRGName, infraID, nil).
|
||||
Return(sdknetwork.LoadBalancersClientGetResponse{LoadBalancer: fakeLoadBalancersGet(0, api.VisibilityPublic)}, nil)
|
||||
loadBalancersClient.EXPECT().
|
||||
CreateOrUpdateAndWait(ctx, clusterRGName, infraID, fakeUpdatedLoadBalancer(1)).Return(nil)
|
||||
CreateOrUpdateAndWait(ctx, clusterRGName, infraID, fakeUpdatedLoadBalancer(1), nil).Return(nil)
|
||||
publicIPAddressClient.EXPECT().
|
||||
List(gomock.Any(), clusterRGName).
|
||||
List(gomock.Any(), clusterRGName, nil).
|
||||
Return(getFakePublicIPList(1), nil)
|
||||
loadBalancersClient.EXPECT().
|
||||
Get(gomock.Any(), clusterRGName, infraID, "").
|
||||
Return(fakeLoadBalancersGet(1, api.VisibilityPublic), nil)
|
||||
Get(gomock.Any(), clusterRGName, infraID, nil).
|
||||
Return(sdknetwork.LoadBalancersClientGetResponse{LoadBalancer: fakeLoadBalancersGet(1, api.VisibilityPublic)}, nil)
|
||||
},
|
||||
expectedLoadBalancerProfile: &api.LoadBalancerProfile{
|
||||
ManagedOutboundIPs: &api.ManagedOutboundIPs{
|
||||
|
@ -844,24 +846,24 @@ func TestReconcileLoadBalancerProfile(t *testing.T) {
|
|||
},
|
||||
},
|
||||
mocks: func(
|
||||
loadBalancersClient *mock_network.MockLoadBalancersClient,
|
||||
publicIPAddressClient *mock_network.MockPublicIPAddressesClient,
|
||||
loadBalancersClient *mock_armnetwork.MockLoadBalancersClient,
|
||||
publicIPAddressClient *mock_armnetwork.MockPublicIPAddressesClient,
|
||||
ctx context.Context) {
|
||||
publicIPAddressClient.EXPECT().
|
||||
List(gomock.Any(), clusterRGName).
|
||||
List(gomock.Any(), clusterRGName, nil).
|
||||
Return(getFakePublicIPList(1), nil)
|
||||
loadBalancersClient.EXPECT().
|
||||
Get(gomock.Any(), clusterRGName, infraID, "").
|
||||
Return(fakeLoadBalancersGet(1, api.VisibilityPublic), nil)
|
||||
Get(gomock.Any(), clusterRGName, infraID, nil).
|
||||
Return(sdknetwork.LoadBalancersClientGetResponse{LoadBalancer: fakeLoadBalancersGet(1, api.VisibilityPublic)}, nil)
|
||||
loadBalancersClient.EXPECT().
|
||||
CreateOrUpdateAndWait(ctx, clusterRGName, infraID, fakeUpdatedLoadBalancer(0)).Return(nil)
|
||||
CreateOrUpdateAndWait(ctx, clusterRGName, infraID, fakeUpdatedLoadBalancer(0), nil).Return(nil)
|
||||
publicIPAddressClient.EXPECT().
|
||||
List(gomock.Any(), clusterRGName).
|
||||
List(gomock.Any(), clusterRGName, nil).
|
||||
Return(getFakePublicIPList(1), nil)
|
||||
loadBalancersClient.EXPECT().
|
||||
Get(gomock.Any(), clusterRGName, infraID, "").
|
||||
Return(fakeLoadBalancersGet(0, api.VisibilityPublic), nil)
|
||||
publicIPAddressClient.EXPECT().DeleteAndWait(gomock.Any(), "clusterRG", "uuid1-outbound-pip-v4")
|
||||
Get(gomock.Any(), clusterRGName, infraID, nil).
|
||||
Return(sdknetwork.LoadBalancersClientGetResponse{LoadBalancer: fakeLoadBalancersGet(0, api.VisibilityPublic)}, nil)
|
||||
publicIPAddressClient.EXPECT().DeleteAndWait(gomock.Any(), "clusterRG", "uuid1-outbound-pip-v4", nil)
|
||||
},
|
||||
|
||||
expectedLoadBalancerProfile: &api.LoadBalancerProfile{
|
||||
|
@ -913,26 +915,26 @@ func TestReconcileLoadBalancerProfile(t *testing.T) {
|
|||
},
|
||||
},
|
||||
mocks: func(
|
||||
loadBalancersClient *mock_network.MockLoadBalancersClient,
|
||||
publicIPAddressClient *mock_network.MockPublicIPAddressesClient,
|
||||
loadBalancersClient *mock_armnetwork.MockLoadBalancersClient,
|
||||
publicIPAddressClient *mock_armnetwork.MockPublicIPAddressesClient,
|
||||
ctx context.Context) {
|
||||
publicIPAddressClient.EXPECT().
|
||||
List(gomock.Any(), clusterRGName).
|
||||
List(gomock.Any(), clusterRGName, nil).
|
||||
Return(getFakePublicIPList(0), nil)
|
||||
publicIPAddressClient.EXPECT().
|
||||
CreateOrUpdateAndWait(ctx, clusterRGName, "uuid1-outbound-pip-v4", getFakePublicIPAddress("uuid1-outbound-pip-v4", location)).Return(nil)
|
||||
CreateOrUpdateAndWait(ctx, clusterRGName, "uuid1-outbound-pip-v4", getFakePublicIPAddress("uuid1-outbound-pip-v4", location), nil).Return(nil)
|
||||
loadBalancersClient.EXPECT().
|
||||
Get(gomock.Any(), clusterRGName, infraID, "").
|
||||
Return(fakeLoadBalancersGet(0, api.VisibilityPublic), nil)
|
||||
Get(gomock.Any(), clusterRGName, infraID, nil).
|
||||
Return(sdknetwork.LoadBalancersClientGetResponse{LoadBalancer: fakeLoadBalancersGet(0, api.VisibilityPublic)}, nil)
|
||||
loadBalancersClient.EXPECT().
|
||||
CreateOrUpdateAndWait(ctx, clusterRGName, infraID, fakeUpdatedLoadBalancer(1)).Return(fmt.Errorf("lb update failed"))
|
||||
CreateOrUpdateAndWait(ctx, clusterRGName, infraID, fakeUpdatedLoadBalancer(1), nil).Return(fmt.Errorf("lb update failed"))
|
||||
publicIPAddressClient.EXPECT().
|
||||
List(gomock.Any(), clusterRGName).
|
||||
List(gomock.Any(), clusterRGName, nil).
|
||||
Return(getFakePublicIPList(1), nil)
|
||||
loadBalancersClient.EXPECT().
|
||||
Get(gomock.Any(), clusterRGName, infraID, "").
|
||||
Return(fakeLoadBalancersGet(0, api.VisibilityPublic), nil)
|
||||
publicIPAddressClient.EXPECT().DeleteAndWait(gomock.Any(), "clusterRG", "uuid1-outbound-pip-v4")
|
||||
Get(gomock.Any(), clusterRGName, infraID, nil).
|
||||
Return(sdknetwork.LoadBalancersClientGetResponse{LoadBalancer: fakeLoadBalancersGet(0, api.VisibilityPublic)}, nil)
|
||||
publicIPAddressClient.EXPECT().DeleteAndWait(gomock.Any(), "clusterRG", "uuid1-outbound-pip-v4", nil)
|
||||
},
|
||||
expectedLoadBalancerProfile: &api.LoadBalancerProfile{
|
||||
ManagedOutboundIPs: &api.ManagedOutboundIPs{
|
||||
|
@ -989,25 +991,25 @@ func TestReconcileLoadBalancerProfile(t *testing.T) {
|
|||
},
|
||||
},
|
||||
mocks: func(
|
||||
loadBalancersClient *mock_network.MockLoadBalancersClient,
|
||||
publicIPAddressClient *mock_network.MockPublicIPAddressesClient,
|
||||
loadBalancersClient *mock_armnetwork.MockLoadBalancersClient,
|
||||
publicIPAddressClient *mock_armnetwork.MockPublicIPAddressesClient,
|
||||
ctx context.Context) {
|
||||
publicIPAddressClient.EXPECT().
|
||||
List(gomock.Any(), clusterRGName).
|
||||
List(gomock.Any(), clusterRGName, nil).
|
||||
Return(getFakePublicIPList(2), nil)
|
||||
loadBalancersClient.EXPECT().
|
||||
Get(gomock.Any(), clusterRGName, infraID, "").
|
||||
Return(fakeLoadBalancersGet(2, api.VisibilityPublic), nil)
|
||||
Get(gomock.Any(), clusterRGName, infraID, nil).
|
||||
Return(sdknetwork.LoadBalancersClientGetResponse{LoadBalancer: fakeLoadBalancersGet(2, api.VisibilityPublic)}, nil)
|
||||
loadBalancersClient.EXPECT().
|
||||
CreateOrUpdateAndWait(ctx, clusterRGName, infraID, fakeUpdatedLoadBalancer(0)).Return(nil)
|
||||
CreateOrUpdateAndWait(ctx, clusterRGName, infraID, fakeUpdatedLoadBalancer(0), nil).Return(nil)
|
||||
publicIPAddressClient.EXPECT().
|
||||
List(gomock.Any(), clusterRGName).
|
||||
List(gomock.Any(), clusterRGName, nil).
|
||||
Return(getFakePublicIPList(2), nil)
|
||||
loadBalancersClient.EXPECT().
|
||||
Get(gomock.Any(), clusterRGName, infraID, "").
|
||||
Return(fakeLoadBalancersGet(0, api.VisibilityPublic), nil)
|
||||
publicIPAddressClient.EXPECT().DeleteAndWait(gomock.Any(), "clusterRG", "uuid1-outbound-pip-v4").Return(fmt.Errorf("error"))
|
||||
publicIPAddressClient.EXPECT().DeleteAndWait(gomock.Any(), "clusterRG", "uuid2-outbound-pip-v4").Return(fmt.Errorf("error"))
|
||||
Get(gomock.Any(), clusterRGName, infraID, nil).
|
||||
Return(sdknetwork.LoadBalancersClientGetResponse{LoadBalancer: fakeLoadBalancersGet(0, api.VisibilityPublic)}, nil)
|
||||
publicIPAddressClient.EXPECT().DeleteAndWait(gomock.Any(), "clusterRG", "uuid1-outbound-pip-v4", nil).Return(fmt.Errorf("error"))
|
||||
publicIPAddressClient.EXPECT().DeleteAndWait(gomock.Any(), "clusterRG", "uuid2-outbound-pip-v4", nil).Return(fmt.Errorf("error"))
|
||||
},
|
||||
expectedLoadBalancerProfile: &api.LoadBalancerProfile{
|
||||
ManagedOutboundIPs: &api.ManagedOutboundIPs{
|
||||
|
@ -1058,26 +1060,26 @@ func TestReconcileLoadBalancerProfile(t *testing.T) {
|
|||
},
|
||||
},
|
||||
mocks: func(
|
||||
loadBalancersClient *mock_network.MockLoadBalancersClient,
|
||||
publicIPAddressClient *mock_network.MockPublicIPAddressesClient,
|
||||
loadBalancersClient *mock_armnetwork.MockLoadBalancersClient,
|
||||
publicIPAddressClient *mock_armnetwork.MockPublicIPAddressesClient,
|
||||
ctx context.Context) {
|
||||
publicIPAddressClient.EXPECT().
|
||||
List(gomock.Any(), clusterRGName).
|
||||
List(gomock.Any(), clusterRGName, nil).
|
||||
Return(getFakePublicIPList(0), nil)
|
||||
publicIPAddressClient.EXPECT().
|
||||
CreateOrUpdateAndWait(ctx, clusterRGName, "uuid1-outbound-pip-v4", getFakePublicIPAddress("uuid1-outbound-pip-v4", location)).Return(nil)
|
||||
CreateOrUpdateAndWait(ctx, clusterRGName, "uuid1-outbound-pip-v4", getFakePublicIPAddress("uuid1-outbound-pip-v4", location), nil).Return(nil)
|
||||
publicIPAddressClient.EXPECT().
|
||||
CreateOrUpdateAndWait(ctx, clusterRGName, "uuid2-outbound-pip-v4", getFakePublicIPAddress("uuid2-outbound-pip-v4", location)).Return(fmt.Errorf("failed to create ip"))
|
||||
CreateOrUpdateAndWait(ctx, clusterRGName, "uuid2-outbound-pip-v4", getFakePublicIPAddress("uuid2-outbound-pip-v4", location), nil).Return(fmt.Errorf("failed to create ip"))
|
||||
loadBalancersClient.EXPECT().
|
||||
Get(gomock.Any(), clusterRGName, infraID, "").
|
||||
Return(fakeLoadBalancersGet(0, api.VisibilityPublic), nil)
|
||||
Get(gomock.Any(), clusterRGName, infraID, nil).
|
||||
Return(sdknetwork.LoadBalancersClientGetResponse{LoadBalancer: fakeLoadBalancersGet(0, api.VisibilityPublic)}, nil)
|
||||
publicIPAddressClient.EXPECT().
|
||||
List(gomock.Any(), clusterRGName).
|
||||
List(gomock.Any(), clusterRGName, nil).
|
||||
Return(getFakePublicIPList(1), nil)
|
||||
loadBalancersClient.EXPECT().
|
||||
Get(gomock.Any(), clusterRGName, infraID, "").
|
||||
Return(fakeLoadBalancersGet(0, api.VisibilityPublic), nil)
|
||||
publicIPAddressClient.EXPECT().DeleteAndWait(gomock.Any(), "clusterRG", "uuid1-outbound-pip-v4").Return(fmt.Errorf("error"))
|
||||
Get(gomock.Any(), clusterRGName, infraID, nil).
|
||||
Return(sdknetwork.LoadBalancersClientGetResponse{LoadBalancer: fakeLoadBalancersGet(0, api.VisibilityPublic)}, nil)
|
||||
publicIPAddressClient.EXPECT().DeleteAndWait(gomock.Any(), "clusterRG", "uuid1-outbound-pip-v4", nil).Return(fmt.Errorf("error"))
|
||||
},
|
||||
expectedLoadBalancerProfile: &api.LoadBalancerProfile{
|
||||
ManagedOutboundIPs: &api.ManagedOutboundIPs{
|
||||
|
@ -1107,14 +1109,14 @@ func TestReconcileLoadBalancerProfile(t *testing.T) {
|
|||
uuid.DefaultGenerator = uuidfake.NewGenerator(tt.uuids)
|
||||
controller := gomock.NewController(t)
|
||||
defer controller.Finish()
|
||||
loadBalancersClient := mock_network.NewMockLoadBalancersClient(controller)
|
||||
publicIPAddressClient := mock_network.NewMockPublicIPAddressesClient(controller)
|
||||
loadBalancersClient := mock_armnetwork.NewMockLoadBalancersClient(controller)
|
||||
publicIPAddressClient := mock_armnetwork.NewMockPublicIPAddressesClient(controller)
|
||||
|
||||
if tt.mocks != nil {
|
||||
tt.mocks(loadBalancersClient, publicIPAddressClient, ctx)
|
||||
}
|
||||
tt.m.loadBalancers = loadBalancersClient
|
||||
tt.m.publicIPAddresses = publicIPAddressClient
|
||||
tt.m.armLoadBalancers = loadBalancersClient
|
||||
tt.m.armPublicIPAddresses = publicIPAddressClient
|
||||
|
||||
// Run reconcileLoadBalancerProfile and assert the correct results
|
||||
err = tt.m.reconcileLoadBalancerProfile(ctx)
|
||||
|
@ -1129,18 +1131,18 @@ func TestReconcileLoadBalancerProfile(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func getFakePublicIPAddress(name, location string) mgmtnetwork.PublicIPAddress {
|
||||
func getFakePublicIPAddress(name, location string) sdknetwork.PublicIPAddress {
|
||||
id := fmt.Sprintf("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/publicIPAddresses/%s", name)
|
||||
return mgmtnetwork.PublicIPAddress{
|
||||
return sdknetwork.PublicIPAddress{
|
||||
Name: &name,
|
||||
ID: &id,
|
||||
Location: to.StringPtr(location),
|
||||
PublicIPAddressPropertiesFormat: &mgmtnetwork.PublicIPAddressPropertiesFormat{
|
||||
PublicIPAllocationMethod: mgmtnetwork.Static,
|
||||
PublicIPAddressVersion: mgmtnetwork.IPv4,
|
||||
Location: ptr.To(location),
|
||||
Properties: &sdknetwork.PublicIPAddressPropertiesFormat{
|
||||
PublicIPAllocationMethod: ptr.To(sdknetwork.IPAllocationMethodStatic),
|
||||
PublicIPAddressVersion: ptr.To(sdknetwork.IPVersionIPv4),
|
||||
},
|
||||
Sku: &mgmtnetwork.PublicIPAddressSku{
|
||||
Name: mgmtnetwork.PublicIPAddressSkuNameStandard,
|
||||
SKU: &sdknetwork.PublicIPAddressSKU{
|
||||
Name: ptr.To(sdknetwork.PublicIPAddressSKUNameStandard),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -1149,7 +1151,7 @@ func getFakePublicIPAddress(name, location string) mgmtnetwork.PublicIPAddress {
|
|||
// It is assumed that desired IPs include the default outbound IPs, however this won't work for transitions from
|
||||
// customer provided IPs/Prefixes to managed IPs if the api server is private since the default IP
|
||||
// would be deleted
|
||||
func fakeUpdatedLoadBalancer(additionalIPCount int) mgmtnetwork.LoadBalancer {
|
||||
func fakeUpdatedLoadBalancer(additionalIPCount int) sdknetwork.LoadBalancer {
|
||||
clusterRGID := "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG"
|
||||
defaultOutboundIPID := "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/publicIPAddresses/infraID-pip-v4"
|
||||
lb := getClearedLB()
|
||||
|
@ -1163,56 +1165,56 @@ func fakeUpdatedLoadBalancer(additionalIPCount int) mgmtnetwork.LoadBalancer {
|
|||
}
|
||||
|
||||
// Returns lb as it would be returned via m.loadBalancersClient.Get.
|
||||
func fakeLoadBalancersGet(additionalIPCount int, apiServerVisibility api.Visibility) mgmtnetwork.LoadBalancer {
|
||||
defaultOutboundFIPConfig := mgmtnetwork.FrontendIPConfiguration{
|
||||
Name: to.StringPtr("public-lb-ip-v4"),
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/public-lb-ip-v4"),
|
||||
FrontendIPConfigurationPropertiesFormat: &mgmtnetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
OutboundRules: &[]mgmtnetwork.SubResource{{
|
||||
ID: to.StringPtr(outboundRuleV4),
|
||||
func fakeLoadBalancersGet(additionalIPCount int, apiServerVisibility api.Visibility) sdknetwork.LoadBalancer {
|
||||
defaultOutboundFIPConfig := sdknetwork.FrontendIPConfiguration{
|
||||
Name: ptr.To("public-lb-ip-v4"),
|
||||
ID: ptr.To("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/public-lb-ip-v4"),
|
||||
Properties: &sdknetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
OutboundRules: []*sdknetwork.SubResource{{
|
||||
ID: ptr.To(outboundRuleV4),
|
||||
}},
|
||||
PublicIPAddress: &mgmtnetwork.PublicIPAddress{
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/publicIPAddresses/infraID-pip-v4"),
|
||||
PublicIPAddress: &sdknetwork.PublicIPAddress{
|
||||
ID: ptr.To("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/publicIPAddresses/infraID-pip-v4"),
|
||||
},
|
||||
},
|
||||
}
|
||||
if apiServerVisibility == api.VisibilityPublic {
|
||||
defaultOutboundFIPConfig.FrontendIPConfigurationPropertiesFormat.LoadBalancingRules = &[]mgmtnetwork.SubResource{
|
||||
defaultOutboundFIPConfig.Properties.LoadBalancingRules = []*sdknetwork.SubResource{
|
||||
{
|
||||
ID: to.StringPtr("api-internal-v4"),
|
||||
ID: ptr.To("api-internal-v4"),
|
||||
},
|
||||
}
|
||||
}
|
||||
lb := mgmtnetwork.LoadBalancer{
|
||||
Name: to.StringPtr("infraID"),
|
||||
LoadBalancerPropertiesFormat: &mgmtnetwork.LoadBalancerPropertiesFormat{
|
||||
FrontendIPConfigurations: &[]mgmtnetwork.FrontendIPConfiguration{
|
||||
lb := sdknetwork.LoadBalancer{
|
||||
Name: ptr.To("infraID"),
|
||||
Properties: &sdknetwork.LoadBalancerPropertiesFormat{
|
||||
FrontendIPConfigurations: []*sdknetwork.FrontendIPConfiguration{
|
||||
{
|
||||
Name: to.StringPtr("ae3506385907e44eba9ef9bf76eac973"),
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/ae3506385907e44eba9ef9bf76eac973"),
|
||||
FrontendIPConfigurationPropertiesFormat: &mgmtnetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
LoadBalancingRules: &[]mgmtnetwork.SubResource{
|
||||
Name: ptr.To("ae3506385907e44eba9ef9bf76eac973"),
|
||||
ID: ptr.To("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/ae3506385907e44eba9ef9bf76eac973"),
|
||||
Properties: &sdknetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
LoadBalancingRules: []*sdknetwork.SubResource{
|
||||
{
|
||||
ID: to.StringPtr("ae3506385907e44eba9ef9bf76eac973-TCP-80"),
|
||||
ID: ptr.To("ae3506385907e44eba9ef9bf76eac973-TCP-80"),
|
||||
},
|
||||
{
|
||||
ID: to.StringPtr("ae3506385907e44eba9ef9bf76eac973-TCP-443"),
|
||||
ID: ptr.To("ae3506385907e44eba9ef9bf76eac973-TCP-443"),
|
||||
},
|
||||
},
|
||||
PublicIPAddress: &mgmtnetwork.PublicIPAddress{
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/publicIPAddresses/infraID-default-v4"),
|
||||
PublicIPAddress: &sdknetwork.PublicIPAddress{
|
||||
ID: ptr.To("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/publicIPAddresses/infraID-default-v4"),
|
||||
},
|
||||
},
|
||||
},
|
||||
defaultOutboundFIPConfig,
|
||||
&defaultOutboundFIPConfig,
|
||||
},
|
||||
OutboundRules: &[]mgmtnetwork.OutboundRule{
|
||||
OutboundRules: []*sdknetwork.OutboundRule{
|
||||
{
|
||||
Name: to.StringPtr(outboundRuleV4),
|
||||
OutboundRulePropertiesFormat: &mgmtnetwork.OutboundRulePropertiesFormat{
|
||||
FrontendIPConfigurations: &[]mgmtnetwork.SubResource{
|
||||
Name: ptr.To(outboundRuleV4),
|
||||
Properties: &sdknetwork.OutboundRulePropertiesFormat{
|
||||
FrontendIPConfigurations: []*sdknetwork.SubResource{
|
||||
{
|
||||
ID: to.StringPtr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/public-lb-ip-v4"),
|
||||
ID: ptr.To("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/public-lb-ip-v4"),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -1224,49 +1226,50 @@ func fakeLoadBalancersGet(additionalIPCount int, apiServerVisibility api.Visibil
|
|||
fipName := fmt.Sprintf("uuid%d-outbound-pip-v4", i+1)
|
||||
ipID := fmt.Sprintf("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/publicIPAddresses/uuid%d-outbound-pip-v4", i+1)
|
||||
fipID := fmt.Sprintf("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG/providers/Microsoft.Network/loadBalancers/infraID/frontendIPConfigurations/uuid%d-outbound-pip-v4", i+1)
|
||||
fipConfig := mgmtnetwork.FrontendIPConfiguration{
|
||||
fipConfig := &sdknetwork.FrontendIPConfiguration{
|
||||
Name: &fipName,
|
||||
ID: &fipID,
|
||||
FrontendIPConfigurationPropertiesFormat: &mgmtnetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
OutboundRules: &[]mgmtnetwork.SubResource{{
|
||||
ID: to.StringPtr(outboundRuleV4),
|
||||
Properties: &sdknetwork.FrontendIPConfigurationPropertiesFormat{
|
||||
OutboundRules: []*sdknetwork.SubResource{{
|
||||
ID: ptr.To(outboundRuleV4),
|
||||
}},
|
||||
PublicIPAddress: &mgmtnetwork.PublicIPAddress{
|
||||
PublicIPAddress: &sdknetwork.PublicIPAddress{
|
||||
ID: &ipID,
|
||||
},
|
||||
},
|
||||
}
|
||||
*lb.LoadBalancerPropertiesFormat.FrontendIPConfigurations = append(*lb.LoadBalancerPropertiesFormat.FrontendIPConfigurations, fipConfig)
|
||||
outboundRules := *lb.LoadBalancerPropertiesFormat.OutboundRules
|
||||
*outboundRules[0].FrontendIPConfigurations = append(*outboundRules[0].FrontendIPConfigurations, mgmtnetwork.SubResource{ID: fipConfig.ID})
|
||||
lb.Properties.FrontendIPConfigurations = append(lb.Properties.FrontendIPConfigurations, fipConfig)
|
||||
outboundRules := lb.Properties.OutboundRules
|
||||
outboundRules[0].Properties.FrontendIPConfigurations = append(outboundRules[0].Properties.FrontendIPConfigurations, &sdknetwork.SubResource{ID: fipConfig.ID})
|
||||
}
|
||||
return lb
|
||||
}
|
||||
|
||||
func getClearedLB() mgmtnetwork.LoadBalancer {
|
||||
func getClearedLB() sdknetwork.LoadBalancer {
|
||||
lb := fakeLoadBalancersGet(0, api.VisibilityPublic)
|
||||
removeOutboundIPsFromLB(lb)
|
||||
return lb
|
||||
}
|
||||
|
||||
func getFakePublicIPList(managedCount int) []mgmtnetwork.PublicIPAddress {
|
||||
func getFakePublicIPList(managedCount int) []*sdknetwork.PublicIPAddress {
|
||||
infraID := "infraID"
|
||||
clusterRGID := "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clusterRG"
|
||||
defaultOutboundIPName := infraID + "-pip-v4"
|
||||
defaultOutboundIPID := clusterRGID + "/providers/Microsoft.Network/publicIPAddresses/" + defaultOutboundIPName
|
||||
ips := []mgmtnetwork.PublicIPAddress{
|
||||
ips := []*sdknetwork.PublicIPAddress{
|
||||
{
|
||||
ID: &defaultOutboundIPID,
|
||||
Name: &defaultOutboundIPName,
|
||||
},
|
||||
{
|
||||
ID: to.StringPtr(clusterRGID + "/providers/Microsoft.Network/publicIPAddresses/infraID-default-v4"),
|
||||
Name: to.StringPtr("infraID-default-v4"),
|
||||
ID: ptr.To(clusterRGID + "/providers/Microsoft.Network/publicIPAddresses/infraID-default-v4"),
|
||||
Name: ptr.To("infraID-default-v4"),
|
||||
},
|
||||
}
|
||||
for i := 0; i < managedCount; i++ {
|
||||
ipName := fmt.Sprintf("uuid%d-outbound-pip-v4", i+1)
|
||||
ips = append(ips, getFakePublicIPAddress(ipName, "eastus"))
|
||||
ip := getFakePublicIPAddress(ipName, "eastus")
|
||||
ips = append(ips, &ip)
|
||||
}
|
||||
return ips
|
||||
}
|
||||
|
|
|
@ -40,6 +40,10 @@ type Resource struct {
|
|||
Tags map[string]interface{} `json:"tags,omitempty"`
|
||||
Copy *Copy `json:"copy,omitempty"`
|
||||
Comments string `json:"comments,omitempty"`
|
||||
// Etag is required to omit Etag member when it's not set.
|
||||
// arm* SDK uses its own MarshalJSON, and empty members are converted to nil,
|
||||
// but Etag: nil fails the ARM template validation.
|
||||
Etag string `json:"etag,omitempty"`
|
||||
}
|
||||
|
||||
// Deployment represents a nested ARM deployment in a deployment
|
||||
|
|
Загрузка…
Ссылка в новой задаче