Skip to content

Commit

Permalink
Make LendingLimit enabled by default in the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
macsko committed Aug 27, 2024
1 parent b6ee6ab commit b5603b2
Show file tree
Hide file tree
Showing 10 changed files with 354 additions and 82 deletions.
99 changes: 89 additions & 10 deletions pkg/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ func TestCacheClusterQueueOperations(t *testing.T) {
return nil
}
cases := []struct {
name string
operation func(*Cache) error
clientObjects []client.Object
wantClusterQueues map[string]*clusterQueue
wantCohorts map[string]sets.Set[string]
enableLendingLimit bool
name string
operation func(*Cache) error
clientObjects []client.Object
wantClusterQueues map[string]*clusterQueue
wantCohorts map[string]sets.Set[string]
disableLendingLimit bool
}{
{
name: "add",
Expand Down Expand Up @@ -398,7 +398,6 @@ func TestCacheClusterQueueOperations(t *testing.T) {
"one": sets.New("b"),
"two": sets.New("a", "c", "e", "f"),
},
enableLendingLimit: true,
},
{
name: "shouldn't delete usage resources on update ClusterQueue",
Expand Down Expand Up @@ -926,8 +925,7 @@ func TestCacheClusterQueueOperations(t *testing.T) {
wantCohorts: map[string]sets.Set[string]{},
},
{
name: "add CQ with multiple resource groups and flavors",
enableLendingLimit: true,
name: "add CQ with multiple resource groups and flavors",
operation: func(cache *Cache) error {
cq := utiltesting.MakeClusterQueue("foo").
ResourceGroup(
Expand Down Expand Up @@ -996,11 +994,92 @@ func TestCacheClusterQueueOperations(t *testing.T) {
},
},
},
{
name: "should not populate the fields with lendingLimit when feature disabled",
disableLendingLimit: true,
operation: func(cache *Cache) error {
cq := utiltesting.MakeClusterQueue("foo").
ResourceGroup(
kueue.FlavorQuotas{
Name: "on-demand",
Resources: []kueue.ResourceQuota{
{
Name: corev1.ResourceCPU,
NominalQuota: resource.MustParse("10"),
LendingLimit: ptr.To(resource.MustParse("8")),
},
{
Name: corev1.ResourceMemory,
NominalQuota: resource.MustParse("10Gi"),
LendingLimit: ptr.To(resource.MustParse("8Gi")),
},
},
},
kueue.FlavorQuotas{
Name: "spot",
Resources: []kueue.ResourceQuota{
{
Name: corev1.ResourceCPU,
NominalQuota: resource.MustParse("20"),
LendingLimit: ptr.To(resource.MustParse("20")),
},
{
Name: corev1.ResourceMemory,
NominalQuota: resource.MustParse("20Gi"),
LendingLimit: ptr.To(resource.MustParse("20Gi")),
},
},
},
).
ResourceGroup(
kueue.FlavorQuotas{
Name: "license",
Resources: []kueue.ResourceQuota{
{
Name: "license",
NominalQuota: resource.MustParse("8"),
LendingLimit: ptr.To(resource.MustParse("4")),
},
},
},
).
Obj()
return cache.AddClusterQueue(context.Background(), cq)
},
wantClusterQueues: map[string]*clusterQueue{
"foo": {
Name: "foo",
NamespaceSelector: labels.Everything(),
Status: pending,
Preemption: defaultPreemption,
AllocatableResourceGeneration: 1,
FlavorFungibility: defaultFlavorFungibility,
FairWeight: oneQuantity,
GuaranteedQuota: nil,
Usage: resources.FlavorResourceQuantities{
{Flavor: "on-demand", Resource: corev1.ResourceCPU}: 0,
{Flavor: "on-demand", Resource: corev1.ResourceMemory}: 0,
{Flavor: "spot", Resource: corev1.ResourceCPU}: 0,
{Flavor: "spot", Resource: corev1.ResourceMemory}: 0,
{Flavor: "license", Resource: "license"}: 0,
},
AdmittedUsage: resources.FlavorResourceQuantities{
{Flavor: "on-demand", Resource: corev1.ResourceCPU}: 0,
{Flavor: "on-demand", Resource: corev1.ResourceMemory}: 0,
{Flavor: "spot", Resource: corev1.ResourceCPU}: 0,
{Flavor: "spot", Resource: corev1.ResourceMemory}: 0,
{Flavor: "license", Resource: "license"}: 0,
},
},
},
},
}

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
defer features.SetFeatureGateDuringTest(t, features.LendingLimit, tc.enableLendingLimit)()
if tc.disableLendingLimit {
defer features.SetFeatureGateDuringTest(t, features.LendingLimit, false)()
}
cache := New(utiltesting.NewFakeClient(tc.clientObjects...))
if err := tc.operation(cache); err != nil {
t.Errorf("Unexpected error during test operation: %s", err)
Expand Down
57 changes: 45 additions & 12 deletions pkg/cache/clusterqueue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ func TestClusterQueueUpdateWithFlavors(t *testing.T) {

func TestFitInCohort(t *testing.T) {
cases := map[string]struct {
request resources.FlavorResourceQuantities
wantFit bool
usage resources.FlavorResourceQuantities
clusterQueue []*kueue.ClusterQueue
enableLendingLimit bool
request resources.FlavorResourceQuantities
wantFit bool
usage resources.FlavorResourceQuantities
clusterQueue []*kueue.ClusterQueue
disableLendingLimit bool
}{
"full cohort, empty request": {
wantFit: true,
Expand Down Expand Up @@ -262,7 +262,7 @@ func TestFitInCohort(t *testing.T) {
Obj(),
},
},
"lendingLimit enabled can't fit": {
"lendingLimit can't fit": {
request: resources.FlavorResourceQuantities{
{Flavor: "f1", Resource: corev1.ResourceCPU}: 3_000,
},
Expand Down Expand Up @@ -295,9 +295,43 @@ func TestFitInCohort(t *testing.T) {
Cohort("C").
Obj(),
},
enableLendingLimit: true,
},
"lendingLimit enabled can fit": {
"lendingLimit should not affect the fit when feature disabled": {
disableLendingLimit: true,
request: resources.FlavorResourceQuantities{
{Flavor: "f1", Resource: corev1.ResourceCPU}: 3_000,
},
wantFit: true,
usage: resources.FlavorResourceQuantities{
{Flavor: "f1", Resource: corev1.ResourceCPU}: 2_000,
},
clusterQueue: []*kueue.ClusterQueue{
utiltesting.
MakeClusterQueue("CQ").
ResourceGroup(
utiltesting.MakeFlavorQuotas("f1").
ResourceQuotaWrapper(corev1.ResourceCPU).
NominalQuota("2").
Append().
FlavorQuotas,
).
Cohort("C").
Obj(),
utiltesting.
MakeClusterQueue("CQ-B").
ResourceGroup(
utiltesting.MakeFlavorQuotas("f1").
ResourceQuotaWrapper(corev1.ResourceCPU).
NominalQuota("3").
LendingLimit("2").
Append().
FlavorQuotas,
).
Cohort("C").
Obj(),
},
},
"lendingLimit can fit": {
request: resources.FlavorResourceQuantities{
{Flavor: "f1", Resource: corev1.ResourceCPU}: 3_000,
},
Expand Down Expand Up @@ -330,13 +364,14 @@ func TestFitInCohort(t *testing.T) {
Cohort("C").
Obj(),
},
enableLendingLimit: true,
},
}

for name, tc := range cases {
t.Run(name, func(t *testing.T) {
defer features.SetFeatureGateDuringTest(t, features.LendingLimit, tc.enableLendingLimit)()
if tc.disableLendingLimit {
defer features.SetFeatureGateDuringTest(t, features.LendingLimit, false)()
}
cache := New(utiltesting.NewFakeClient())

cache.AddOrUpdateResourceFlavor(utiltesting.MakeResourceFlavor("f1").Obj())
Expand Down Expand Up @@ -1018,8 +1053,6 @@ func TestDominantResourceShare(t *testing.T) {
}
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
defer features.SetFeatureGateDuringTest(t, features.LendingLimit, true)()

cache := New(utiltesting.NewFakeClient())
cache.AddOrUpdateResourceFlavor(utiltesting.MakeResourceFlavor("default").Obj())
cache.AddOrUpdateResourceFlavor(utiltesting.MakeResourceFlavor("on-demand").Obj())
Expand Down
Loading

0 comments on commit b5603b2

Please sign in to comment.