diff --git a/backend/src/apiserver/resource/resource_manager_test.go b/backend/src/apiserver/resource/resource_manager_test.go index 7a69344ddd2..280bf123bd9 100644 --- a/backend/src/apiserver/resource/resource_manager_test.go +++ b/backend/src/apiserver/resource/resource_manager_test.go @@ -55,6 +55,10 @@ func strPtr(i string) *string { func initEnvVars() { viper.Set(common.PodNamespace, "ns1") + viper.Set("OWNER_UID", "something") + viper.Set("OWNER_NAME", "test") + viper.Set("OWNER_API_VERSION", "datasciencepipelinesapplications.opendatahub.io/v1") + viper.Set("OWNER_KIND", "DataSciencePipelinesApplication") } type FakeBadObjectStore struct{} @@ -2380,7 +2384,7 @@ func TestCreateJob_ThroughWorkflowSpecV2(t *testing.T) { DisplayName: "j1", K8SName: "job-", Namespace: "ns1", - ServiceAccount: "pipeline-runner", + ServiceAccount: "pipeline-runner-test", Enabled: true, ExperimentId: DefaultFakeUUID, CreatedAtInSec: 2, @@ -3173,7 +3177,7 @@ func TestReportScheduledWorkflowResource_Success_withRuntimeParamsV2(t *testing. DisplayName: "j1", Namespace: "ns1", ExperimentId: job.ExperimentId, - ServiceAccount: "pipeline-runner", + ServiceAccount: "pipeline-runner-test", Enabled: false, UUID: actualJob.UUID, Conditions: "STATUS_UNSPECIFIED", diff --git a/backend/src/apiserver/server/fakes_test.go b/backend/src/apiserver/server/fakes_test.go index 70e50000bc9..858f26b1f14 100644 --- a/backend/src/apiserver/server/fakes_test.go +++ b/backend/src/apiserver/server/fakes_test.go @@ -139,6 +139,10 @@ var referencesOfInvalidPipelineVersion = []*apiv1beta1.ResourceReference{ // This automatically runs before all the tests. func initEnvVars() { viper.Set(common.PodNamespace, "ns1") + viper.Set("OWNER_UID", "something") + viper.Set("OWNER_NAME", "test") + viper.Set("OWNER_API_VERSION", "datasciencepipelinesapplications.opendatahub.io/v1") + viper.Set("OWNER_KIND", "DataSciencePipelinesApplication") } func initWithExperiment(t *testing.T) (*resource.FakeClientManager, *resource.ResourceManager, *model.Experiment) { diff --git a/backend/src/apiserver/server/job_server_test.go b/backend/src/apiserver/server/job_server_test.go index 6e53a2edb58..789e4019249 100644 --- a/backend/src/apiserver/server/job_server_test.go +++ b/backend/src/apiserver/server/job_server_test.go @@ -450,7 +450,7 @@ func TestCreateJob_V2(t *testing.T) { expectedJob_V2 := &apiv1beta1.Job{ Id: "123e4567-e89b-12d3-a456-426655440000", Name: "job1", - ServiceAccount: "pipeline-runner", + ServiceAccount: "pipeline-runner-test", Enabled: true, MaxConcurrency: 1, Trigger: &apiv1beta1.Trigger{ @@ -540,7 +540,7 @@ func TestListRecurringRuns_MultiUser(t *testing.T) { expectedRecurringRun := &apiv2beta1.RecurringRun{ RecurringRunId: "123e4567-e89b-12d3-a456-426655440000", DisplayName: "recurring_run_1", - ServiceAccount: "pipeline-runner", + ServiceAccount: "pipeline-runner-test", Mode: apiv2beta1.RecurringRun_ENABLE, Namespace: "ns1", MaxConcurrency: 1, @@ -972,7 +972,7 @@ func TestCreateRecurringRun(t *testing.T) { expectedRecurringRun := &apiv2beta1.RecurringRun{ RecurringRunId: "123e4567-e89b-12d3-a456-426655440000", DisplayName: "recurring_run_1", - ServiceAccount: "pipeline-runner", + ServiceAccount: "pipeline-runner-test", Mode: apiv2beta1.RecurringRun_ENABLE, Namespace: "ns1", MaxConcurrency: 1, @@ -1034,7 +1034,7 @@ func TestGetRecurringRun(t *testing.T) { expectedRecurringRun := &apiv2beta1.RecurringRun{ RecurringRunId: "123e4567-e89b-12d3-a456-426655440000", DisplayName: "recurring_run_1", - ServiceAccount: "pipeline-runner", + ServiceAccount: "pipeline-runner-test", Mode: apiv2beta1.RecurringRun_ENABLE, Namespace: "ns1", MaxConcurrency: 1, @@ -1099,7 +1099,7 @@ func TestListRecurringRuns(t *testing.T) { expectedRecurringRun := &apiv2beta1.RecurringRun{ RecurringRunId: "123e4567-e89b-12d3-a456-426655440000", DisplayName: "recurring_run_1", - ServiceAccount: "pipeline-runner", + ServiceAccount: "pipeline-runner-test", Mode: apiv2beta1.RecurringRun_ENABLE, Namespace: "ns1", MaxConcurrency: 1, diff --git a/backend/src/apiserver/template/template_test.go b/backend/src/apiserver/template/template_test.go index 0c0cdc729ec..7ea193a6b01 100644 --- a/backend/src/apiserver/template/template_test.go +++ b/backend/src/apiserver/template/template_test.go @@ -197,6 +197,15 @@ func TestScheduledWorkflow(t *testing.T) { }, } + ownerReferences := []metav1.OwnerReference{ + { + APIVersion: "datasciencepipelinesapplications.opendatahub.io/v1", + Kind: "DataSciencePipelinesApplication", + Name: "test", + UID: "something", + }, + } + expectedScheduledWorkflow := scheduledworkflow.ScheduledWorkflow{ TypeMeta: metav1.TypeMeta{ APIVersion: "kubeflow.org/v2beta1", @@ -204,7 +213,7 @@ func TestScheduledWorkflow(t *testing.T) { }, ObjectMeta: metav1.ObjectMeta{ GenerateName: "name1", - OwnerReferences: []metav1.OwnerReference{}, + OwnerReferences: ownerReferences, }, Spec: scheduledworkflow.ScheduledWorkflowSpec{ Enabled: true, @@ -223,11 +232,11 @@ func TestScheduledWorkflow(t *testing.T) { PipelineId: "1", PipelineName: "pipeline name", NoCatchup: util.BoolPointer(true), - ServiceAccount: "pipeline-runner", + ServiceAccount: "pipeline-runner-test", }, } - actualScheduledWorkflow, err := v2Template.ScheduledWorkflow(modelJob, []metav1.OwnerReference{}) + actualScheduledWorkflow, err := v2Template.ScheduledWorkflow(modelJob, ownerReferences) assert.Nil(t, err) // We don't compare this field because it changes with every driver/launcher image release. diff --git a/backend/src/apiserver/template/v2_template.go b/backend/src/apiserver/template/v2_template.go index 22ad326fbe9..fc40739c46a 100644 --- a/backend/src/apiserver/template/v2_template.go +++ b/backend/src/apiserver/template/v2_template.go @@ -19,6 +19,7 @@ import ( "encoding/json" "errors" "fmt" + wfapi "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1" "io" "regexp" "strings" @@ -79,7 +80,19 @@ func (t *V2Spec) ScheduledWorkflow(modelJob *model.Job, ownerReferences []metav1 var obj interface{} if util.CurrentExecutionType() == util.ArgoWorkflow { + var dspaName = "" + for _, ownerRef := range ownerReferences { + if ownerRef.Kind == "DataSciencePipelinesApplication" { + dspaName = ownerRef.Name + } + } + + if dspaName == "" { + return nil, errors.New("failed to get the name of the DataSciencePipelinesApplication to mount the ServiceAccountName") + } + obj, err = argocompiler.Compile(job, kubernetesSpec, nil) + obj.(*wfapi.Workflow).Spec.ServiceAccountName += "-" + dspaName } else if util.CurrentExecutionType() == util.TektonPipelineRun { obj, err = tektoncompiler.Compile(job, kubernetesSpec, &tektoncompiler.Options{LauncherImage: Launcher}) }