Skip to content

Commit

Permalink
fix: subnet update issue when vnetResourceGroup is specified
Browse files Browse the repository at this point in the history
  • Loading branch information
andyzhangx authored and k8s-infra-cherrypick-robot committed Aug 1, 2024
1 parent 5c2a650 commit 571b789
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pkg/provider/azure_loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2324,7 +2324,7 @@ func (az *Cloud) reconcileFrontendIPConfigs(clusterName string,
if subnetName == nil {
subnetName = &az.SubnetName
}
subnet, existsSubnet, err = az.getSubnet(az.VnetName, *subnetName)
subnet, existsSubnet, err = az.getSubnet("", az.VnetName, *subnetName)
if err != nil {
return nil, toDeleteConfigs, false, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/provider/azure_privatelinkservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (az *Cloud) disablePLSNetworkPolicy(service *v1.Service) error {
subnetName = &az.SubnetName
}

subnet, existsSubnet, err := az.getSubnet(az.VnetName, *subnetName)
subnet, existsSubnet, err := az.getSubnet("", az.VnetName, *subnetName)
if err != nil {
return err
}
Expand Down Expand Up @@ -352,7 +352,7 @@ func (az *Cloud) reconcilePLSIpConfigs(
if subnetName == nil {
subnetName = &az.SubnetName
}
subnet, existsSubnet, err := az.getSubnet(az.VnetName, *subnetName)
subnet, existsSubnet, err := az.getSubnet("", az.VnetName, *subnetName)
if err != nil {
return false, err
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/provider/azure_storageaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ func (az *Cloud) EnsureStorageAccount(ctx context.Context, accountOptions *Accou
func (az *Cloud) createPrivateEndpoint(ctx context.Context, accountName string, accountID *string, privateEndpointName, vnetResourceGroup, vnetName, subnetName, location string, storageType StorageType) error {
klog.V(2).Infof("Creating private endpoint(%s) for account (%s)", privateEndpointName, accountName)

subnet, _, err := az.getSubnet(vnetName, subnetName)
subnet, _, err := az.getSubnet(vnetResourceGroup, vnetName, subnetName)
if err != nil {
return err
}
Expand All @@ -608,6 +608,7 @@ func (az *Cloud) createPrivateEndpoint(ctx context.Context, accountName string,
// Disable the private endpoint network policies before creating private endpoint
subnet.SubnetPropertiesFormat.PrivateEndpointNetworkPolicies = network.VirtualNetworkPrivateEndpointNetworkPoliciesDisabled
}

if rerr := az.SubnetsClient.CreateOrUpdate(ctx, vnetResourceGroup, vnetName, subnetName, subnet); rerr != nil {
return rerr.Error()
}
Expand Down
15 changes: 8 additions & 7 deletions pkg/provider/azure_subnet_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,18 @@ func (az *Cloud) CreateOrUpdateSubnet(service *v1.Service, subnet network.Subnet
return nil
}

func (az *Cloud) getSubnet(virtualNetworkName string, subnetName string) (network.Subnet, bool, error) {
var rg string
if len(az.VnetResourceGroup) > 0 {
rg = az.VnetResourceGroup
} else {
rg = az.ResourceGroup
func (az *Cloud) getSubnet(vnetResourceGroup, virtualNetworkName, subnetName string) (network.Subnet, bool, error) {
if vnetResourceGroup == "" {
if len(az.VnetResourceGroup) > 0 {
vnetResourceGroup = az.VnetResourceGroup
} else {
vnetResourceGroup = az.ResourceGroup
}
}

ctx, cancel := getContextWithCancel()
defer cancel()
subnet, err := az.SubnetsClient.Get(ctx, rg, virtualNetworkName, subnetName, "")
subnet, err := az.SubnetsClient.Get(ctx, vnetResourceGroup, virtualNetworkName, subnetName, "")
exists, rerr := checkResourceExistsFromError(err)
if rerr != nil {
return subnet, false, rerr.Error()
Expand Down

0 comments on commit 571b789

Please sign in to comment.