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 14, 2024
1 parent fd12357 commit ea8e7f9
Show file tree
Hide file tree
Showing 13 changed files with 422 additions and 32 deletions.
32 changes: 32 additions & 0 deletions apis/kueue/v1beta1/localqueue_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,31 @@ 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 Flavor struct {
// name of the flavor.
Name ResourceFlavorReference `json:"name"`

// resources used in the flavor.
// +listType=set
// +kubebuilder:validation:MaxItems=16
// +optional
Resources []corev1.ResourceName `json:"resources,omitempty"`

// nodeLabels are labels that associate the ResourceFlavor with Nodes that
// have the same labels.
// +mapType=atomic
// +kubebuilder:validation:MaxProperties=8
// +optional
NodeLabels map[string]string `json:"nodeLabels,omitempty"`

// nodeTaints are taints that the nodes associated with this ResourceFlavor
// have.
// +listType=atomic
// +kubebuilder:validation:MaxItems=8
// +optional
NodeTaints []corev1.Taint `json:"nodeTaints,omitempty"`
}

// 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 +113,13 @@ type LocalQueueStatus struct {
// +kubebuilder:validation:MaxItems=16
// +optional
FlavorUsage []LocalQueueFlavorUsage `json:"flavorUsage"`

// flavors lists all currently available ResourceFlavors in specified ClusterQueue.
// +listType=map
// +listMapKey=name
// +kubebuilder:validation:MaxItems=16
// +optional
Flavors []Flavor `json:"availableFlavors,omitempty"`
}

const (
Expand Down
41 changes: 41 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
80 changes: 80 additions & 0 deletions client-go/applyconfiguration/kueue/v1beta1/flavor.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.

70 changes: 70 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,76 @@ spec:
admitted to a ClusterQueue and that haven't finished yet.
format: int32
type: integer
availableFlavors:
description: flavors 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
nodeLabels:
additionalProperties:
type: string
description: |-
nodeLabels are labels that associate the ResourceFlavor with Nodes that
have the same labels.
maxProperties: 8
type: object
x-kubernetes-map-type: atomic
nodeTaints:
description: |-
nodeTaints are taints that the nodes associated with this ResourceFlavor
have.
items:
description: |-
The node this Taint is attached to has the "effect" on
any pod that does not tolerate the Taint.
properties:
effect:
description: |-
Required. The effect of the taint on pods
that do not tolerate the taint.
Valid effects are NoSchedule, PreferNoSchedule and NoExecute.
type: string
key:
description: Required. The taint key to be applied to
a node.
type: string
timeAdded:
description: |-
TimeAdded represents the time at which the taint was added.
It is only written for NoExecute taints.
format: date-time
type: string
value:
description: The taint value corresponding to the taint
key.
type: string
required:
- effect
- key
type: object
maxItems: 8
type: array
x-kubernetes-list-type: atomic
resources:
description: resources used in the flavor.
items:
type: string
maxItems: 16
type: array
x-kubernetes-list-type: set
required:
- name
type: object
maxItems: 16
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
32 changes: 32 additions & 0 deletions pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"context"
"errors"
"fmt"
corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/kueue/pkg/features"
"sort"
"sync"

Expand All @@ -38,6 +40,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 +671,7 @@ type LocalQueueUsageStats struct {
ReservingWorkloads int
AdmittedResources []kueue.LocalQueueFlavorUsage
AdmittedWorkloads int
Flavors []kueue.Flavor
}

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

flavors := make(map[kueue.ResourceFlavorReference]kueue.Flavor)
if features.Enabled(features.ExposeFlavorsInLocalQueue) {
resourcesInFlavor := make(map[kueue.ResourceFlavorReference]sets.Set[corev1.ResourceName])
for _, rg := range cqImpl.ResourceGroups {
for _, rgFlavor := range rg.Flavors {
if _, ok := resourcesInFlavor[rgFlavor]; !ok {
resourcesInFlavor[rgFlavor] = sets.New[corev1.ResourceName]()
}
resourcesInFlavor[rgFlavor].Insert(rg.CoveredResources.UnsortedList()...)
}
}

for _, rg := range cqImpl.ResourceGroups {
for _, rgFlavor := range rg.Flavors {
flavor := kueue.Flavor{Name: rgFlavor}
if rif, ok := resourcesInFlavor[rgFlavor]; !ok {
flavor.Resources = rif.UnsortedList()
}
if rf, ok := c.resourceFlavors[rgFlavor]; ok {
flavor.NodeLabels = rf.Spec.NodeLabels
flavor.NodeTaints = rf.Spec.NodeTaints
}
flavors[rgFlavor] = flavor
}
}
}

return &LocalQueueUsageStats{
ReservedResources: filterLocalQueueUsage(qImpl.usage, cqImpl.ResourceGroups),
ReservingWorkloads: qImpl.reservingWorkloads,
AdmittedResources: filterLocalQueueUsage(qImpl.admittedUsage, cqImpl.ResourceGroups),
AdmittedWorkloads: qImpl.admittedWorkloads,
Flavors: maps.Values(flavors),
}, 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.Flavors = stats.Flavors
if len(conditionStatus) != 0 && len(reason) != 0 && len(msg) != 0 {
meta.SetStatusCondition(&queue.Status.Conditions, metav1.Condition{
Type: kueue.LocalQueueActive,
Expand Down
Loading

0 comments on commit ea8e7f9

Please sign in to comment.