-
Notifications
You must be signed in to change notification settings - Fork 449
Azure Stack Support #5532
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
base: main
Are you sure you want to change the base?
Azure Stack Support #5532
Changes from all commits
2212107
70bea61
6ae8304
435df16
66bd450
ba8bb88
32e327a
170b6f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,12 @@ func ResourceNotFound(err error) bool { | |
return errors.As(err, &rerr) && rerr.StatusCode == http.StatusNotFound | ||
} | ||
|
||
// BadRequest parses an error to check if it its status code is Bad Request (400). | ||
func BadRequest(err error) bool { | ||
var rerr *azcore.ResponseError | ||
return errors.As(err, &rerr) && rerr.StatusCode == http.StatusBadRequest | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a simple unit test for this function in |
||
} | ||
|
||
// VMDeletedError is returned when a virtual machine is deleted outside of capz. | ||
type VMDeletedError struct { | ||
ProviderID string | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,24 +19,27 @@ package availabilitysets | |
import ( | ||
"context" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5" | ||
"github.com/pkg/errors" | ||
"k8s.io/utils/ptr" | ||
|
||
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1" | ||
"sigs.k8s.io/cluster-api-provider-azure/azure" | ||
"sigs.k8s.io/cluster-api-provider-azure/azure/converters" | ||
"sigs.k8s.io/cluster-api-provider-azure/azure/services/resourceskus" | ||
) | ||
|
||
// AvailabilitySetSpec defines the specification for an availability set. | ||
type AvailabilitySetSpec struct { | ||
Name string | ||
ResourceGroup string | ||
ClusterName string | ||
Location string | ||
SKU *resourceskus.SKU | ||
AdditionalTags infrav1.Tags | ||
Name string | ||
ResourceGroup string | ||
ClusterName string | ||
Location string | ||
CloudEnvironment string | ||
SKU *resourceskus.SKU | ||
AdditionalTags infrav1.Tags | ||
} | ||
|
||
// ResourceName returns the name of the availability set. | ||
|
@@ -64,20 +67,10 @@ func (s *AvailabilitySetSpec) Parameters(_ context.Context, existing interface{} | |
return nil, nil | ||
} | ||
|
||
if s.SKU == nil { | ||
return nil, errors.New("unable to get required availability set SKU from machine cache") | ||
} | ||
|
||
var faultDomainCount *int32 | ||
faultDomainCountStr, ok := s.SKU.GetCapability(resourceskus.MaximumPlatformFaultDomainCount) | ||
if !ok { | ||
return nil, errors.Errorf("unable to get required availability set SKU capability %s", resourceskus.MaximumPlatformFaultDomainCount) | ||
} | ||
count, err := strconv.ParseInt(faultDomainCountStr, 10, 32) | ||
faultDomainCount, err := getFaultDomainCount(s.SKU, s.CloudEnvironment) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "unable to parse availability set fault domain count") | ||
return nil, err | ||
} | ||
faultDomainCount = ptr.To[int32](int32(count)) | ||
|
||
asParams := armcompute.AvailabilitySet{ | ||
SKU: &armcompute.SKU{ | ||
|
@@ -98,3 +91,27 @@ func (s *AvailabilitySetSpec) Parameters(_ context.Context, existing interface{} | |
|
||
return asParams, nil | ||
} | ||
|
||
func getFaultDomainCount(sku *resourceskus.SKU, cloudEnvironment string) (*int32, error) { | ||
// Azure Stack environments may not implement the resource SKU API | ||
// for availability sets. Use a default value instead. | ||
if strings.EqualFold(cloudEnvironment, azure.StackCloudName) { | ||
return ptr.To(int32(2)), nil | ||
} | ||
Comment on lines
+98
to
+100
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a unit test case for when cloud environment is Azure Stack to |
||
|
||
if sku == nil { | ||
return nil, errors.New("unable to get required availability set SKU from machine cache") | ||
} | ||
|
||
var faultDomainCount *int32 | ||
faultDomainCountStr, ok := sku.GetCapability(resourceskus.MaximumPlatformFaultDomainCount) | ||
if !ok { | ||
return nil, errors.Errorf("unable to get required availability set SKU capability %s", resourceskus.MaximumPlatformFaultDomainCount) | ||
} | ||
count, err := strconv.ParseInt(faultDomainCountStr, 10, 32) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "unable to parse availability set fault domain count") | ||
} | ||
faultDomainCount = ptr.To(int32(count)) | ||
return faultDomainCount, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,14 +109,21 @@ func (ac *AzureClient) CreateOrUpdateAsync(ctx context.Context, spec azure.Resou | |
// request to Azure and if accepted without error, the func will return a Poller which can be used to track the ongoing | ||
// progress of the operation. | ||
func (ac *AzureClient) DeleteAsync(ctx context.Context, spec azure.ResourceSpecGetter, resumeToken string) (poller *runtime.Poller[armcompute.VirtualMachinesClientDeleteResponse], err error) { | ||
ctx, _, done := tele.StartSpanWithLogger(ctx, "virtualmachines.AzureClient.Delete") | ||
ctx, log, done := tele.StartSpanWithLogger(ctx, "virtualmachines.AzureClient.Delete") | ||
defer done() | ||
|
||
forceDelete := ptr.To(true) | ||
opts := &armcompute.VirtualMachinesClientBeginDeleteOptions{ResumeToken: resumeToken, ForceDeletion: forceDelete} | ||
poller, err = ac.virtualmachines.BeginDelete(ctx, spec.ResourceGroupName(), spec.ResourceName(), opts) | ||
if err != nil { | ||
return nil, err | ||
if azure.BadRequest(err) { | ||
log.Info("Failed to Begin VM Delete with Force Deletion, retrying without the force flag") | ||
opts.ForceDeletion = ptr.To(false) | ||
poller, err = ac.virtualmachines.BeginDelete(ctx, spec.ResourceGroupName(), spec.ResourceName(), opts) | ||
} | ||
if err != nil { | ||
return nil, err | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like a good improvement, but is it related to Azure Stack support? What problem is it trying to solve? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, azure stack throws a 400 error that says the force flag is not supported... Should I add a comment? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oops I think I forgot to add the comment. This is specified in the commit message, but I will add a code comment in my next pass. |
||
} | ||
|
||
ctx, cancel := context.WithTimeout(ctx, ac.apiCallTimeout) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it intended to add AzureStack to the comment here as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intentionally did not add it here, because I did not think there would be support for Azure Stack with managed control planes. Happy to discuss more, but I don't have a lot of background knowledge on this.