Skip to content
Open
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
4 changes: 4 additions & 0 deletions slice/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ func setupControllers(mgr ctrl.Manager, certsReady chan struct{}, activationTime
setupLog.Error(err, "Unable to create webhook", "webhook", "LeaderWorkerSet")
os.Exit(1)
}
if err := webhooks.SetupStatefulSetWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "Unable to create webhook", "webhook", "StatefulSet")
os.Exit(1)
}

if failedCtrl, err := controller.SetupControllers(mgr, controller.Options{
ActivationTimeout: activationTimeout, RetryDelayOnSliceFailure: retryDelay}); err != nil {
Expand Down
19 changes: 19 additions & 0 deletions slice/config/webhook/manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,22 @@ webhooks:
resources:
- leaderworkersets
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
service:
name: webhook-service
namespace: system
path: /mutate-apps-v1-statefulset
failurePolicy: Fail
name: mstatefulset.slice-controller.kb.io
rules:
- apiGroups:
- apps
apiVersions:
- v1
operations:
- CREATE
resources:
- statefulsets
sideEffects: None
69 changes: 69 additions & 0 deletions slice/internal/util/testingjobs/leaderworkerset/wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,72 @@ func (w *Wrapper) LeaderNodeAffinity(key string, values []string) *Wrapper {
)
return w
}

func (w *Wrapper) StartupPolicy(policy leaderworkersetv1.StartupPolicyType) *Wrapper {
w.Spec.StartupPolicy = policy
return w
}

func (w *Wrapper) WorkerName(name string) *Wrapper {
if len(w.Spec.LeaderWorkerTemplate.WorkerTemplate.Spec.Containers) == 0 {
w.Spec.LeaderWorkerTemplate.WorkerTemplate.Spec.Containers = []corev1.Container{{}}
}
w.Spec.LeaderWorkerTemplate.WorkerTemplate.Spec.Containers[0].Name = name
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if there is more than 1 container?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm but this is only for e2e tests. Making it work for any number of containers would introduce additional complexity and in kueue also we have 1 container hardcoded in such wrappers (https://github.com/kubernetes-sigs/kueue/blob/90375d4a3e8c363f7187512c8f5ad4145d041610/pkg/util/testingjobs/leaderworkerset/wrappers.go#L189-L211)

return w
}

func (w *Wrapper) LeaderName(name string) *Wrapper {
if w.Spec.LeaderWorkerTemplate.LeaderTemplate == nil {
w.Spec.LeaderWorkerTemplate.LeaderTemplate = &corev1.PodTemplateSpec{}
}
if len(w.Spec.LeaderWorkerTemplate.LeaderTemplate.Spec.Containers) == 0 {
w.Spec.LeaderWorkerTemplate.LeaderTemplate.Spec.Containers = []corev1.Container{{}}
}
w.Spec.LeaderWorkerTemplate.LeaderTemplate.Spec.Containers[0].Name = name
return w
}

func (w *Wrapper) LeaderImage(img string) *Wrapper {
if w.Spec.LeaderWorkerTemplate.LeaderTemplate == nil {
w.Spec.LeaderWorkerTemplate.LeaderTemplate = &corev1.PodTemplateSpec{}
}
if len(w.Spec.LeaderWorkerTemplate.LeaderTemplate.Spec.Containers) == 0 {
w.Spec.LeaderWorkerTemplate.LeaderTemplate.Spec.Containers = []corev1.Container{{}}
}
w.Spec.LeaderWorkerTemplate.LeaderTemplate.Spec.Containers[0].Image = img
return w
}

func (w *Wrapper) LeaderArgs(args ...string) *Wrapper {
if w.Spec.LeaderWorkerTemplate.LeaderTemplate == nil {
w.Spec.LeaderWorkerTemplate.LeaderTemplate = &corev1.PodTemplateSpec{}
}
if len(w.Spec.LeaderWorkerTemplate.LeaderTemplate.Spec.Containers) == 0 {
w.Spec.LeaderWorkerTemplate.LeaderTemplate.Spec.Containers = []corev1.Container{{}}
}
w.Spec.LeaderWorkerTemplate.LeaderTemplate.Spec.Containers[0].Args = args
return w
}

func (w *Wrapper) LeaderLimit(resourceName corev1.ResourceName, quantity string) *Wrapper {
if w.Spec.LeaderWorkerTemplate.LeaderTemplate == nil {
w.Spec.LeaderWorkerTemplate.LeaderTemplate = &corev1.PodTemplateSpec{}
}
if len(w.Spec.LeaderWorkerTemplate.LeaderTemplate.Spec.Containers) == 0 {
w.Spec.LeaderWorkerTemplate.LeaderTemplate.Spec.Containers = []corev1.Container{{}}
}
if w.Spec.LeaderWorkerTemplate.LeaderTemplate.Spec.Containers[0].Resources.Limits == nil {
w.Spec.LeaderWorkerTemplate.LeaderTemplate.Spec.Containers[0].Resources.Limits = make(corev1.ResourceList)
}
w.Spec.LeaderWorkerTemplate.LeaderTemplate.Spec.Containers[0].Resources.Limits[resourceName] = resource.MustParse(quantity)
return w
}

func (w *Wrapper) LeaderRequestAndLimit(resourceName corev1.ResourceName, quantity string) *Wrapper {
w.LeaderLimit(resourceName, quantity)
if w.Spec.LeaderWorkerTemplate.LeaderTemplate.Spec.Containers[0].Resources.Requests == nil {
w.Spec.LeaderWorkerTemplate.LeaderTemplate.Spec.Containers[0].Resources.Requests = make(corev1.ResourceList)
}
w.Spec.LeaderWorkerTemplate.LeaderTemplate.Spec.Containers[0].Resources.Requests[resourceName] = resource.MustParse(quantity)
return w
}
59 changes: 59 additions & 0 deletions slice/internal/webhooks/statefulset_webhook.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
Copyright The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package webhooks

import (
"context"

appsv1 "k8s.io/api/apps/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"

"tpu-slice-controller/internal/core"
)

type StatefulSetWebhook struct{}

func SetupStatefulSetWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr, &appsv1.StatefulSet{}).
WithDefaulter(&StatefulSetWebhook{}).
Complete()
}

// +kubebuilder:webhook:path=/mutate-apps-v1-statefulset,mutating=true,failurePolicy=fail,sideEffects=None,groups=apps,resources=statefulsets,verbs=create,versions=v1,name=mstatefulset.slice-controller.kb.io,admissionReviewVersions=v1

var _ admission.Defaulter[*appsv1.StatefulSet] = &StatefulSetWebhook{}

func (r *StatefulSetWebhook) Default(ctx context.Context, sts *appsv1.StatefulSet) error {
log := ctrl.LoggerFrom(ctx).WithName("statefulset-webhook")

if !core.IsRelevantPodTemplateSpec(sts.Spec.Template) {
log.V(5).Info("Skipping non-relevant StatefulSet")
return nil
}

log.V(5).Info("Defaulting StatefulSet")
tpuTopology := core.GetTPUTopology(sts.Spec.Template)
if sts.Spec.Template.Spec.NodeSelector == nil {
sts.Spec.Template.Spec.NodeSelector = make(map[string]string)
}
if _, ok := sts.Spec.Template.Spec.NodeSelector[core.TPUTopologyAnnotation]; !ok {
sts.Spec.Template.Spec.NodeSelector[core.TPUTopologyAnnotation] = tpuTopology
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about health selector?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The health labels are always at the nodes (unlike the topology labels that are added only after the slice is Active), so it is not interfering with the scheduling to just add them in the LWS/Job/Jobset webhook.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was asking whether we should add node selector for healthy/degraded nodes or not.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We add this healthy/degraded selector in LWS webhook and it is propagated to kueue workload, so TAS knows which nodes to exclude. I think it should be propagated from LWS to STS but even if its not then is it a problem?

}

return nil
}
Loading
Loading