Skip to content

Commit 31ffc34

Browse files
fix: use subnet name in subnet lookup (#639)
1 parent c47105f commit 31ffc34

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

pkg/azure/client.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,13 @@ func (az *azClient) DeployGatewayWithVnet(resourceGroupName ResourceGroup, vnetN
137137
}
138138

139139
glog.Infof("Checking the Vnet %s for a subnet with prefix %s", vnetName, subnetPrefix)
140-
subnet, err := az.findSubnet(vnet, subnetPrefix)
140+
subnet, err := az.findSubnet(vnet, subnetName, subnetPrefix)
141141
if err != nil {
142+
if subnetPrefix == "" {
143+
glog.Infof("Unable to find a subnet with subnetName %s. Please provide subnetPrefix in order to allow AGIC to create a subnet in Vnet %s", subnetName, vnetName)
144+
return
145+
}
146+
142147
glog.Infof("Unable to find a subnet. Creating a subnet %s with prefix %s in Vnet %s", subnetName, subnetPrefix, vnetName)
143148
subnet, err = az.createSubnet(vnet, subnetName, subnetPrefix)
144149
if err != nil {
@@ -185,13 +190,13 @@ func (az *azClient) getVnet(resourceGroupName ResourceGroup, vnetName ResourceNa
185190
return az.virtualNetworksClient.Get(az.ctx, string(resourceGroupName), string(vnetName), "")
186191
}
187192

188-
func (az *azClient) findSubnet(vnet n.VirtualNetwork, subnetPrefix string) (subnet n.Subnet, err error) {
193+
func (az *azClient) findSubnet(vnet n.VirtualNetwork, subnetName ResourceName, subnetPrefix string) (subnet n.Subnet, err error) {
189194
for _, subnet := range *vnet.Subnets {
190-
if *subnet.AddressPrefix == subnetPrefix {
195+
if string(subnetName) == *subnet.Name && (subnetPrefix == "" || subnetPrefix == *subnet.AddressPrefix) {
191196
return subnet, nil
192197
}
193198
}
194-
err = errors.New("Unable to find subnet")
199+
err = errors.New("Unable to find subnet with matching subnetName and subnetPrefix")
195200
return
196201
}
197202

0 commit comments

Comments
 (0)