Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graduate LendingLimit to Beta #2909

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions apis/kueue/v1beta1/clusterqueue_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,7 @@ type ResourceQuota struct {
// all the nominalQuota can be borrowed by other clusterQueues in the cohort.
// If not null, it must be non-negative.
// lendingLimit must be null if spec.cohort is empty.
// This field is in alpha stage. To be able to use this field,
// enable the feature gate LendingLimit, which is disabled by default.
// This field is in beta stage and is enabled by default.
// +optional
LendingLimit *resource.Quantity `json:"lendingLimit,omitempty"`
}
Expand Down
3 changes: 1 addition & 2 deletions charts/kueue/templates/crd/kueue.x-k8s.io_clusterqueues.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,7 @@ spec:
all the nominalQuota can be borrowed by other clusterQueues in the cohort.
If not null, it must be non-negative.
lendingLimit must be null if spec.cohort is empty.
This field is in alpha stage. To be able to use this field,
enable the feature gate LendingLimit, which is disabled by default.
This field is in beta stage and is enabled by default.
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
name:
Expand Down
3 changes: 1 addition & 2 deletions charts/kueue/templates/crd/kueue.x-k8s.io_cohorts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ spec:
all the nominalQuota can be borrowed by other clusterQueues in the cohort.
If not null, it must be non-negative.
lendingLimit must be null if spec.cohort is empty.
This field is in alpha stage. To be able to use this field,
enable the feature gate LendingLimit, which is disabled by default.
This field is in beta stage and is enabled by default.
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
name:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,7 @@ spec:
all the nominalQuota can be borrowed by other clusterQueues in the cohort.
If not null, it must be non-negative.
lendingLimit must be null if spec.cohort is empty.
This field is in alpha stage. To be able to use this field,
enable the feature gate LendingLimit, which is disabled by default.
This field is in beta stage and is enabled by default.
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
name:
Expand Down
3 changes: 1 addition & 2 deletions config/components/crd/bases/kueue.x-k8s.io_cohorts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ spec:
all the nominalQuota can be borrowed by other clusterQueues in the cohort.
If not null, it must be non-negative.
lendingLimit must be null if spec.cohort is empty.
This field is in alpha stage. To be able to use this field,
enable the feature gate LendingLimit, which is disabled by default.
This field is in beta stage and is enabled by default.
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
name:
Expand Down
86 changes: 75 additions & 11 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 @@ -482,7 +481,6 @@ func TestCacheClusterQueueOperations(t *testing.T) {
wantCohorts: map[string]sets.Set[string]{
"one": sets.New("a"),
},
enableLendingLimit: true,
},
{
// Cohort one is deleted, as its members move
Expand Down Expand Up @@ -926,8 +924,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 +993,78 @@ 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,
},
},
},
}

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