diff --git a/pkg/controller/jobs/statefulset/statefulset_webhook.go b/pkg/controller/jobs/statefulset/statefulset_webhook.go index 7d95457500..2b1d07fdb6 100644 --- a/pkg/controller/jobs/statefulset/statefulset_webhook.go +++ b/pkg/controller/jobs/statefulset/statefulset_webhook.go @@ -62,16 +62,24 @@ func (wh *Webhook) Default(ctx context.Context, obj runtime.Object) error { log := ctrl.LoggerFrom(ctx).WithName("statefulset-webhook") log.V(5).Info("Applying defaults") - cqLabel, ok := ss.Labels[constants.QueueLabel] - if !ok { + queueName := jobframework.QueueNameForObject(ss.Object()) + + // Skip not managed by Kueue. + if queueName == "" && !wh.manageJobsWithoutQueueName { return nil } + if queueName != "" { + if ss.Spec.Template.Labels == nil { + ss.Spec.Template.Labels = make(map[string]string, 2) + } + ss.Spec.Template.Labels[constants.QueueLabel] = queueName + } + if ss.Spec.Template.Labels == nil { - ss.Spec.Template.Labels = make(map[string]string, 2) + ss.Spec.Template.Labels = make(map[string]string, 1) } - ss.Spec.Template.Labels[constants.QueueLabel] = cqLabel ss.Spec.Template.Labels[pod.GroupNameLabel] = GetWorkloadName(ss.Name) if ss.Spec.Template.Annotations == nil { diff --git a/pkg/controller/jobs/statefulset/statefulset_webhook_test.go b/pkg/controller/jobs/statefulset/statefulset_webhook_test.go index d8cb8149c3..8ea379ee8c 100644 --- a/pkg/controller/jobs/statefulset/statefulset_webhook_test.go +++ b/pkg/controller/jobs/statefulset/statefulset_webhook_test.go @@ -42,6 +42,28 @@ func TestDefault(t *testing.T) { enableIntegrations []string want *appsv1.StatefulSet }{ + "statefulset not managed by kueue": { + enableIntegrations: []string{"pod"}, + statefulset: testingstatefulset.MakeStatefulSet("test-pod", ""). + Replicas(10). + Obj(), + want: testingstatefulset.MakeStatefulSet("test-pod", ""). + Replicas(10). + Obj(), + }, + "statefulset managed by kueue without queue name": { + enableIntegrations: []string{"pod"}, + manageJobsWithoutQueueName: true, + statefulset: testingstatefulset.MakeStatefulSet("test-pod", ""). + Replicas(10). + Obj(), + want: testingstatefulset.MakeStatefulSet("test-pod", ""). + Replicas(10). + PodTemplateSpecPodGroupNameLabel("test-pod", "", gvk). + PodTemplateSpecPodGroupTotalCountAnnotation(10). + PodTemplateSpecPodGroupFastAdmissionAnnotation(true). + Obj(), + }, "statefulset with queue": { enableIntegrations: []string{"pod"}, statefulset: testingstatefulset.MakeStatefulSet("test-pod", "").