Skip to content

Commit 3d40286

Browse files
committed
OCPBUGS-33234: azure: bump profile used for network
It seems Azure has added support for multiple address prefixes for a subnet. This means that getting subnet details might return only `addressPrefixes` while `addressPrefix` is `nil`. In such cases, the Installer will fail with a SIGSEGV: ``` $ ../openshift-install create manifests --dir . INFO Credentials loaded from file "/root/.azure/osServicePrincipal.json" panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x2f7d2e9] goroutine 1 [running]: github.com/openshift/installer/pkg/asset/installconfig/azure.validateSubnet({0xc000e1ade8?, 0x237b46b8?}, 0xc000122018?, 0xc000abee40, {0xc000e29d40, 0x28}, {0xc000001080, 0x1, 0x4}) /go/src/github.com/openshift/installer/pkg/asset/installconfig/azure/validation.go:529 +0x69 github.com/openshift/installer/pkg/asset/installconfig/azure.validateNetworks({0x237e1268, 0xc000015f78}, 0xc0000ced00, {0xc000001080, 0x1, 0x4}, 0xc000a4cde0) /go/src/github.com/openshift/installer/pkg/asset/installconfig/azure/validation.go:512 +0x2ff [...] ``` Let's bump the profile version used from 2018-03-01 to 2020-09-01 so we can have access to both properties and select the appropriate one.
1 parent 0360da3 commit 3d40286

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

pkg/asset/installconfig/azure/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77
"strings"
88
"time"
99

10-
aznetwork "github.com/Azure/azure-sdk-for-go/profiles/2018-03-01/network/mgmt/network"
1110
azres "github.com/Azure/azure-sdk-for-go/profiles/2018-03-01/resources/mgmt/resources"
1211
azsubs "github.com/Azure/azure-sdk-for-go/profiles/2018-03-01/resources/mgmt/subscriptions"
12+
aznetwork "github.com/Azure/azure-sdk-for-go/profiles/2020-09-01/network/mgmt/network"
1313
azenc "github.com/Azure/azure-sdk-for-go/profiles/latest/compute/mgmt/compute"
1414
azmarketplace "github.com/Azure/azure-sdk-for-go/profiles/latest/marketplaceordering/mgmt/marketplaceordering"
1515
"github.com/Azure/go-autorest/autorest/to"

pkg/asset/installconfig/azure/mock/azureclient_generated.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/asset/installconfig/azure/validation.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"strings"
1111

1212
azdns "github.com/Azure/azure-sdk-for-go/profiles/2018-03-01/dns/mgmt/dns"
13-
aznetwork "github.com/Azure/azure-sdk-for-go/profiles/2018-03-01/network/mgmt/network"
13+
aznetwork "github.com/Azure/azure-sdk-for-go/profiles/2020-09-01/network/mgmt/network"
1414
azenc "github.com/Azure/azure-sdk-for-go/profiles/latest/compute/mgmt/compute"
1515
"github.com/Azure/go-autorest/autorest/to"
1616
"github.com/sirupsen/logrus"
@@ -526,7 +526,19 @@ func validateNetworks(client API, p *aztypes.Platform, machineNetworks []types.M
526526
func validateSubnet(client API, fieldPath *field.Path, subnet *aznetwork.Subnet, subnetName string, networks []types.MachineNetworkEntry) field.ErrorList {
527527
allErrs := field.ErrorList{}
528528

529-
subnetIP, _, err := net.ParseCIDR(*subnet.AddressPrefix)
529+
var addressPrefix string
530+
switch {
531+
case subnet.AddressPrefix != nil:
532+
addressPrefix = *subnet.AddressPrefix
533+
// NOTE: if the subscription has the `AllowMultipleAddressPrefixesOnSubnet` feature, the Azure API will return a
534+
// `addressPrefixes` field with a slice of addresses instead of a single value via `addressPrefix`.
535+
case subnet.AddressPrefixes != nil && len(*subnet.AddressPrefixes) > 0:
536+
addressPrefix = (*subnet.AddressPrefixes)[0]
537+
default:
538+
return append(allErrs, field.Invalid(fieldPath, subnetName, "subnet does not have an address prefix"))
539+
}
540+
541+
subnetIP, _, err := net.ParseCIDR(addressPrefix)
530542
if err != nil {
531543
return append(allErrs, field.Invalid(fieldPath, subnetName, "unable to parse subnet CIDR"))
532544
}

pkg/asset/installconfig/azure/validation_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import (
55
"net"
66
"testing"
77

8-
aznetwork "github.com/Azure/azure-sdk-for-go/profiles/2018-03-01/network/mgmt/network"
98
azres "github.com/Azure/azure-sdk-for-go/profiles/2018-03-01/resources/mgmt/resources"
109
azsubs "github.com/Azure/azure-sdk-for-go/profiles/2018-03-01/resources/mgmt/subscriptions"
10+
aznetwork "github.com/Azure/azure-sdk-for-go/profiles/2020-09-01/network/mgmt/network"
1111
azenc "github.com/Azure/azure-sdk-for-go/profiles/latest/compute/mgmt/compute"
1212
"github.com/Azure/go-autorest/autorest/to"
1313
"github.com/golang/mock/gomock"

0 commit comments

Comments
 (0)