Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(backend): Fixed ServiceAccount in job creation #11481

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions backend/src/apiserver/resource/resource_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1005,18 +1005,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)
Expand Down
7 changes: 4 additions & 3 deletions backend/src/apiserver/template/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
}

Expand Down
6 changes: 4 additions & 2 deletions backend/src/apiserver/template/v2_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
Loading