@@ -3,22 +3,22 @@ package cloudprovider
33import (
44 "context"
55 "fmt"
6- "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
7- "k8s.io/utils/ptr"
86 "net"
97 "os"
108 "strings"
119 "sync"
1210 "time"
1311
12+ "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
13+ "k8s.io/utils/ptr"
14+
1415 "github.com/Azure/azure-sdk-for-go/sdk/azcore"
1516 "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
1617 "github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud"
1718 "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
1819 "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
1920 "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute"
2021 "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6"
21- "github.com/Azure/go-autorest/autorest/azure"
2222 azureapi "github.com/Azure/go-autorest/autorest/azure"
2323 "github.com/Azure/msi-dataplane/pkg/dataplane"
2424 v1 "github.com/openshift/api/cloudnetwork/v1"
@@ -44,7 +44,7 @@ type Azure struct {
4444 CloudProvider
4545 platformStatus * configv1.AzurePlatformStatus
4646 resourceGroup string
47- env azure .Environment
47+ env azureapi .Environment
4848 vmClient * armcompute.VirtualMachinesClient
4949 virtualNetworkClient * armnetwork.VirtualNetworksClient
5050 networkClient * armnetwork.InterfacesClient
@@ -124,13 +124,13 @@ func (a *Azure) initCredentials() error {
124124
125125 // Pick the Azure "Environment", which is just a named set of API endpoints.
126126 if a .cfg .APIOverride != "" {
127- a .env , err = azure .EnvironmentFromURL (a .cfg .APIOverride )
127+ a .env , err = azureapi .EnvironmentFromURL (a .cfg .APIOverride )
128128 } else {
129129 name := a .cfg .AzureEnvironment
130130 if name == "" {
131131 name = "AzurePublicCloud"
132132 }
133- a .env , err = azure .EnvironmentFromName (name )
133+ a .env , err = azureapi .EnvironmentFromName (name )
134134 }
135135 if err != nil {
136136 return fmt .Errorf ("failed to initialize Azure environment: %w" , err )
@@ -223,13 +223,13 @@ OuterLoop:
223223 if err != nil {
224224 return fmt .Errorf ("error looking up backend address pool %s with ID %s: %v" , ptr .Deref (pool .Name , "" ), ptr .Deref (pool .ID , "" ), err )
225225 }
226- if realPool . Properties . LoadBalancerBackendAddresses != nil && len (realPool .Properties .LoadBalancerBackendAddresses ) > 0 {
226+ if len (realPool .Properties .LoadBalancerBackendAddresses ) > 0 {
227227 if realPool .Properties .OutboundRule != nil {
228228 loadBalancerBackendAddressPoolsArgument = nil
229229 attachedOutboundRule = realPool .Properties .OutboundRule
230230 break OuterLoop
231231 }
232- if realPool . Properties . OutboundRules != nil && len (realPool .Properties .OutboundRules ) > 0 {
232+ if len (realPool .Properties .OutboundRules ) > 0 {
233233 loadBalancerBackendAddressPoolsArgument = nil
234234 attachedOutboundRule = (realPool .Properties .OutboundRules )[0 ]
235235 break OuterLoop
@@ -447,7 +447,7 @@ func (a *Azure) getNetworkInterfaces(instance *armcompute.VirtualMachine) ([]arm
447447 if instance .Properties == nil || instance .Properties .NetworkProfile == nil {
448448 return nil , NoNetworkInterfaceError
449449 }
450- if instance . Properties . NetworkProfile . NetworkInterfaces == nil || len (instance .Properties .NetworkProfile .NetworkInterfaces ) == 0 {
450+ if len (instance .Properties .NetworkProfile .NetworkInterfaces ) == 0 {
451451 return nil , NoNetworkInterfaceError
452452 }
453453 networkInterfaces := []armnetwork.Interface {}
@@ -577,17 +577,23 @@ func (a *Azure) getAddressPrefixes(networkInterface armnetwork.Interface) ([]*st
577577 // FIXME: This might not work for IPv6.
578578 if virtualNetwork .Properties != nil && virtualNetwork .Properties .Subnets != nil {
579579 for _ , vns := range virtualNetwork .Properties .Subnets {
580- if vns .Name != nil && vns .Properties .AddressPrefix != nil &&
581- ptr .Deref (vns .Name , "" ) == subnetName {
582- return []* string {vns .Properties .AddressPrefix }, nil
580+ if vns .Name != nil && ptr .Deref (vns .Name , "" ) == subnetName {
581+ if vns .Properties .AddressPrefix != nil {
582+ return []* string {vns .Properties .AddressPrefix }, nil
583+ }
584+ // In some cases, addressPrefixes is set with single element.
585+ // so use it when addressPrefix is not available.
586+ if len (vns .Properties .AddressPrefixes ) > 0 {
587+ return vns .Properties .AddressPrefixes , nil
588+ }
583589 }
584590 }
585591 }
586592
587593 if virtualNetwork .Properties .AddressSpace == nil {
588594 return nil , fmt .Errorf ("nil subnet address space" )
589595 }
590- if virtualNetwork . Properties . AddressSpace . AddressPrefixes == nil || len (virtualNetwork .Properties .AddressSpace .AddressPrefixes ) == 0 {
596+ if len (virtualNetwork .Properties .AddressSpace .AddressPrefixes ) == 0 {
591597 return nil , fmt .Errorf ("no subnet address prefixes defined" )
592598 }
593599 return virtualNetwork .Properties .AddressSpace .AddressPrefixes , nil
@@ -668,11 +674,11 @@ func getNameFromResourceID(id string) string {
668674func ParseCloudEnvironment (env azureapi.Environment ) cloud.Configuration {
669675 var cloudConfig cloud.Configuration
670676 switch env {
671- case azure .ChinaCloud :
677+ case azureapi .ChinaCloud :
672678 cloudConfig = cloud .AzureChina
673- case azure .USGovernmentCloud :
679+ case azureapi .USGovernmentCloud :
674680 cloudConfig = cloud .AzureGovernment
675- case azure .PublicCloud :
681+ case azureapi .PublicCloud :
676682 cloudConfig = cloud .AzurePublic
677683 default : // AzureStackCloud
678684 cloudConfig = cloud.Configuration {
0 commit comments