Skip to content

Commit

Permalink
UPSTREAM: <carry>: Fixed workflow's ServiceAccountName
Browse files Browse the repository at this point in the history
Signed-off-by: Helber Belmiro <[email protected]>
  • Loading branch information
hbelmiro committed Jan 23, 2025
1 parent d4a6ec4 commit 499f1ea
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 10 deletions.
8 changes: 6 additions & 2 deletions backend/src/apiserver/resource/resource_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions backend/src/apiserver/server/fakes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions backend/src/apiserver/server/job_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
15 changes: 12 additions & 3 deletions backend/src/apiserver/template/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,23 @@ 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",
Kind: "ScheduledWorkflow",
},
ObjectMeta: metav1.ObjectMeta{
GenerateName: "name1",
OwnerReferences: []metav1.OwnerReference{},
OwnerReferences: ownerReferences,
},
Spec: scheduledworkflow.ScheduledWorkflowSpec{
Enabled: true,
Expand All @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions backend/src/apiserver/template/v2_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"encoding/json"
"errors"
"fmt"
wfapi "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
"io"
"regexp"
"strings"
Expand Down Expand Up @@ -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})
}
Expand Down

0 comments on commit 499f1ea

Please sign in to comment.