-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure PublicIPAddress resources aren't permanently blocked (#4481)
* Make ReferencedResourceNotProvisioned into a warning * Add test for fix
- Loading branch information
1 parent
ec6984d
commit 8850de9
Showing
3 changed files
with
1,781 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
v2/api/network/customizations/public_ip_address_extension.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
86 changes: 86 additions & 0 deletions
86
v2/internal/controllers/networking_ipaddress_notBlockedByPrefix_20240401_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
Oops, something went wrong.