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

Ensure PublicIPAddress resources aren't permanently blocked #4481

Merged
merged 2 commits into from
Dec 3, 2024
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
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
Loading