Skip to content

Commit

Permalink
fix Redeploy pipelineYmlName (#1570) (#1656)
Browse files Browse the repository at this point in the history
Co-authored-by: pipipipipi43 <32703277+pipipipipi43@users.noreply.github.com>
  • Loading branch information
erda-bot and pipipipipi43 authored Sep 2, 2021
1 parent 93627d5 commit 9d68b46
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
7 changes: 6 additions & 1 deletion modules/dop/services/cdp/cdp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
}
Expand Down
6 changes: 5 additions & 1 deletion modules/orchestrator/services/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
43 changes: 43 additions & 0 deletions modules/orchestrator/services/runtime/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
}
})
}
}

0 comments on commit 9d68b46

Please sign in to comment.