From 3a82cc0b86c602ba08696ebd1e2059ecb6460325 Mon Sep 17 00:00:00 2001 From: Abirdcfly Date: Thu, 16 Jan 2025 14:19:47 +0800 Subject: [PATCH] propagate priority-class label for deploy Signed-off-by: Abirdcfly --- pkg/controller/jobframework/interface.go | 3 +-- pkg/controller/jobframework/reconciler.go | 2 +- pkg/controller/jobframework/validation.go | 2 +- pkg/controller/jobs/deployment/deployment_webhook.go | 4 ++++ 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pkg/controller/jobframework/interface.go b/pkg/controller/jobframework/interface.go index 67e2b70bd8..ba600ad1b4 100644 --- a/pkg/controller/jobframework/interface.go +++ b/pkg/controller/jobframework/interface.go @@ -170,8 +170,7 @@ func MaximumExecutionTimeSeconds(job GenericJob) *int32 { return ptr.To(int32(v)) } -func workloadPriorityClassName(job GenericJob) string { - object := job.Object() +func WorkloadPriorityClassName(object client.Object) string { if workloadPriorityClassLabel := object.GetLabels()[constants.WorkloadPriorityClassLabel]; workloadPriorityClassLabel != "" { return workloadPriorityClassLabel } diff --git a/pkg/controller/jobframework/reconciler.go b/pkg/controller/jobframework/reconciler.go index 79a5ef1944..ddc1a4abee 100644 --- a/pkg/controller/jobframework/reconciler.go +++ b/pkg/controller/jobframework/reconciler.go @@ -988,7 +988,7 @@ func (r *JobReconciler) prepareWorkload(ctx context.Context, job GenericJob, wl } func (r *JobReconciler) extractPriority(ctx context.Context, podSets []kueue.PodSet, job GenericJob) (string, string, int32, error) { - if workloadPriorityClass := workloadPriorityClassName(job); len(workloadPriorityClass) > 0 { + if workloadPriorityClass := WorkloadPriorityClassName(job.Object()); len(workloadPriorityClass) > 0 { return utilpriority.GetPriorityFromWorkloadPriorityClass(ctx, r.client, workloadPriorityClass) } if jobWithPriorityClass, isImplemented := job.(JobWithPriorityClass); isImplemented { diff --git a/pkg/controller/jobframework/validation.go b/pkg/controller/jobframework/validation.go index 98be6809da..52d2863ea4 100644 --- a/pkg/controller/jobframework/validation.go +++ b/pkg/controller/jobframework/validation.go @@ -120,7 +120,7 @@ func validateUpdateForQueueName(oldJob, newJob GenericJob) field.ErrorList { } func validateUpdateForWorkloadPriorityClassName(oldJob, newJob GenericJob) field.ErrorList { - allErrs := apivalidation.ValidateImmutableField(workloadPriorityClassName(newJob), workloadPriorityClassName(oldJob), workloadPriorityClassNamePath) + allErrs := apivalidation.ValidateImmutableField(WorkloadPriorityClassName(newJob.Object()), WorkloadPriorityClassName(oldJob.Object()), workloadPriorityClassNamePath) return allErrs } diff --git a/pkg/controller/jobs/deployment/deployment_webhook.go b/pkg/controller/jobs/deployment/deployment_webhook.go index 9704f3e0d4..0c77aa062e 100644 --- a/pkg/controller/jobs/deployment/deployment_webhook.go +++ b/pkg/controller/jobs/deployment/deployment_webhook.go @@ -87,6 +87,10 @@ func (wh *Webhook) Default(ctx context.Context, obj runtime.Object) error { } } + if priorityClass := jobframework.WorkloadPriorityClassName(deployment.Object()); priorityClass != "" { + deployment.Spec.Template.Labels[constants.WorkloadPriorityClassLabel] = priorityClass + } + return nil }