Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix possible VNET panic #1652

Merged
merged 1 commit into from
Jul 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions pkg/resourcemanager/vnet/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/resourcemanager/vnet/vnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down