Skip to content

Commit

Permalink
first iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Stuchinskii committed Sep 29, 2023
1 parent 86de9f0 commit 13a2389
Show file tree
Hide file tree
Showing 42 changed files with 1,431 additions and 516 deletions.
5 changes: 4 additions & 1 deletion apis/kueue/v1beta1/workload_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ type PodSet struct {
// the keys in the nodeLabels from the ResourceFlavors considered for this
// Workload are used to filter the ResourceFlavors that can be assigned to
// this podSet.
Template corev1.PodTemplateSpec `json:"template"`
Template *corev1.PodTemplateSpec `json:"template"`

// count is the number of pods for the spec.
// +kubebuilder:validation:Minimum=1
Expand All @@ -131,6 +131,9 @@ type PodSet struct {
//
// +optional
MinCount *int32 `json:"minCount,omitempty"`

// PodTemplateName is the name of the PodTemplate the Workload is associated with.
PodTemplateName *string `json:"podTemplateName,omitempty"`
}

// WorkloadStatus defines the observed state of Workload
Expand Down
11 changes: 10 additions & 1 deletion apis/kueue/v1beta1/zz_generated.deepcopy.go

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

4 changes: 4 additions & 0 deletions charts/kueue/templates/crd/kueue.x-k8s.io_workloads.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ spec:
name:
description: name is the PodSet name.
type: string
podTemplateName:
description: PodTemplateName is the name of the PodTemplate
the Workload is associated with.
type: string
template:
description: "template is the Pod template. \n The only allowed
fields in template.metadata are labels and annotations. \n
Expand Down
17 changes: 13 additions & 4 deletions client-go/applyconfiguration/kueue/v1beta1/podset.go

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

4 changes: 4 additions & 0 deletions config/components/crd/bases/kueue.x-k8s.io_workloads.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ spec:
name:
description: name is the PodSet name.
type: string
podTemplateName:
description: PodTemplateName is the name of the PodTemplate
the Workload is associated with.
type: string
template:
description: "template is the Pod template. \n The only allowed
fields in template.metadata are labels and annotations. \n
Expand Down
39 changes: 39 additions & 0 deletions config/components/webhook/manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,25 @@ webhooks:
resources:
- clusterqueues
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
service:
name: webhook-service
namespace: system
path: /mutate-v1-job
failurePolicy: Fail
name: mpodtemplate.kb.io
rules:
- apiGroups:
- ""
apiVersions:
- v1
operations:
- CREATE
resources:
- podtemplate
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
Expand Down Expand Up @@ -459,6 +478,26 @@ webhooks:
resources:
- localqueues
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
service:
name: webhook-service
namespace: system
path: /validate-v1-job
failurePolicy: Fail
name: vpodtemplate.kb.io
rules:
- apiGroups:
- ""
apiVersions:
- v1
operations:
- CREATE
- UPDATE
resources:
- podtemplate
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
Expand Down
38 changes: 29 additions & 9 deletions pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"sync"

"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/util/sets"
Expand Down Expand Up @@ -327,12 +328,31 @@ func (c *Cache) AddClusterQueue(ctx context.Context, cq *kueue.ClusterQueue) err
if !workload.HasQuotaReservation(&w) {
continue
}
c.addOrUpdateWorkload(&workloads.Items[i])
podTemplates, err := c.extractPodTemplate(ctx, w)
if err != nil {
return fmt.Errorf("getting podTemplate that match the name: %w", err)
}
c.addOrUpdateWorkload(&workloads.Items[i], podTemplates)
}

return nil
}

func (c *Cache) extractPodTemplate(ctx context.Context, w kueue.Workload) ([]corev1.PodTemplate, error) {
podTemplates := make([]corev1.PodTemplate, 0, len(w.Spec.PodSets))
for _, ps := range w.Spec.PodSets {
if ps.PodTemplateName == nil {
continue
}
var podTemplate corev1.PodTemplate
if err := c.client.Get(ctx, client.ObjectKey{Name: *ps.PodTemplateName, Namespace: w.Namespace}, &podTemplate); err != nil {
continue
}
podTemplates = append(podTemplates, podTemplate)
}
return podTemplates, nil
}

func (c *Cache) UpdateClusterQueue(cq *kueue.ClusterQueue) error {
c.Lock()
defer c.Unlock()
Expand Down Expand Up @@ -413,13 +433,13 @@ func (c *Cache) UpdateLocalQueue(oldQ, newQ *kueue.LocalQueue) error {
return nil
}

func (c *Cache) AddOrUpdateWorkload(w *kueue.Workload) bool {
func (c *Cache) AddOrUpdateWorkload(w *kueue.Workload, pts []corev1.PodTemplate) bool {
c.Lock()
defer c.Unlock()
return c.addOrUpdateWorkload(w)
return c.addOrUpdateWorkload(w, pts)
}

func (c *Cache) addOrUpdateWorkload(w *kueue.Workload) bool {
func (c *Cache) addOrUpdateWorkload(w *kueue.Workload, pts []corev1.PodTemplate) bool {
if !workload.HasQuotaReservation(w) {
return false
}
Expand All @@ -438,10 +458,10 @@ func (c *Cache) addOrUpdateWorkload(w *kueue.Workload) bool {
if c.podsReadyTracking {
c.podsReadyCond.Broadcast()
}
return clusterQueue.addWorkload(w) == nil
return clusterQueue.addWorkload(w, pts) == nil
}

func (c *Cache) UpdateWorkload(oldWl, newWl *kueue.Workload) error {
func (c *Cache) UpdateWorkload(oldWl *kueue.Workload, newWl *kueue.Workload, pts []corev1.PodTemplate) error {
c.Lock()
defer c.Unlock()
if workload.HasQuotaReservation(oldWl) {
Expand All @@ -463,7 +483,7 @@ func (c *Cache) UpdateWorkload(oldWl, newWl *kueue.Workload) error {
if c.podsReadyTracking {
c.podsReadyCond.Broadcast()
}
return cq.addWorkload(newWl)
return cq.addWorkload(newWl, pts)
}

func (c *Cache) DeleteWorkload(w *kueue.Workload) error {
Expand Down Expand Up @@ -500,7 +520,7 @@ func (c *Cache) IsAssumedOrAdmittedWorkload(w workload.Info) bool {
return false
}

func (c *Cache) AssumeWorkload(w *kueue.Workload) error {
func (c *Cache) AssumeWorkload(w *kueue.Workload, pts []corev1.PodTemplate) error {
c.Lock()
defer c.Unlock()

Expand All @@ -519,7 +539,7 @@ func (c *Cache) AssumeWorkload(w *kueue.Workload) error {
return errCqNotFound
}

if err := cq.addWorkload(w); err != nil {
if err := cq.addWorkload(w, pts); err != nil {
return err
}
c.assumedWorkloads[k] = string(w.Status.Admission.ClusterQueue)
Expand Down
Loading

0 comments on commit 13a2389

Please sign in to comment.