Skip to content
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
1 change: 1 addition & 0 deletions slice/internal/core/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const (
TPUAcceleratorLabel = "cloud.google.com/gke-tpu-accelerator"
TPUBlockLabel = "cloud.google.com/gce-topology-block"
TPUSubBlockLabel = "cloud.google.com/gke-tpu-partition-4x4x4-id"
TPUSkipWardenAnnotation = "cloud.google.com/skip-tpu-webhook-check"
TPUResourceName = "google.com/tpu"
RetryOnFailureAnnotation = "slice.gke.io/retry-on-failure"
TPUsPerCube = 64
Expand Down
35 changes: 22 additions & 13 deletions slice/internal/webhooks/leaderworkerset_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package webhooks
import (
"context"

corev1 "k8s.io/api/core/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
kueue "sigs.k8s.io/kueue/apis/kueue/v1beta1"
Expand Down Expand Up @@ -68,28 +69,36 @@ func (r *LeaderWorkerSetWebhook) Default(ctx context.Context, lws *leaderworkers
return nil
}

log.V(5).Info("Annotating WorkerTemplate")
tpuTopology := lws.Spec.LeaderWorkerTemplate.WorkerTemplate.Annotations[core.TPUSliceTopologyAnnotation]
parsed, err := topology.ParseTopologyV7(tpuTopology)
if err != nil {
return err
}
annotatePodTemplateSpecWithSliceHealth(&lws.Spec.LeaderWorkerTemplate.WorkerTemplate, parsed, r.DefaultSliceHealthValues)
if lws.Spec.LeaderWorkerTemplate.WorkerTemplate.Annotations == nil {
lws.Spec.LeaderWorkerTemplate.WorkerTemplate.Annotations = make(map[string]string)

log.V(5).Info("Annotating LeaderWorkerTemplate")
annotatePodTemplateSpec(&lws.Spec.LeaderWorkerTemplate.WorkerTemplate, parsed, r.DefaultSliceHealthValues)
annotatePodTemplateSpec(lws.Spec.LeaderWorkerTemplate.LeaderTemplate, parsed, r.DefaultSliceHealthValues)
setPodSetGroupName(lws)

return nil
}

func annotatePodTemplateSpec(template *corev1.PodTemplateSpec, parsed topology.ParsedTopology, defaultSliceHealthValues []string) {
if template == nil {
return
}
annotatePodTemplateSpecWithSliceHealth(template, parsed, defaultSliceHealthValues)
if template.Annotations == nil {
template.Annotations = make(map[string]string)
}
template.Annotations[core.TPUSkipWardenAnnotation] = "true"
template.Annotations[kueue.PodSetRequiredTopologyAnnotation] = parsed.RequiredSliceLevel()
}

func setPodSetGroupName(lws *leaderworkersetv1.LeaderWorkerSet) {
if lws.Spec.LeaderWorkerTemplate.LeaderTemplate != nil {
// if the leader is defined, annotate both templates with the same group name
lws.Spec.LeaderWorkerTemplate.WorkerTemplate.Annotations[podsetGroupName] = podsetGroupValue
lws.Spec.LeaderWorkerTemplate.LeaderTemplate.Annotations[podsetGroupName] = podsetGroupValue

annotatePodTemplateSpecWithSliceHealth(lws.Spec.LeaderWorkerTemplate.LeaderTemplate, parsed, r.DefaultSliceHealthValues)
if lws.Spec.LeaderWorkerTemplate.LeaderTemplate.Annotations == nil {
lws.Spec.LeaderWorkerTemplate.LeaderTemplate.Annotations = make(map[string]string)
}
lws.Spec.LeaderWorkerTemplate.LeaderTemplate.Annotations[kueue.PodSetRequiredTopologyAnnotation] = parsed.RequiredSliceLevel()
}

lws.Spec.LeaderWorkerTemplate.WorkerTemplate.Annotations[kueue.PodSetRequiredTopologyAnnotation] = parsed.RequiredSliceLevel()
return nil
}
4 changes: 4 additions & 0 deletions slice/internal/webhooks/leaderworkerset_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func TestLeaderWorkerSetDefault(t *testing.T) {
Size(4).
WorkerAnnotation(core.TPUSliceTopologyAnnotation, "2x2x4").
WorkerAnnotation(kueue.PodSetRequiredTopologyAnnotation, "cloud.google.com/gke-tpu-partition-2x2x4-id").
WorkerAnnotation(core.TPUSkipWardenAnnotation, "true").
WorkerNodeSelector("cloud.google.com/gke-tpu-accelerator", string(slice.TypeTpu7x)).
WorkerNodeAffinity("cloud.google.com/gke-tpu-partition-2x2x4-state", []string{core.TPUSliceHealthNodeSelectorHealthy}).
WorkerLimit(core.TPUResourceName, "4").
Expand All @@ -114,11 +115,13 @@ func TestLeaderWorkerSetDefault(t *testing.T) {
WorkerAnnotation(core.TPUSliceTopologyAnnotation, "2x2x4").
WorkerAnnotation(podsetGroupName, podsetGroupValue).
WorkerAnnotation(kueue.PodSetRequiredTopologyAnnotation, "cloud.google.com/gke-tpu-partition-2x2x4-id").
WorkerAnnotation(core.TPUSkipWardenAnnotation, "true").
WorkerNodeSelector("cloud.google.com/gke-tpu-accelerator", string(slice.TypeTpu7x)).
WorkerNodeAffinity("cloud.google.com/gke-tpu-partition-2x2x4-state", []string{core.TPUSliceHealthNodeSelectorHealthy}).
WorkerLimit(core.TPUResourceName, "4").
LeaderAnnotation(core.TPUSliceTopologyAnnotation, "2x2x4").
LeaderAnnotation(podsetGroupName, podsetGroupValue).
LeaderAnnotation(core.TPUSkipWardenAnnotation, "true").
LeaderAnnotation(kueue.PodSetRequiredTopologyAnnotation, "cloud.google.com/gke-tpu-partition-2x2x4-id").
LeaderNodeSelector("cloud.google.com/gke-tpu-accelerator", string(slice.TypeTpu7x)).
LeaderNodeAffinity("cloud.google.com/gke-tpu-partition-2x2x4-state", []string{core.TPUSliceHealthNodeSelectorHealthy}).
Expand All @@ -139,6 +142,7 @@ func TestLeaderWorkerSetDefault(t *testing.T) {
Size(4).
WorkerAnnotation(core.TPUSliceTopologyAnnotation, "2x2x4").
WorkerAnnotation(kueue.PodSetRequiredTopologyAnnotation, "cloud.google.com/gke-tpu-partition-2x2x4-id").
WorkerAnnotation(core.TPUSkipWardenAnnotation, "true").
WorkerNodeSelector("cloud.google.com/gke-tpu-accelerator", string(slice.TypeTpu7x)).
WorkerNodeSelector("cloud.google.com/gke-tpu-partition-2x2x4-state", "HEALTHY").
WorkerLimit(core.TPUResourceName, "4").
Expand Down
Loading