Skip to content

Commit

Permalink
Add an additional layer to the API that wraps rules for AdmissionChecks
Browse files Browse the repository at this point in the history
  • Loading branch information
PBundyra committed Apr 11, 2024
1 parent a75ffee commit 0992e5b
Show file tree
Hide file tree
Showing 15 changed files with 138 additions and 157 deletions.
10 changes: 8 additions & 2 deletions apis/kueue/v1beta1/clusterqueue_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ type ClusterQueueSpec struct {
// admissionCheckStrategy defines a list of strategies to determine which ResourceFlavors require AdmissionChecks.
// This property cannot be used in conjunction with the 'admissionChecks' property.
// +optional
AdmissionCheckStrategy []AdmissionCheckStrategy `json:"admissionCheckStrategy,omitempty"`
AdmissionChecksStrategy AdmissionChecksStrategy `json:"admissionChecksStrategy,omitempty"`

// stopPolicy - if set to a value different from None, the ClusterQueue is considered Inactive, no new reservation being
// made.
Expand All @@ -119,7 +119,13 @@ type ClusterQueueSpec struct {
}

// AdmissionCheckStrategy defines a strategy for a AdmissionCheck.
type AdmissionCheckStrategy struct {
type AdmissionChecksStrategy struct {
// admissionChecks is a list of strategies for AdmissionChecks
AdmissionChecks []AdmissionCheckStrategyRule `json:"admissionChecks,omitempty"`
}

// AdmissionCheckStrategyRule defines rules for a single AdmissionCheck
type AdmissionCheckStrategyRule struct {
// name is an AdmissionCheck's name.
Name string `json:"name"`

Expand Down
38 changes: 27 additions & 11 deletions apis/kueue/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 27 additions & 22 deletions charts/kueue/templates/crd/kueue.x-k8s.io_clusterqueues.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,35 +73,40 @@ spec:
spec:
description: ClusterQueueSpec defines the desired state of ClusterQueue
properties:
admissionCheckStrategy:
description: |-
admissionCheckStrategy defines a list of strategies to determine which ResourceFlavors require AdmissionChecks.
This property cannot be used in conjunction with the 'admissionChecks' property.
items:
description: AdmissionCheckStrategy defines a strategy for a AdmissionCheck.
properties:
name:
description: name is an AdmissionCheck's name.
type: string
onFlavors:
description: |-
onFlavors is a list of ResourceFlavors' names that this AdmissionCheck should run for.
If empty, the AdmissionCheck will run for all workloads submitted to the ClusterQueue.
items:
type: string
type: array
required:
- name
- onFlavors
type: object
type: array
admissionChecks:
description: |-
admissionChecks lists the AdmissionChecks required by this ClusterQueue.
Cannot be used along with AdmissionCheckStrategy.
items:
type: string
type: array
admissionChecksStrategy:
description: |-
admissionCheckStrategy defines a list of strategies to determine which ResourceFlavors require AdmissionChecks.
This property cannot be used in conjunction with the 'admissionChecks' property.
properties:
admissionChecks:
description: admissionChecks is a list of strategies for AdmissionChecks
items:
description: AdmissionCheckStrategyRule defines rules for a
single AdmissionCheck
properties:
name:
description: name is an AdmissionCheck's name.
type: string
onFlavors:
description: |-
onFlavors is a list of ResourceFlavors' names that this AdmissionCheck should run for.
If empty, the AdmissionCheck will run for all workloads submitted to the ClusterQueue.
items:
type: string
type: array
required:
- name
- onFlavors
type: object
type: array
type: object
cohort:
description: |-
cohort that this ClusterQueue belongs to. CQs that belong to the
Expand Down

This file was deleted.

33 changes: 14 additions & 19 deletions client-go/applyconfiguration/kueue/v1beta1/clusterqueuespec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions client-go/applyconfiguration/utils.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 27 additions & 22 deletions config/components/crd/bases/kueue.x-k8s.io_clusterqueues.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,35 +58,40 @@ spec:
spec:
description: ClusterQueueSpec defines the desired state of ClusterQueue
properties:
admissionCheckStrategy:
description: |-
admissionCheckStrategy defines a list of strategies to determine which ResourceFlavors require AdmissionChecks.
This property cannot be used in conjunction with the 'admissionChecks' property.
items:
description: AdmissionCheckStrategy defines a strategy for a AdmissionCheck.
properties:
name:
description: name is an AdmissionCheck's name.
type: string
onFlavors:
description: |-
onFlavors is a list of ResourceFlavors' names that this AdmissionCheck should run for.
If empty, the AdmissionCheck will run for all workloads submitted to the ClusterQueue.
items:
type: string
type: array
required:
- name
- onFlavors
type: object
type: array
admissionChecks:
description: |-
admissionChecks lists the AdmissionChecks required by this ClusterQueue.
Cannot be used along with AdmissionCheckStrategy.
items:
type: string
type: array
admissionChecksStrategy:
description: |-
admissionCheckStrategy defines a list of strategies to determine which ResourceFlavors require AdmissionChecks.
This property cannot be used in conjunction with the 'admissionChecks' property.
properties:
admissionChecks:
description: admissionChecks is a list of strategies for AdmissionChecks
items:
description: AdmissionCheckStrategyRule defines rules for a
single AdmissionCheck
properties:
name:
description: name is an AdmissionCheck's name.
type: string
onFlavors:
description: |-
onFlavors is a list of ResourceFlavors' names that this AdmissionCheck should run for.
If empty, the AdmissionCheck will run for all workloads submitted to the ClusterQueue.
items:
type: string
type: array
required:
- name
- onFlavors
type: object
type: array
type: object
cohort:
description: |-
cohort that this ClusterQueue belongs to. CQs that belong to the
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/core/workload_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ func (w *workloadCqHandler) Update(ctx context.Context, ev event.UpdateEvent, wq

if !newCq.DeletionTimestamp.IsZero() ||
!utilslices.CmpNoOrder(oldCq.Spec.AdmissionChecks, newCq.Spec.AdmissionChecks) ||
!cmp.Equal(oldCq.Spec.AdmissionCheckStrategy, newCq.Spec.AdmissionCheckStrategy) ||
!cmp.Equal(oldCq.Spec.AdmissionChecksStrategy, newCq.Spec.AdmissionChecksStrategy) ||
!ptr.Equal(oldCq.Spec.StopPolicy, newCq.Spec.StopPolicy) {
w.queueReconcileForWorkloads(ctx, newCq.Name, wq)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/core/workload_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,8 @@ func TestReconcile(t *testing.T) {
Obj(),
cq: utiltesting.MakeClusterQueue("cq").
AdmissionCheckStrategy(
*utiltesting.MakeAdmissionCheckStrategy("ac1", "flavor1").Obj(),
*utiltesting.MakeAdmissionCheckStrategy("ac2").Obj()).
*utiltesting.MakeAdmissionCheckStrategyRule("ac1", "flavor1").Obj(),
*utiltesting.MakeAdmissionCheckStrategyRule("ac2").Obj()).
Obj(),
lq: utiltesting.MakeLocalQueue("queue", "ns").ClusterQueue("cq").Obj(),
wantWorkload: utiltesting.MakeWorkload("wl", "ns").
Expand Down
20 changes: 10 additions & 10 deletions pkg/util/testing/wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,8 @@ func (c *ClusterQueueWrapper) Cohort(cohort string) *ClusterQueueWrapper {
return c
}

func (c *ClusterQueueWrapper) AdmissionCheckStrategy(acs ...kueue.AdmissionCheckStrategy) *ClusterQueueWrapper {
c.Spec.AdmissionCheckStrategy = acs
func (c *ClusterQueueWrapper) AdmissionCheckStrategy(acs ...kueue.AdmissionCheckStrategyRule) *ClusterQueueWrapper {
c.Spec.AdmissionChecksStrategy.AdmissionChecks = acs
return c
}

Expand Down Expand Up @@ -771,27 +771,27 @@ func MakeAdmissionCheck(name string) *AdmissionCheckWrapper {
}
}

type AdmissionCheckStrategyWrapper struct{ kueue.AdmissionCheckStrategy }
type AdmissionCheckStrategyRuleWrapper struct{ kueue.AdmissionCheckStrategyRule }

func MakeAdmissionCheckStrategy(name string, flavors ...string) *AdmissionCheckStrategyWrapper {
func MakeAdmissionCheckStrategyRule(name string, flavors ...string) *AdmissionCheckStrategyRuleWrapper {
if len(flavors) == 0 {
flavors = make([]string, 0)
}
return &AdmissionCheckStrategyWrapper{
AdmissionCheckStrategy: kueue.AdmissionCheckStrategy{
return &AdmissionCheckStrategyRuleWrapper{
AdmissionCheckStrategyRule: kueue.AdmissionCheckStrategyRule{
Name: name,
OnFlavors: flavors,
},
}
}

func (acs *AdmissionCheckStrategyWrapper) OnFlavors(flavors []string) *AdmissionCheckStrategyWrapper {
acs.AdmissionCheckStrategy.OnFlavors = flavors
func (acs *AdmissionCheckStrategyRuleWrapper) OnFlavors(flavors []string) *AdmissionCheckStrategyRuleWrapper {
acs.AdmissionCheckStrategyRule.OnFlavors = flavors
return acs
}

func (acs *AdmissionCheckStrategyWrapper) Obj() *kueue.AdmissionCheckStrategy {
return &acs.AdmissionCheckStrategy
func (acs *AdmissionCheckStrategyRuleWrapper) Obj() *kueue.AdmissionCheckStrategyRule {
return &acs.AdmissionCheckStrategyRule
}

func (ac *AdmissionCheckWrapper) Active(status metav1.ConditionStatus) *AdmissionCheckWrapper {
Expand Down
Loading

0 comments on commit 0992e5b

Please sign in to comment.