Skip to content

Commit 19d402a

Browse files
committed
address comments
Signed-off-by: Britania Rodriguez Reyes <[email protected]>
1 parent 279b054 commit 19d402a

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

pkg/propertychecker/azure/checker.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const (
2929
maxVMInstanceCapacity = 200
3030

3131
// minVMInstanceCapacity defines the minimum allowed VM instance capacity for SKU capacity requirements.
32-
// The Azure Capacity API requires capacity values greater than 0, so minimum is set to 1.
32+
// The Azure vmSizeRecommender API requires capacity values greater than 0, so minimum is set to 1.
3333
// Lower bound is enforced after adjusting for operator semantics.
3434
minVMInstanceCapacity = 1
3535
)
@@ -80,14 +80,14 @@ func (s *PropertyChecker) CheckIfMeetSKUCapacityRequirement(
8080
}
8181

8282
// Request VM size recommendations to validate SKU availability and capacity.
83-
// The capacity is checked by ensuring the current allocatable capacity is greater than the requested capacity.
83+
// The capacity is checked by ensuring the current allocatable capacity is greater than or equals to the requested capacity.
8484
klog.V(2).Infof("Checking SKU %s with capacity %d in cluster %s", sku, capacity, cluster.Name)
8585
request := &computev1.GenerateAttributeBasedRecommendationsRequest{
8686
SubscriptionId: subID,
8787
Location: location,
8888
RegularPriorityProfile: &computev1.RegularPriorityProfile{
8989
CapacityUnitType: computev1.CapacityUnitType_CAPACITY_UNIT_TYPE_VM_INSTANCE_COUNT,
90-
TargetCapacity: capacity, // CurrentAllocatableCapacity > RequestedCapacity
90+
TargetCapacity: capacity, // CurrentAllocatableCapacity >= RequestedCapacity
9191
},
9292
ResourceProperties: &computev1.ResourceProperties{
9393
VmAttributes: &computev1.VMAttributes{
@@ -122,7 +122,7 @@ func (s *PropertyChecker) CheckIfMeetSKUCapacityRequirement(
122122
// This function is specifically designed for Azure SKU capacity properties that follow the pattern:
123123
// "kubernetes.azure.com/vm-sizes/{sku}/capacity"
124124
// Returns the capacity value adjusted for the operator semantics, as the VMSizeRecommender API
125-
// checks whether current allocatable capacity is greater than the requested capacity.
125+
// checks whether current allocatable capacity is greater than or equal to the requested capacity.
126126
func extractCapacityRequirements(req placementv1beta1.PropertySelectorRequirement) (uint32, error) {
127127
if req.Operator != placementv1beta1.PropertySelectorGreaterThan && req.Operator != placementv1beta1.PropertySelectorGreaterThanOrEqualTo {
128128
return 0, fmt.Errorf("unsupported operator %q for SKU capacity property, only GreaterThan (Gt) and GreaterThanOrEqualTo (Ge) are supported", req.Operator)
@@ -170,7 +170,7 @@ func validateCapacity(value string, operator placementv1beta1.PropertySelectorOp
170170
// Ensure capacity meets minimum requirements (minVMInstanceCapacity) after operator adjustment.
171171
// The VMSizeRecommender API requires capacity > 0.
172172
if capacity < minVMInstanceCapacity {
173-
capacity = minVMInstanceCapacity
173+
return 0, fmt.Errorf("capacity value %d is below minimum allowed value of %d", capacity, minVMInstanceCapacity)
174174
}
175175

176176
return capacity, nil

pkg/propertychecker/azure/checker_test.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,11 @@ func TestValidateCapacity(t *testing.T) {
7272
errorSubstring: "invalid capacity value",
7373
},
7474
{
75-
name: "invalid value of zero for capacity replaced with minimum",
76-
value: "0",
77-
operator: placementv1beta1.PropertySelectorGreaterThanOrEqualTo,
78-
wantValue: 1,
75+
name: "invalid value of zero for capacity",
76+
value: "0",
77+
operator: placementv1beta1.PropertySelectorGreaterThanOrEqualTo,
78+
wantError: true,
79+
errorSubstring: "is below minimum allowed value",
7980
},
8081
{
8182
name: "capacity equal to max limit with GreaterThan operator",
@@ -178,14 +179,15 @@ func TestExtractCapacityRequirements(t *testing.T) {
178179
errorSubstring: "exceeds maximum allowed value of 200",
179180
},
180181
{
181-
name: "invalid Azure SKU capacity property exceeding min limit",
182+
name: "invalid Azure SKU capacity property below min limit",
182183
req: placementv1beta1.PropertySelectorRequirement{
183184
Name: fmt.Sprintf(azure.CapacityPerSKUPropertyTmpl, "Standard_B2ms"),
184185
Operator: placementv1beta1.PropertySelectorGreaterThanOrEqualTo,
185-
Values: []string{"1"},
186+
Values: []string{"0"},
186187
},
187-
wantSKU: "Standard_B2ms",
188-
wantCapacityValue: 1,
188+
wantSKU: "Standard_B2ms",
189+
wantError: true,
190+
errorSubstring: "is below minimum allowed value",
189191
},
190192
{
191193
name: "invalid Azure SKU capacity property with decimal",
@@ -296,7 +298,7 @@ func TestExtractCapacityRequirements(t *testing.T) {
296298
}
297299

298300
func TestCheckIfMeetSKUCapacityRequirement(t *testing.T) {
299-
// Prepare test data
301+
// Prepare test data.
300302
validSKU := "Standard_D2s_v3"
301303
validPropertySelectorRequirement := placementv1beta1.PropertySelectorRequirement{
302304
Name: fmt.Sprintf(azure.CapacityPerSKUPropertyTmpl, validSKU),
@@ -417,7 +419,7 @@ func TestCheckIfMeetSKUCapacityRequirement(t *testing.T) {
417419
errorSubstring: "unsupported operator \"Eq\" for SKU capacity property, only GreaterThan (Gt) and GreaterThanOrEqualTo (Ge) are supported",
418420
},
419421
{
420-
name: "too low value in requirement replaced with minimum capacity",
422+
name: "too low value in requirement",
421423
cluster: cluster,
422424
sku: validSKU,
423425
targetCapacity: 1,
@@ -426,8 +428,8 @@ func TestCheckIfMeetSKUCapacityRequirement(t *testing.T) {
426428
Operator: placementv1beta1.PropertySelectorGreaterThanOrEqualTo,
427429
Values: []string{"0"},
428430
},
429-
mockStatusCode: http.StatusOK,
430-
wantAvailable: true,
431+
wantError: true,
432+
errorSubstring: "is below minimum allowed value",
431433
},
432434
{
433435
name: "cases-insensitive request - available SKU",

0 commit comments

Comments
 (0)