From 9d68b46a038f384749de804bd51157f8d6d5db7d Mon Sep 17 00:00:00 2001 From: erda-bot <81558540+erda-bot@users.noreply.github.com> Date: Thu, 2 Sep 2021 19:07:25 +0800 Subject: [PATCH] fix Redeploy pipelineYmlName (#1570) (#1656) Co-authored-by: pipipipipi43 <32703277+pipipipipi43@users.noreply.github.com> --- modules/dop/services/cdp/cdp.go | 7 ++- .../orchestrator/services/runtime/runtime.go | 6 ++- .../services/runtime/runtime_test.go | 43 +++++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/modules/dop/services/cdp/cdp.go b/modules/dop/services/cdp/cdp.go index 385031ef71a..a601276aa84 100644 --- a/modules/dop/services/cdp/cdp.go +++ b/modules/dop/services/cdp/cdp.go @@ -57,6 +57,11 @@ func (cdp *CDP) CdpNotifyProcess(pipelineEvent *apistructs.PipelineInstanceEvent if err != nil { return err } + org, err := cdp.bdl.GetOrg(orgID) + if err != nil { + logrus.Errorf("failed to get org info err: %s", err) + return err + } pipelineDetail, err := cdp.bdl.GetPipeline(pipelineData.PipelineID) if err != nil { return err @@ -170,7 +175,7 @@ func (cdp *CDP) CdpNotifyProcess(pipelineEvent *apistructs.PipelineInstanceEvent "appName": pipelineDetail.ApplicationName, "projectID": strconv.FormatUint(pipelineDetail.ProjectID, 10), "projectName": pipelineDetail.ProjectName, - "orgName": pipelineDetail.OrgName, + "orgName": org.Name, "branch": pipelineDetail.Branch, "uiPublicURL": conf.UIPublicURL(), } diff --git a/modules/orchestrator/services/runtime/runtime.go b/modules/orchestrator/services/runtime/runtime.go index 7a0cf9b7e34..ff2eccb9672 100644 --- a/modules/orchestrator/services/runtime/runtime.go +++ b/modules/orchestrator/services/runtime/runtime.go @@ -454,7 +454,7 @@ func (r *Runtime) RedeployPipeline(operator user.ID, orgID uint64, runtimeID uin apistructs.LabelAppName: app.Name, apistructs.LabelProjectName: app.ProjectName, }, - PipelineYmlName: fmt.Sprintf("dice-deploy-redeploy-%d", runtime.ID), + PipelineYmlName: getRedeployPipelineYmlName(*runtime), ClusterName: runtime.ClusterName, PipelineSource: apistructs.PipelineSourceDice, AutoRunAtOnce: true, @@ -1908,3 +1908,7 @@ func init() { queryStringDecoder = schema.NewDecoder() queryStringDecoder.IgnoreUnknownKeys(true) } + +func getRedeployPipelineYmlName(runtime dbclient.Runtime) string { + return fmt.Sprintf("%d/%s/%s/pipeline.yml", runtime.ApplicationID, runtime.Workspace, runtime.Name) +} diff --git a/modules/orchestrator/services/runtime/runtime_test.go b/modules/orchestrator/services/runtime/runtime_test.go index d6b22c4ef01..0ce8b1adf0e 100644 --- a/modules/orchestrator/services/runtime/runtime_test.go +++ b/modules/orchestrator/services/runtime/runtime_test.go @@ -24,6 +24,7 @@ import ( "github.com/erda-project/erda/apistructs" "github.com/erda-project/erda/bundle" + "github.com/erda-project/erda/modules/orchestrator/dbclient" "github.com/erda-project/erda/pkg/parser/diceyml" ) @@ -102,3 +103,45 @@ func TestGetRollbackConfig(t *testing.T) { assert.Equal(t, 6, cfg[3]["STAGING"]) assert.Equal(t, 8, cfg[3]["PROD"]) } + +func Test_getRedeployPipelineYmlName(t *testing.T) { + type args struct { + runtime dbclient.Runtime + } + tests := []struct { + name string + args args + want string + }{ + // TODO: Add test cases + { + name: "Filled in the space and scene set", + args: args{ + runtime: dbclient.Runtime{ + ApplicationID: 1, + Workspace: "PORD", + Name: "master", + }, + }, + want: "1/PORD/master/pipeline.yml", + }, + { + name: "Filled in the space and scene set", + args: args{ + runtime: dbclient.Runtime{ + ApplicationID: 4, + Workspace: "TEST", + Name: "master", + }, + }, + want: "4/TEST/master/pipeline.yml", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := getRedeployPipelineYmlName(tt.args.runtime); got != tt.want { + t.Errorf("getRedeployPipelineYmlName() = %v, want %v", got, tt.want) + } + }) + } +}