Skip to content

Commit

Permalink
Expose Flavors in LocalQueue Status.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbobrovskyi committed Oct 7, 2024
1 parent fd12357 commit fd0ed8b
Show file tree
Hide file tree
Showing 11 changed files with 262 additions and 32 deletions.
12 changes: 12 additions & 0 deletions apis/kueue/v1beta1/localqueue_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ type LocalQueueSpec struct {
// +kubebuilder:validation:Pattern="^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$"
type ClusterQueueReference string

type AvailableFlavor struct {
// name of the flavor.
Name ResourceFlavorReference `json:"name"`
}

// LocalQueueStatus defines the observed state of LocalQueue
type LocalQueueStatus struct {
// PendingWorkloads is the number of Workloads in the LocalQueue not yet admitted to a ClusterQueue
Expand Down Expand Up @@ -88,6 +93,13 @@ type LocalQueueStatus struct {
// +kubebuilder:validation:MaxItems=16
// +optional
FlavorUsage []LocalQueueFlavorUsage `json:"flavorUsage"`

// availableFlavors lists all currently available ResourceFlavors
// in specified ClusterQueue.
//
// +listType=map
// +listMapKey=name
AvailableFlavors []AvailableFlavor `json:"availableFlavors,omitempty"`
}

const (
Expand Down
20 changes: 20 additions & 0 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.

18 changes: 18 additions & 0 deletions charts/kueue/templates/crd/kueue.x-k8s.io_localqueues.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,24 @@ spec:
admitted to a ClusterQueue and that haven't finished yet.
format: int32
type: integer
availableFlavors:
description: |-
availableFlavors lists all currently available ResourceFlavors
in specified ClusterQueue.
items:
properties:
name:
description: name of the flavor.
maxLength: 253
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
type: string
required:
- name
type: object
type: array
x-kubernetes-list-map-keys:
- name
x-kubernetes-list-type: map
conditions:
description: |-
Conditions hold the latest available observations of the LocalQueue
Expand Down
42 changes: 42 additions & 0 deletions client-go/applyconfiguration/kueue/v1beta1/availableflavor.go

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

14 changes: 14 additions & 0 deletions client-go/applyconfiguration/kueue/v1beta1/localqueuestatus.go

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

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

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

18 changes: 18 additions & 0 deletions config/components/crd/bases/kueue.x-k8s.io_localqueues.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,24 @@ spec:
admitted to a ClusterQueue and that haven't finished yet.
format: int32
type: integer
availableFlavors:
description: |-
availableFlavors lists all currently available ResourceFlavors
in specified ClusterQueue.
items:
properties:
name:
description: name of the flavor.
maxLength: 253
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
type: string
required:
- name
type: object
type: array
x-kubernetes-list-map-keys:
- name
x-kubernetes-list-type: map
conditions:
description: |-
Conditions hold the latest available observations of the LocalQueue
Expand Down
12 changes: 12 additions & 0 deletions pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"sigs.k8s.io/kueue/pkg/hierarchy"
"sigs.k8s.io/kueue/pkg/metrics"
"sigs.k8s.io/kueue/pkg/resources"
"sigs.k8s.io/kueue/pkg/util/maps"
"sigs.k8s.io/kueue/pkg/workload"
)

Expand Down Expand Up @@ -668,6 +669,7 @@ type LocalQueueUsageStats struct {
ReservingWorkloads int
AdmittedResources []kueue.LocalQueueFlavorUsage
AdmittedWorkloads int
AvailableFlavors []kueue.AvailableFlavor
}

func (c *Cache) LocalQueueUsage(qObj *kueue.LocalQueue) (*LocalQueueUsageStats, error) {
Expand All @@ -683,11 +685,21 @@ func (c *Cache) LocalQueueUsage(qObj *kueue.LocalQueue) (*LocalQueueUsageStats,
return nil, errQNotFound
}

availableFlavors := make(map[kueue.ResourceFlavorReference]kueue.AvailableFlavor)
for _, rg := range cqImpl.ResourceGroups {
for _, fl := range rg.Flavors {
availableFlavors[fl] = kueue.AvailableFlavor{
Name: fl,
}
}
}

return &LocalQueueUsageStats{
ReservedResources: filterLocalQueueUsage(qImpl.usage, cqImpl.ResourceGroups),
ReservingWorkloads: qImpl.reservingWorkloads,
AdmittedResources: filterLocalQueueUsage(qImpl.admittedUsage, cqImpl.ResourceGroups),
AdmittedWorkloads: qImpl.admittedWorkloads,
AvailableFlavors: maps.Values(availableFlavors),
}, nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/controller/core/localqueue_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ func (r *LocalQueueReconciler) UpdateStatusIfChanged(
queue.Status.AdmittedWorkloads = int32(stats.AdmittedWorkloads)
queue.Status.FlavorsReservation = stats.ReservedResources
queue.Status.FlavorUsage = stats.AdmittedResources
queue.Status.AvailableFlavors = stats.AvailableFlavors
if len(conditionStatus) != 0 && len(reason) != 0 && len(msg) != 0 {
meta.SetStatusCondition(&queue.Status.Conditions, metav1.Condition{
Type: kueue.LocalQueueActive,
Expand Down
34 changes: 34 additions & 0 deletions site/content/en/docs/reference/kueue.v1beta1.md
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,30 @@ If empty, the AdmissionCheck will run for all workloads submitted to the Cluster
</tbody>
</table>

## `AvailableFlavor` {#kueue-x-k8s-io-v1beta1-AvailableFlavor}


**Appears in:**

- [LocalQueueStatus](#kueue-x-k8s-io-v1beta1-LocalQueueStatus)



<table class="table">
<thead><tr><th width="30%">Field</th><th>Description</th></tr></thead>
<tbody>


<tr><td><code>name</code> <B>[Required]</B><br/>
<a href="#kueue-x-k8s-io-v1beta1-ResourceFlavorReference"><code>ResourceFlavorReference</code></a>
</td>
<td>
<p>name of the flavor.</p>
</td>
</tr>
</tbody>
</table>

## `BorrowWithinCohort` {#kueue-x-k8s-io-v1beta1-BorrowWithinCohort}


Expand Down Expand Up @@ -1289,6 +1313,14 @@ workloads assigned to this LocalQueue.</p>
workloads assigned to this LocalQueue.</p>
</td>
</tr>
<tr><td><code>availableFlavors</code> <B>[Required]</B><br/>
<a href="#kueue-x-k8s-io-v1beta1-AvailableFlavor"><code>[]AvailableFlavor</code></a>
</td>
<td>
<p>availableFlavors lists all currently available ResourceFlavors
in specified ClusterQueue.</p>
</td>
</tr>
</tbody>
</table>

Expand Down Expand Up @@ -1613,6 +1645,8 @@ this time would be reset to null.</p>

- [AdmissionCheckStrategyRule](#kueue-x-k8s-io-v1beta1-AdmissionCheckStrategyRule)

- [AvailableFlavor](#kueue-x-k8s-io-v1beta1-AvailableFlavor)

- [FlavorQuotas](#kueue-x-k8s-io-v1beta1-FlavorQuotas)

- [FlavorUsage](#kueue-x-k8s-io-v1beta1-FlavorUsage)
Expand Down
Loading

0 comments on commit fd0ed8b

Please sign in to comment.