From 8fcd80e0d1a06e02ac66778f7f59eae64580787a Mon Sep 17 00:00:00 2001 From: Matthew Christopher Date: Thu, 15 Jul 2021 16:35:38 -0700 Subject: [PATCH] Fix possible VNET panic --- pkg/resourcemanager/vnet/reconcile.go | 11 ++++++----- pkg/resourcemanager/vnet/vnet.go | 12 ++++++------ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/pkg/resourcemanager/vnet/reconcile.go b/pkg/resourcemanager/vnet/reconcile.go index 4d1107d5f65..5eea341541a 100644 --- a/pkg/resourcemanager/vnet/reconcile.go +++ b/pkg/resourcemanager/vnet/reconcile.go @@ -10,13 +10,14 @@ import ( "strings" "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-09-01/network" + "github.com/pkg/errors" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/types" + azurev1alpha1 "github.com/Azure/azure-service-operator/api/v1alpha1" "github.com/Azure/azure-service-operator/pkg/errhelp" "github.com/Azure/azure-service-operator/pkg/helpers" "github.com/Azure/azure-service-operator/pkg/resourcemanager" - "github.com/pkg/errors" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/types" ) // Ensure makes sure that an VNet instance exists @@ -49,7 +50,7 @@ func (g *AzureVNetManager) Ensure(ctx context.Context, obj runtime.Object, opts } instance.Status.Provisioning = true - result, err := g.CreateVNet( + _, err = g.CreateVNet( ctx, location, resourceGroup, @@ -61,7 +62,7 @@ func (g *AzureVNetManager) Ensure(ctx context.Context, obj runtime.Object, opts azerr := errhelp.NewAzureError(err) instance.Status.Message = err.Error() - if result.Response.Response != nil && result.Response.Response.StatusCode == http.StatusBadRequest { + if azerr.Code == http.StatusBadRequest { instance.Status.Provisioning = false return true, nil } diff --git a/pkg/resourcemanager/vnet/vnet.go b/pkg/resourcemanager/vnet/vnet.go index e50b9e10980..cfbf2e2dcdf 100644 --- a/pkg/resourcemanager/vnet/vnet.go +++ b/pkg/resourcemanager/vnet/vnet.go @@ -9,12 +9,13 @@ import ( "net" vnetwork "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-09-01/network" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/to" + azurev1alpha1 "github.com/Azure/azure-service-operator/api/v1alpha1" "github.com/Azure/azure-service-operator/pkg/resourcemanager/config" "github.com/Azure/azure-service-operator/pkg/resourcemanager/iam" "github.com/Azure/azure-service-operator/pkg/telemetry" - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/to" ) // AzureVNetManager is the struct that the manager functions hang off @@ -63,7 +64,8 @@ func (m *AzureVNetManager) CreateVNet(ctx context.Context, location string, reso subnetsToAdd = append(subnetsToAdd, s) } - future, err := client.CreateOrUpdate( + var future vnetwork.VirtualNetworksCreateOrUpdateFuture + future, err = client.CreateOrUpdate( ctx, resourceGroupName, resourceName, @@ -78,9 +80,7 @@ func (m *AzureVNetManager) CreateVNet(ctx context.Context, location string, reso }, ) if err != nil { - return vnetwork.VirtualNetwork{ - Response: autorest.Response{Response: future.Response()}, - }, err + return vnetwork.VirtualNetwork{}, err } return future.Result(client)