diff --git a/backend/src/apiserver/resource/resource_manager.go b/backend/src/apiserver/resource/resource_manager.go index 312453a9659..a50a989b7c8 100644 --- a/backend/src/apiserver/resource/resource_manager.go +++ b/backend/src/apiserver/resource/resource_manager.go @@ -1081,18 +1081,19 @@ func (r *ResourceManager) CreateJob(ctx context.Context, job *model.Job) (*model for _, modelRef := range job.ResourceReferences { modelRef.ResourceUUID = string(swf.UID) } - // Get the service account - serviceAccount := "" - if swf.Spec.Workflow != nil { - execSpec, err := util.ScheduleSpecToExecutionSpec(util.ArgoWorkflow, swf.Spec.Workflow) - if err == nil { - serviceAccount = execSpec.ServiceAccount() - } - } - job.ServiceAccount = serviceAccount if tmpl.GetTemplateType() == template.V1 { + // Get the service account + serviceAccount := "" + if swf.Spec.Workflow != nil { + execSpec, err := util.ScheduleSpecToExecutionSpec(util.ArgoWorkflow, swf.Spec.Workflow) + if err == nil { + serviceAccount = execSpec.ServiceAccount() + } + } + job.ServiceAccount = serviceAccount job.PipelineSpec.WorkflowSpecManifest = manifest } else { + job.ServiceAccount = newScheduledWorkflow.Spec.ServiceAccount job.PipelineSpec.PipelineSpecManifest = manifest } return r.jobStore.CreateJob(job) diff --git a/backend/src/apiserver/template/template_test.go b/backend/src/apiserver/template/template_test.go index 98e7482bf46..27c9817cb60 100644 --- a/backend/src/apiserver/template/template_test.go +++ b/backend/src/apiserver/template/template_test.go @@ -217,9 +217,10 @@ func TestScheduledWorkflow(t *testing.T) { Parameters: []scheduledworkflow.Parameter{{Name: "y", Value: "\"world\""}}, Spec: "", }, - PipelineId: "1", - PipelineName: "pipeline name", - NoCatchup: util.BoolPointer(true), + PipelineId: "1", + PipelineName: "pipeline name", + NoCatchup: util.BoolPointer(true), + ServiceAccount: "pipeline-runner", }, } diff --git a/backend/src/apiserver/template/v2_template.go b/backend/src/apiserver/template/v2_template.go index d14ddffdaeb..1055bcdf8a9 100644 --- a/backend/src/apiserver/template/v2_template.go +++ b/backend/src/apiserver/template/v2_template.go @@ -97,7 +97,9 @@ func (t *V2Spec) ScheduledWorkflow(modelJob *model.Job) (*scheduledworkflow.Sche if modelJob.Namespace != "" { executionSpec.SetExecutionNamespace(modelJob.Namespace) } - setDefaultServiceAccount(executionSpec, modelJob.ServiceAccount) + if executionSpec.ServiceAccount() == "" { + setDefaultServiceAccount(executionSpec, modelJob.ServiceAccount) + } // Disable istio sidecar injection if not specified executionSpec.SetAnnotationsToAllTemplatesIfKeyNotExist(util.AnnotationKeyIstioSidecarInject, util.AnnotationValueIstioSidecarInjectDisabled) swfGeneratedName, err := toSWFCRDResourceGeneratedName(modelJob.K8SName) @@ -132,7 +134,7 @@ func (t *V2Spec) ScheduledWorkflow(modelJob *model.Job) (*scheduledworkflow.Sche PipelineId: modelJob.PipelineId, PipelineName: modelJob.PipelineName, PipelineVersionId: modelJob.PipelineVersionId, - ServiceAccount: modelJob.ServiceAccount, + ServiceAccount: executionSpec.ServiceAccount(), }, } return scheduledWorkflow, nil