Skip to content

Commit f1b7367

Browse files
Merge pull request #123 from hbelmiro/cherry-pick-11481
UPSTREAM: 11481: chore(backend): Fixed ServiceAccount in job creation
2 parents dcf2d0e + 37c74b3 commit f1b7367

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

backend/src/apiserver/resource/resource_manager.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,18 +1022,19 @@ func (r *ResourceManager) CreateJob(ctx context.Context, job *model.Job) (*model
10221022
for _, modelRef := range job.ResourceReferences {
10231023
modelRef.ResourceUUID = string(swf.UID)
10241024
}
1025-
// Get the service account
1026-
serviceAccount := ""
1027-
if swf.Spec.Workflow != nil {
1028-
execSpec, err := util.ScheduleSpecToExecutionSpec(util.ArgoWorkflow, swf.Spec.Workflow)
1029-
if err == nil {
1030-
serviceAccount = execSpec.ServiceAccount()
1031-
}
1032-
}
1033-
job.ServiceAccount = serviceAccount
10341025
if tmpl.GetTemplateType() == template.V1 {
1026+
// Get the service account
1027+
serviceAccount := ""
1028+
if swf.Spec.Workflow != nil {
1029+
execSpec, err := util.ScheduleSpecToExecutionSpec(util.ArgoWorkflow, swf.Spec.Workflow)
1030+
if err == nil {
1031+
serviceAccount = execSpec.ServiceAccount()
1032+
}
1033+
}
1034+
job.ServiceAccount = serviceAccount
10351035
job.PipelineSpec.WorkflowSpecManifest = manifest
10361036
} else {
1037+
job.ServiceAccount = newScheduledWorkflow.Spec.ServiceAccount
10371038
job.PipelineSpec.PipelineSpecManifest = manifest
10381039
}
10391040
return r.jobStore.CreateJob(job)

backend/src/apiserver/template/template_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,10 @@ func TestScheduledWorkflow(t *testing.T) {
220220
Parameters: []scheduledworkflow.Parameter{{Name: "y", Value: "\"world\""}},
221221
Spec: "",
222222
},
223-
PipelineId: "1",
224-
PipelineName: "pipeline name",
225-
NoCatchup: util.BoolPointer(true),
223+
PipelineId: "1",
224+
PipelineName: "pipeline name",
225+
NoCatchup: util.BoolPointer(true),
226+
ServiceAccount: "pipeline-runner",
226227
},
227228
}
228229

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, ownerReferences []metav1
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)
@@ -135,7 +137,7 @@ func (t *V2Spec) ScheduledWorkflow(modelJob *model.Job, ownerReferences []metav1
135137
PipelineId: modelJob.PipelineId,
136138
PipelineName: modelJob.PipelineName,
137139
PipelineVersionId: modelJob.PipelineVersionId,
138-
ServiceAccount: modelJob.ServiceAccount,
140+
ServiceAccount: executionSpec.ServiceAccount(),
139141
},
140142
}
141143
return scheduledWorkflow, nil

0 commit comments

Comments
 (0)