Skip to content

Commit

Permalink
test(sdkerrors): testing SKUFamily errors and TotalRegional cores
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryce-Soghigian committed Dec 1, 2023
1 parent 6d9c7d2 commit f734a32
Showing 1 changed file with 82 additions and 2 deletions.
84 changes: 82 additions & 2 deletions pkg/providers/instancetype/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ limitations under the License.
package instancetype_test

import (
"bytes"
"context"
"encoding/base64"
"fmt"
"io"
"net/http"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -48,6 +51,9 @@ import (
coretest "github.com/aws/karpenter-core/pkg/test"
. "github.com/aws/karpenter-core/pkg/test/expectations"

sdkerrors "github.com/Azure/azure-sdk-for-go-extensions/pkg/errors"
"github.com/Azure/azure-sdk-for-go/sdk/azcore"

"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute"
"github.com/Azure/karpenter/pkg/apis"
"github.com/Azure/karpenter/pkg/apis/settings"
Expand Down Expand Up @@ -77,7 +83,6 @@ func TestAzure(t *testing.T) {

var _ = BeforeSuite(func() {
ctx = coreoptions.ToContext(ctx, coretest.Options())
// ctx = options.ToContext(ctx, test.Options())
ctx = settings.ToContext(ctx, test.Settings())

env = coretest.NewEnvironment(scheme.Scheme, coretest.WithCRDs(apis.CRDs...))
Expand Down Expand Up @@ -130,6 +135,77 @@ var _ = Describe("InstanceType Provider", func() {
ExpectCleanedUp(ctx, env.Client)
})

Context("subscription level quota error responses", func() {
It("should fail to provsion when SKUFamily error is returned, and succeed when its gone", func() {
errorMessageHittingLimit := "Operation could not be completed as it results in exceeding approved standardDLSv5Family Cores quota. Additional details - Deployment Model: Resource Manager, Location: westus2, Current Limit: 100, Current Usage: 96, Additional Required: 32, (Minimum) New Limit Required: 128. Submit a request for Quota increase at https://aka.ms/ProdportalCRP/#blade/Microsoft_Azure_Capacity/UsageAndQuota.ReactView/Parameters/%7B%22subscriptionId%22:%(redacted)%22,%22command%22:%22openQuotaApprovalBlade%22,%22quotas%22:[%7B%22location%22:%22westus2%22,%22providerId%22:%22Microsoft.Compute%22,%22resourceName%22:%22standardDLSv5Family%22,%22quotaRequest%22:%7B%22properties%22:%7B%22limit%22:128,%22unit%22:%22Count%22,%22name%22:%7B%22value%22:%22standardDLSv5Family%22%7D%7D%7D%7D]%7D by specifying parameters listed in the ‘Details’ section for deployment to succeed. Please read more about quota limits at https://docs.microsoft.com/en-us/azure/azure-supportability/per-vm-quota-requests"
ExpectApplied(ctx, env.Client, nodePool, nodeClass)
azureEnv.VirtualMachinesAPI.VirtualMachinesBehavior.VirtualMachineCreateOrUpdateBehavior.Error.Set(
&azcore.ResponseError{
ErrorCode: sdkerrors.OperationNotAllowed,
RawResponse: &http.Response{
Body: createSDKErrorBody(sdkerrors.OperationNotAllowed, errorMessageHittingLimit),
},
},
)
pod := coretest.UnschedulablePod()
ExpectProvisioned(ctx, env.Client, cluster, cloudProvider, coreProvisioner, pod)
ExpectNotScheduled(ctx, env.Client, pod)
azureEnv.VirtualMachinesAPI.VirtualMachineCreateOrUpdateBehavior.BeginError.Set(nil)
pod = coretest.UnschedulablePod()
ExpectProvisioned(ctx, env.Client, cluster, cloudProvider, coreProvisioner, pod)
ExpectScheduled(ctx, env.Client, pod)
})
It("should fail to provsion when SKUFamily quota limit is zero, and succeed when its gone", func() {
errorMessageHittingLimit := "Operation could not be completed as it results in exceeding approved standardDLSv5Family Cores quota. Additional details - Deployment Model: Resource Manager, Location: westus2, Current Limit: 0, Current Usage: 0, Additional Required: 32, (Minimum) New Limit Required: 32. Submit a request for Quota increase at https://aka.ms/ProdportalCRP/#blade/Microsoft_Azure_Capacity/UsageAndQuota.ReactView/Parameters/%7B%22subscriptionId%22:%(redacted)%22,%22command%22:%22openQuotaApprovalBlade%22,%22quotas%22:[%7B%22location%22:%22westus2%22,%22providerId%22:%22Microsoft.Compute%22,%22resourceName%22:%22standardDLSv5Family%22,%22quotaRequest%22:%7B%22properties%22:%7B%22limit%22:128,%22unit%22:%22Count%22,%22name%22:%7B%22value%22:%22standardDLSv5Family%22%7D%7D%7D%7D]%7D by specifying parameters listed in the ‘Details’ section for deployment to succeed. Please read more about quota limits at https://docs.microsoft.com/en-us/azure/azure-supportability/per-vm-quota-requests"
ExpectApplied(ctx, env.Client, nodePool, nodeClass)
azureEnv.VirtualMachinesAPI.VirtualMachinesBehavior.VirtualMachineCreateOrUpdateBehavior.Error.Set(
&azcore.ResponseError{
ErrorCode: sdkerrors.OperationNotAllowed,
RawResponse: &http.Response{
Body: createSDKErrorBody(sdkerrors.OperationNotAllowed, errorMessageHittingLimit),
},
},
)
pod := coretest.UnschedulablePod()
ExpectProvisioned(ctx, env.Client, cluster, cloudProvider, coreProvisioner, pod)
ExpectNotScheduled(ctx, env.Client, pod)
azureEnv.VirtualMachinesAPI.VirtualMachineCreateOrUpdateBehavior.BeginError.Set(nil)
pod = coretest.UnschedulablePod()
ExpectProvisioned(ctx, env.Client, cluster, cloudProvider, coreProvisioner, pod)
ExpectScheduled(ctx, env.Client, pod)
})

It("should return ICE if Total Regional Cores Quota errors are hit", func() {
regionalCoresErrorMessage := "Operation could not be completed as it results in exceeding approved Total Regional Cores quota. Additional details - Deployment Model: Resource Manager, Location: uksouth, Current Limit: 100, Current Usage: 100, Additional Required: 64, (Minimum) New Limit Required: 164. Submit a request for Quota increase at https://aka.ms/ProdportalCRP/#blade/Microsoft_Azure_Capacity/UsageAndQuota.ReactView/Parameters/%7B%22subscriptionId%22:%(redacted)%22,%22command%22:%22openQuotaApprovalBlade%22,%22quotas%22:[%7B%22location%22:%22uksouth%22,%22providerId%22:%22Microsoft.Compute%22,%22resourceName%22:%22cores%22,%22quotaRequest%22:%7B%22properties%22:%7B%22limit%22:164,%22unit%22:%22Count%22,%22name%22:%7B%22value%22:%22cores%22%7D%7D%7D%7D]%7D by specifying parameters listed in the ‘Details’ section for deployment to succeed. Please read more about quota limits at https://docs.microsoft.com/en-us/azure/azure-supportability/regional-quota-requests"
azureEnv.VirtualMachinesAPI.VirtualMachinesBehavior.VirtualMachineCreateOrUpdateBehavior.Error.Set(
&azcore.ResponseError{
ErrorCode: sdkerrors.OperationNotAllowed,
RawResponse: &http.Response{
Body: createSDKErrorBody(sdkerrors.OperationNotAllowed, regionalCoresErrorMessage),
},
},
)

ExpectApplied(ctx, env.Client, nodePool, nodeClass)
nodeClaim := coretest.NodeClaim(corev1beta1.NodeClaim{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
corev1beta1.NodePoolLabelKey: nodePool.Name,
},
},
Spec: corev1beta1.NodeClaimSpec{
NodeClassRef: &corev1beta1.NodeClassReference{
Name: nodeClass.Name,
},
},
})
claim, err := cloudProvider.Create(ctx, nodeClaim)
Expect(corecloudprovider.IsInsufficientCapacityError(err)).To(BeTrue())
Expect(claim).To(BeNil())

})
})

Context("Filtering in InstanceType Provider List", func() {
var instanceTypes corecloudprovider.InstanceTypes
var err error
Expand Down Expand Up @@ -227,7 +303,7 @@ var _ = Describe("InstanceType Provider", func() {
Name: nodeClass.Name,
}

ExpectApplied(ctx, env.Client, nodePool, nodeClass)
ExpectApplied(ctx, env.Client, np, nodeClass)
pod := coretest.UnschedulablePod()
ExpectProvisioned(ctx, env.Client, cluster, cloudProvider, coreProvisioner, pod)
ExpectScheduled(ctx, env.Client, pod)
Expand Down Expand Up @@ -897,3 +973,7 @@ var _ = Describe("Tax Calculator", func() {
})
})
})

func createSDKErrorBody(code, message string) io.ReadCloser {
return io.NopCloser(bytes.NewReader([]byte(fmt.Sprintf(`{"error":{"code": "%s", "message": "%s"}}`, code, message))))
}

0 comments on commit f734a32

Please sign in to comment.