Skip to content

Commit 9952cb9

Browse files
committed
chore(backend): Fixed ServiceAccount in job creation
Signed-off-by: Helber Belmiro <helber.belmiro@gmail.com>
1 parent f3cb244 commit 9952cb9

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

backend/src/apiserver/resource/resource_manager.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,18 +1005,19 @@ func (r *ResourceManager) CreateJob(ctx context.Context, job *model.Job) (*model
10051005
for _, modelRef := range job.ResourceReferences {
10061006
modelRef.ResourceUUID = string(swf.UID)
10071007
}
1008-
// Get the service account
1009-
serviceAccount := ""
1010-
if swf.Spec.Workflow != nil {
1011-
execSpec, err := util.ScheduleSpecToExecutionSpec(util.ArgoWorkflow, swf.Spec.Workflow)
1012-
if err == nil {
1013-
serviceAccount = execSpec.ServiceAccount()
1014-
}
1015-
}
1016-
job.ServiceAccount = serviceAccount
10171008
if tmpl.GetTemplateType() == template.V1 {
1009+
// Get the service account
1010+
serviceAccount := ""
1011+
if swf.Spec.Workflow != nil {
1012+
execSpec, err := util.ScheduleSpecToExecutionSpec(util.ArgoWorkflow, swf.Spec.Workflow)
1013+
if err == nil {
1014+
serviceAccount = execSpec.ServiceAccount()
1015+
}
1016+
}
1017+
job.ServiceAccount = serviceAccount
10181018
job.PipelineSpec.WorkflowSpecManifest = manifest
10191019
} else {
1020+
job.ServiceAccount = newScheduledWorkflow.Spec.ServiceAccount
10201021
job.PipelineSpec.PipelineSpecManifest = manifest
10211022
}
10221023
return r.jobStore.CreateJob(job)

backend/src/apiserver/template/v2_template.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ func (t *V2Spec) ScheduledWorkflow(modelJob *model.Job) (*scheduledworkflow.Sche
9797
if modelJob.Namespace != "" {
9898
executionSpec.SetExecutionNamespace(modelJob.Namespace)
9999
}
100-
setDefaultServiceAccount(executionSpec, modelJob.ServiceAccount)
100+
if executionSpec.ServiceAccount() == "" {
101+
setDefaultServiceAccount(executionSpec, modelJob.ServiceAccount)
102+
}
101103
// Disable istio sidecar injection if not specified
102104
executionSpec.SetAnnotationsToAllTemplatesIfKeyNotExist(util.AnnotationKeyIstioSidecarInject, util.AnnotationValueIstioSidecarInjectDisabled)
103105
swfGeneratedName, err := toSWFCRDResourceGeneratedName(modelJob.K8SName)
@@ -132,7 +134,7 @@ func (t *V2Spec) ScheduledWorkflow(modelJob *model.Job) (*scheduledworkflow.Sche
132134
PipelineId: modelJob.PipelineId,
133135
PipelineName: modelJob.PipelineName,
134136
PipelineVersionId: modelJob.PipelineVersionId,
135-
ServiceAccount: modelJob.ServiceAccount,
137+
ServiceAccount: executionSpec.ServiceAccount(),
136138
},
137139
}
138140
return scheduledWorkflow, nil

0 commit comments

Comments
 (0)