Skip to content

Commit

Permalink
Ensure PublicIPAddress resources aren't permanently blocked (#4481)
Browse files Browse the repository at this point in the history
* Make ReferencedResourceNotProvisioned into a warning

* Add test for fix
  • Loading branch information
theunrepentantgeek authored Dec 3, 2024
1 parent ec6984d commit 8850de9
Show file tree
Hide file tree
Showing 3 changed files with 1,781 additions and 0 deletions.
48 changes: 48 additions & 0 deletions v2/api/network/customizations/public_ip_address_extension.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
*/

package customizations

import (
"github.com/go-logr/logr"

"github.com/Azure/azure-service-operator/v2/internal/genericarmclient"
"github.com/Azure/azure-service-operator/v2/pkg/genruntime/core"
"github.com/Azure/azure-service-operator/v2/pkg/genruntime/extensions"
)

var _ extensions.ErrorClassifier = &PublicIPAddressExtension{}

func (extension *PublicIPAddressExtension) ClassifyError(
cloudError *genericarmclient.CloudError,
apiVersion string,
log logr.Logger,
next extensions.ErrorClassifierFunc,
) (core.CloudErrorDetails, error) {
details, err := next(cloudError)
if err != nil {
return core.CloudErrorDetails{}, err
}

// Override is to treat Conflict as retryable for Redis, if the message contains "try again later"
if isRetryablePublicIPAddressError(cloudError) {
details.Classification = core.ErrorRetryable
}

return details, nil
}

func isRetryablePublicIPAddressError(err *genericarmclient.CloudError) bool {
if err == nil {
return false
}

// If a referenced resource is not yet provisioned, it may be coming soon
if err.Code() == "ReferencedResourceNotProvisioned" {
return true
}

return false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
*/

package controllers_test

import (
"testing"

network "github.com/Azure/azure-service-operator/v2/api/network/v1api20240301"
"github.com/Azure/azure-service-operator/v2/internal/testcommon"
"github.com/Azure/azure-service-operator/v2/internal/util/to"
)

func Test_Network_PublicIPAddress_creationNotBlockedByPublicIPPrefix_20240301(t *testing.T) {
t.Parallel()

tc := globalTestContext.ForTest(t)

rg := tc.CreateTestResourceGroupAndWait()

prefix := &network.PublicIPPrefix{
ObjectMeta: tc.MakeObjectMetaWithName("prefix"),
Spec: network.PublicIPPrefix_Spec{
Location: tc.AzureRegion,
Owner: testcommon.AsOwner(rg),
PrefixLength: to.Ptr(29),
PublicIPAddressVersion: to.Ptr(network.IPVersion_IPv4),
Sku: &network.PublicIPPrefixSku{
Name: to.Ptr(network.PublicIPPrefixSku_Name_Standard),
Tier: to.Ptr(network.PublicIPPrefixSku_Tier_Regional),
},
},
}

ip1 := &network.PublicIPAddress{
ObjectMeta: tc.MakeObjectMetaWithName("ip1"),
Spec: network.PublicIPAddress_Spec{
Location: tc.AzureRegion,
Owner: testcommon.AsOwner(rg),
Sku: &network.PublicIPAddressSku{
Name: to.Ptr(network.PublicIPAddressSku_Name_Standard),
},
PublicIPAllocationMethod: to.Ptr(network.IPAllocationMethod_Static),
PublicIPAddressVersion: to.Ptr(network.IPVersion_IPv4),
PublicIPPrefix: &network.SubResource{
Reference: tc.MakeReferenceFromResource(prefix),
},
},
}

ip2 := &network.PublicIPAddress{
ObjectMeta: tc.MakeObjectMetaWithName("ip2"),
Spec: network.PublicIPAddress_Spec{
Location: tc.AzureRegion,
Owner: testcommon.AsOwner(rg),
Sku: &network.PublicIPAddressSku{
Name: to.Ptr(network.PublicIPAddressSku_Name_Standard),
},
PublicIPAllocationMethod: to.Ptr(network.IPAllocationMethod_Static),
PublicIPAddressVersion: to.Ptr(network.IPVersion_IPv4),
PublicIPPrefix: &network.SubResource{
Reference: tc.MakeReferenceFromResource(prefix),
},
},
}

ip3 := &network.PublicIPAddress{
ObjectMeta: tc.MakeObjectMetaWithName("ip3"),
Spec: network.PublicIPAddress_Spec{
Location: tc.AzureRegion,
Owner: testcommon.AsOwner(rg),
Sku: &network.PublicIPAddressSku{
Name: to.Ptr(network.PublicIPAddressSku_Name_Standard),
},
PublicIPAllocationMethod: to.Ptr(network.IPAllocationMethod_Static),
PublicIPAddressVersion: to.Ptr(network.IPVersion_IPv4),
PublicIPPrefix: &network.SubResource{
Reference: tc.MakeReferenceFromResource(prefix),
},
},
}

tc.CreateResourcesAndWait(prefix, ip1, ip2, ip3)
}
Loading

0 comments on commit 8850de9

Please sign in to comment.