Skip to content

Commit 279b054

Browse files
committed
fix capcity value adjustment and tests
Signed-off-by: Britania Rodriguez Reyes <[email protected]>
1 parent b0167ca commit 279b054

File tree

5 files changed

+28
-25
lines changed

5 files changed

+28
-25
lines changed

pkg/propertychecker/azure/checker.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,17 @@ func validateCapacity(value string, operator placementv1beta1.PropertySelectorOp
153153

154154
capacity := uint32(valueUint) // capacity is >= 0 since it's parsed as uint.
155155

156-
// Adjust capacity based on operator semantics for VMSizeRecommender API.
157-
// If operator is GreaterThanOrEqualTo, decrement capacity by 1 as the API checks for strictly greater than.
158-
if operator == placementv1beta1.PropertySelectorGreaterThanOrEqualTo && capacity > minVMInstanceCapacity {
159-
capacity -= 1
156+
// Adjust capacity for VMSizeRecommender API semantics.
157+
// The API requires requested capacity >= 1.
158+
// If operator is GreaterThan (Gt) , increment the requested value by 1.
159+
// Otherwise, use the requested value as-is.
160+
// These adjustments ensure the API interprets the request correctly
161+
if operator == placementv1beta1.PropertySelectorGreaterThan {
162+
capacity += 1
160163
}
161164

162165
// Validate against maximum allowed capacity (exceed maxVMInstanceCapacity).
163-
if capacity >= maxVMInstanceCapacity {
166+
if capacity > maxVMInstanceCapacity {
164167
return 0, fmt.Errorf("capacity value %d exceeds maximum allowed value of %d", capacity, maxVMInstanceCapacity)
165168
}
166169

pkg/propertychecker/azure/checker_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ func TestValidateCapacity(t *testing.T) {
3333
name: "valid capacity value for GreaterThan operator",
3434
value: "10",
3535
operator: placementv1beta1.PropertySelectorGreaterThan,
36-
wantValue: 10,
36+
wantValue: 11,
3737
wantError: false,
3838
},
3939
{
4040
name: "valid capacity value for GreaterThanOrEqualTo operator",
4141
value: "50",
4242
operator: placementv1beta1.PropertySelectorGreaterThanOrEqualTo,
43-
wantValue: 49,
43+
wantValue: 50,
4444
wantError: false,
4545
},
4646
{
@@ -94,7 +94,7 @@ func TestValidateCapacity(t *testing.T) {
9494
name: "capacity equal to max limit with supported operator",
9595
value: "200",
9696
operator: placementv1beta1.PropertySelectorGreaterThanOrEqualTo,
97-
wantValue: 199,
97+
wantValue: 200,
9898
wantError: false,
9999
},
100100
{
@@ -105,15 +105,15 @@ func TestValidateCapacity(t *testing.T) {
105105
errorSubstring: "exceeds maximum allowed value",
106106
},
107107
{
108-
name: "capacity at minimum limit",
108+
name: "capacity at minimum limit (Gt)",
109109
value: "1",
110110
operator: placementv1beta1.PropertySelectorGreaterThan,
111-
wantValue: 1,
111+
wantValue: 2,
112112
wantError: false,
113113
},
114114
{
115-
name: "capacity at minimum limit after adjustment",
116-
value: "2",
115+
name: "capacity at minimum limit (Ge)",
116+
value: "1",
117117
operator: placementv1beta1.PropertySelectorGreaterThanOrEqualTo,
118118
wantValue: 1,
119119
wantError: false,
@@ -163,7 +163,7 @@ func TestExtractCapacityRequirements(t *testing.T) {
163163
Values: []string{"4"},
164164
},
165165
wantSKU: "Standard_D4s_v3",
166-
wantCapacityValue: 4,
166+
wantCapacityValue: 5,
167167
wantError: false,
168168
},
169169
{
@@ -327,7 +327,7 @@ func TestCheckIfMeetSKUCapacityRequirement(t *testing.T) {
327327
name: "valid capacity request",
328328
cluster: cluster,
329329
sku: validSKU,
330-
targetCapacity: 3,
330+
targetCapacity: 4,
331331
req: validPropertySelectorRequirement,
332332
mockStatusCode: http.StatusOK,
333333
wantAvailable: true,
@@ -337,7 +337,7 @@ func TestCheckIfMeetSKUCapacityRequirement(t *testing.T) {
337337
name: "unavailable SKU request",
338338
cluster: cluster,
339339
sku: "Standard_D2s_v4",
340-
targetCapacity: 1,
340+
targetCapacity: 2,
341341
req: placementv1beta1.PropertySelectorRequirement{
342342
Name: fmt.Sprintf(azure.CapacityPerSKUPropertyTmpl, "Standard_D2s_v4"),
343343
Operator: placementv1beta1.PropertySelectorGreaterThanOrEqualTo,
@@ -396,7 +396,7 @@ func TestCheckIfMeetSKUCapacityRequirement(t *testing.T) {
396396
name: "Azure API returns error",
397397
cluster: cluster,
398398
sku: validSKU,
399-
targetCapacity: 3,
399+
targetCapacity: 4,
400400
req: validPropertySelectorRequirement,
401401
mockStatusCode: http.StatusInternalServerError,
402402
wantError: true,
@@ -433,7 +433,7 @@ func TestCheckIfMeetSKUCapacityRequirement(t *testing.T) {
433433
name: "cases-insensitive request - available SKU",
434434
cluster: cluster,
435435
sku: "STANDARD_D2S_V3",
436-
targetCapacity: 1,
436+
targetCapacity: 2,
437437
req: placementv1beta1.PropertySelectorRequirement{
438438
Name: fmt.Sprintf(azure.CapacityPerSKUPropertyTmpl, "STANDARD_D2S_V3"),
439439
Operator: placementv1beta1.PropertySelectorGreaterThanOrEqualTo,

pkg/scheduler/framework/plugins/clusteraffinity/filtering_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ func TestFilter_PropertyChecker(t *testing.T) {
831831
},
832832
},
833833
vmSize: "Standard_D2s_v3",
834-
targetCapacity: 1,
834+
targetCapacity: 2,
835835
},
836836
{
837837
name: "single cluster capacity based term, not matched",
@@ -878,7 +878,7 @@ func TestFilter_PropertyChecker(t *testing.T) {
878878
},
879879
},
880880
vmSize: "Standard_B2ms",
881-
targetCapacity: 3,
881+
targetCapacity: 4,
882882
wantStatus: framework.NewNonErrorStatus(framework.ClusterUnschedulable, p.Name(), "cluster does not match with any of the required cluster affinity terms"),
883883
},
884884
}

pkg/scheduler/framework/plugins/clusteraffinity/types_azure_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func TestMatchPropertiesInPropertyChecker(t *testing.T) {
124124
Values: []string{"2"},
125125
},
126126
vmSize: "Standard_D2s_v3",
127-
targetCapacity: 2,
127+
targetCapacity: 3,
128128
wantHandled: true,
129129
wantAvailable: true,
130130
},
@@ -137,7 +137,7 @@ func TestMatchPropertiesInPropertyChecker(t *testing.T) {
137137
Values: []string{"2"},
138138
},
139139
vmSize: "NonExistentSKU",
140-
targetCapacity: 1,
140+
targetCapacity: 2,
141141
wantHandled: true,
142142
wantAvailable: false,
143143
},

pkg/scheduler/framework/plugins/clusteraffinity/types_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,7 @@ func TestClusterRequirementMatches_WithPropertyChecker(t *testing.T) {
13561356
},
13571357
cluster: cluster,
13581358
sku: "Standard_D2s_v3",
1359-
targetCapacity: 1,
1359+
targetCapacity: 2,
13601360
want: true,
13611361
},
13621362
{
@@ -1388,7 +1388,7 @@ func TestClusterRequirementMatches_WithPropertyChecker(t *testing.T) {
13881388
},
13891389
cluster: cluster,
13901390
sku: "Standard_D4s_v3",
1391-
targetCapacity: 8,
1391+
targetCapacity: 9,
13921392
},
13931393
{
13941394
name: "op >=, matched (max limit)",
@@ -1403,7 +1403,7 @@ func TestClusterRequirementMatches_WithPropertyChecker(t *testing.T) {
14031403
},
14041404
cluster: cluster,
14051405
sku: "Standard_D2s_v3",
1406-
targetCapacity: 199,
1406+
targetCapacity: 200,
14071407
want: true,
14081408
},
14091409
{
@@ -1419,7 +1419,7 @@ func TestClusterRequirementMatches_WithPropertyChecker(t *testing.T) {
14191419
},
14201420
cluster: cluster,
14211421
sku: "Standard_D4s_v3",
1422-
targetCapacity: 79,
1422+
targetCapacity: 80,
14231423
},
14241424
}
14251425

0 commit comments

Comments
 (0)