-
Notifications
You must be signed in to change notification settings - Fork 87
[slice] NodeSelector in STS webhook #1176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: slice-main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about health selector?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| } | ||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)