Skip to content

Commit 8c96fcd

Browse files
committed
DRA: allocator_test: address review comments
1 parent 5a5724d commit 8c96fcd

File tree

2 files changed

+30
-29
lines changed

2 files changed

+30
-29
lines changed

staging/src/k8s.io/dynamic-resource-allocation/structured/allocator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ func (sharedAllocator *Allocator) Allocate(ctx context.Context, node *v1.Node) (
228228
// Constraints are assumed to be monotonic: once a constraint returns
229229
// false, adding more devices will not cause it to return true. This
230230
// allows the search to stop early once a constraint returns false.
231-
var constraints = make([]constraint, 0, len(claim.Spec.Devices.Constraints))
231+
var constraints = make([]constraint, len(claim.Spec.Devices.Constraints))
232232
for i, constraint := range claim.Spec.Devices.Constraints {
233233
switch {
234234
case constraint.MatchAttribute != nil:
@@ -242,7 +242,7 @@ func (sharedAllocator *Allocator) Allocate(ctx context.Context, node *v1.Node) (
242242
requestNames: sets.New(constraint.Requests...),
243243
attributeName: *constraint.MatchAttribute,
244244
}
245-
constraints = append(constraints, m)
245+
constraints[i] = m
246246
default:
247247
// Unknown constraint type!
248248
return nil, fmt.Errorf("claim %s, constraint #%d: unsupported constraint type", klog.KObj(claim), i)

staging/src/k8s.io/dynamic-resource-allocation/structured/allocator_test.go

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ spec:
242242
memory: 2Gi # large
243243
`)
244244

245-
// Second slice on the same node, with different devices.
245+
// Second slice on the same node, with different device names
246+
// and attributes.
246247
node1slice2 := unmarshal[resourceapi.ResourceSlice](t, `
247248
metadata:
248249
name: worker-1-2-slice
@@ -867,39 +868,39 @@ devices:
867868

868869
expectResults: []any{allocatedTwoDeviceClaim},
869870
},
870-
"devices split across different slices": {
871+
"devices-split-across-different-slices": {
871872
claimsToAllocate: objects(fourDeviceClaim),
872873
classes: objects(driverAClass),
873874
slices: objects(node1slice, node1slice2),
874875
node: node1,
875876

876877
expectResults: []any{allocatedFourDeviceClaim},
877878
},
878-
"obsolete slices": {
879-
claimsToAllocate: objects(twoDeviceClaim),
879+
"obsolete-slice": {
880+
claimsToAllocate: objects(simpleClaim),
880881
classes: objects(driverAClass),
881882
slices: objects(node1ObsoleteSlice, node1slice),
882883
node: node1,
883884

884-
expectResults: []any{allocatedTwoDeviceClaim},
885+
expectResults: []any{allocatedSimpleClaim},
885886
},
886-
"no slices": {
887+
"no-slices": {
887888
claimsToAllocate: objects(simpleClaim),
888889
classes: objects(driverAClass),
889890
slices: nil,
890891
node: node1,
891892

892893
expectResults: nil,
893894
},
894-
"not enough suitable devices": {
895+
"not-enough-suitable-devices": {
895896
claimsToAllocate: objects(fourDeviceClaim),
896897
classes: objects(driverAClass),
897898
slices: objects(node1slice),
898899
node: node1,
899900

900901
expectResults: nil,
901902
},
902-
"no classes": {
903+
"no-classes": {
903904
claimsToAllocate: objects(simpleClaim),
904905
classes: nil,
905906
slices: objects(node1slice),
@@ -908,7 +909,7 @@ devices:
908909
expectResults: nil,
909910
expectError: gomega.MatchError(gomega.ContainSubstring("could not retrieve device class driver-a")),
910911
},
911-
"unknown class": {
912+
"unknown-class": {
912913
claimsToAllocate: objects(simpleClaimWithUnknownClassName),
913914
classes: objects(driverAClass, driverBClass),
914915
slices: objects(node1slice, node1DriverBslice),
@@ -917,7 +918,7 @@ devices:
917918
expectResults: nil,
918919
expectError: gomega.MatchError(gomega.ContainSubstring("could not retrieve device class unknown-class")),
919920
},
920-
"empty class": {
921+
"empty-class": {
921922
claimsToAllocate: objects(simpleClaimWithEmptyClassName),
922923
classes: objects(driverAClass, driverBClass),
923924
slices: objects(node1slice, node1DriverBslice),
@@ -926,23 +927,23 @@ devices:
926927
expectResults: nil,
927928
expectError: gomega.MatchError(gomega.ContainSubstring("claim claim, request req-0: unsupported request type")),
928929
},
929-
"no claims to allocate": {
930+
"no-claims-to-allocate": {
930931
claimsToAllocate: nil,
931932
classes: objects(driverAClass),
932933
slices: objects(node1slice),
933934
node: node1,
934935

935936
expectResults: nil,
936937
},
937-
"all devices": {
938+
"all-devices": {
938939
claimsToAllocate: objects(allDeviceClaim),
939940
classes: objects(driverAClass),
940941
slices: objects(node1slice2),
941942
node: node1,
942943

943944
expectResults: []any{allocated2DeviceClaim},
944945
},
945-
"all devices of the incomplete pool": {
946+
"all-devices-of-the-incomplete-pool": {
946947
claimsToAllocate: objects(allDeviceClaim),
947948
classes: objects(driverAClass),
948949
slices: objects(node1IncompletePoolSlice),
@@ -951,47 +952,47 @@ devices:
951952
expectResults: nil,
952953
expectError: gomega.MatchError(gomega.ContainSubstring("claim claim, request req-0: asks for all devices, but resource pool driver-a/worker-1 is currently being updated")),
953954
},
954-
"network-attached device with class.SuitableNodes": {
955+
"network-attached-device-with-class.SuitableNodes": {
955956
claimsToAllocate: objects(simpleClaim),
956957
classes: objects(driverAClass),
957958
slices: objects(networkAttachedSliceWest),
958959
node: node1,
959960

960961
expectResults: []any{allocatedSimpleClaim},
961962
},
962-
"network-attached device without class.SuitableNodes": {
963+
"network-attached-device-without-class.SuitableNodes": {
963964
claimsToAllocate: objects(simpleClaimDriverB),
964965
classes: objects(driverBClass),
965966
slices: objects(networkAttachedSliceEast),
966967
node: node2,
967968

968969
expectResults: []any{allocatedSimpleClaimDriverB},
969970
},
970-
"unsuccessful allocation of a network-attached device with class.SuitableNodes": {
971+
"unsuccessful-allocation-network-attached-device-with-class.SuitableNodes": {
971972
claimsToAllocate: objects(simpleClaim),
972973
classes: objects(driverAClass),
973974
slices: objects(networkAttachedSliceEast),
974975
node: node1,
975976

976977
expectResults: nil,
977978
},
978-
"unsuccessful allocation of a network-attached device without class.SuitableNodes": {
979+
"unsuccessful-allocation-network-attached-device-without-class.SuitableNodes": {
979980
claimsToAllocate: objects(simpleClaimDriverB),
980981
classes: objects(driverBClass),
981982
slices: objects(networkAttachedSliceWest),
982983
node: node2,
983984

984985
expectResults: nil,
985986
},
986-
"several different drivers": {
987+
"several-different-drivers": {
987988
claimsToAllocate: objects(simpleClaim, simpleClaimDriverB),
988989
classes: objects(driverAClass, driverBClass),
989990
slices: objects(node1slice, node1DriverBslice),
990991
node: node1,
991992

992993
expectResults: []any{allocatedSimpleClaim, allocatedSimpleClaimDriverBWorker1},
993994
},
994-
"already allocated devices": {
995+
"already-allocated-devices": {
995996
claimsToAllocate: objects(simpleClaim),
996997
allocatedClaims: objects(allocatedClaim),
997998
classes: objects(driverAClass),
@@ -1000,63 +1001,63 @@ devices:
10001001

10011002
expectResults: nil,
10021003
},
1003-
"with constraint": {
1004+
"with-constraint": {
10041005
claimsToAllocate: objects(twoDeviceClaimWithConstraint),
10051006
classes: objects(driverAClass),
10061007
slices: objects(node1slice),
10071008
node: node1,
10081009

10091010
expectResults: []any{allocatedTwoDeviceClaim},
10101011
},
1011-
"with constraint: non-existent attribute": {
1012+
"with-constraint-non-existent-attribute": {
10121013
claimsToAllocate: objects(simpleClaimWithConstraintNonExistentAttribute),
10131014
classes: objects(driverAClass),
10141015
slices: objects(node1slice),
10151016
node: node1,
10161017

10171018
expectResults: nil,
10181019
},
1019-
"with constraint: not matching int attribute": {
1020+
"with-constraint-not-matching-int-attribute": {
10201021
claimsToAllocate: objects(claimWithConstraintNotMatchingIntAttribute),
10211022
classes: objects(driverAClass, driverBClass),
10221023
slices: objects(node1slice, node1slice2),
10231024
node: node1,
10241025

10251026
expectResults: nil,
10261027
},
1027-
"with constraint: not matching version attribute": {
1028+
"with-constraint-not-matching-version-attribute": {
10281029
claimsToAllocate: objects(claimWithConstraintNotMatchingVersionAttribute),
10291030
classes: objects(driverAClass, driverBClass),
10301031
slices: objects(node1slice, node1slice2),
10311032
node: node1,
10321033

10331034
expectResults: nil,
10341035
},
1035-
"with constraint: not matching string attribute": {
1036+
"with-constraint-not-matching-string-attribute": {
10361037
claimsToAllocate: objects(claimWithConstraintNotMatchingStringAttribute),
10371038
classes: objects(driverAClass, driverBClass),
10381039
slices: objects(node1slice, node1slice2),
10391040
node: node1,
10401041

10411042
expectResults: nil,
10421043
},
1043-
"with constraint: not matching bool attribute": {
1044+
"with-constraint-not-matching-bool-attribute": {
10441045
claimsToAllocate: objects(claimWithConstraintNotMatchingBoolAttribute),
10451046
classes: objects(driverAClass, driverBClass),
10461047
slices: objects(node1slice, node1slice2),
10471048
node: node1,
10481049

10491050
expectResults: nil,
10501051
},
1051-
"with class device config": {
1052+
"with-class-device-config": {
10521053
claimsToAllocate: objects(simpleClaim),
10531054
classes: objects(driverAClassWithConfig),
10541055
slices: objects(node1slice),
10551056
node: node1,
10561057

10571058
expectResults: []any{allocatedSimpleClaimWithClassConfig},
10581059
},
1059-
"with claim device config": {
1060+
"with-claim-device-config": {
10601061
claimsToAllocate: objects(simpleClaimWithConfig),
10611062
classes: objects(driverAClass),
10621063
slices: objects(node1slice),

0 commit comments

Comments
 (0)