Skip to content

Commit

Permalink
Use index from requests in buildQuickSyncPipeline (#5242)
Browse files Browse the repository at this point in the history
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
  • Loading branch information
Warashi authored Oct 1, 2024
1 parent c4ca5c3 commit c16aebb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
8 changes: 4 additions & 4 deletions pkg/app/pipedv1/plugin/kubernetes/deployment/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,24 @@ func MakeInitialStageMetadata(cfg config.PipelineStage) map[string]string {
}
}

func buildQuickSyncPipeline(autoRollback bool, now time.Time) []*model.PipelineStage {
func buildQuickSyncPipeline(index int32, autoRollback bool, now time.Time) []*model.PipelineStage {
var (
preStageID = ""
stage, _ = GetPredefinedStage(PredefinedStageK8sSync)
stages = []config.PipelineStage{stage}
out = make([]*model.PipelineStage, 0, len(stages))
)

for i, s := range stages {
for _, s := range stages {
id := s.ID
if id == "" {
id = fmt.Sprintf("stage-%d", i)
id = fmt.Sprintf("kubernetes-stage-%d", index)
}
stage := &model.PipelineStage{
Id: id,
Name: s.Name.String(),
Desc: s.Desc,
Index: int32(i),
Index: int32(index),
Predefined: true,
Visible: true,
Status: model.StageStatus_STAGE_NOT_STARTED_YET,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ func TestBuildQuickSyncPipeline(t *testing.T) {

tests := []struct {
name string
index int32
autoRollback bool
expected []*model.PipelineStage
}{
{
name: "without auto rollback",
index: 0,
autoRollback: false,
expected: []*model.PipelineStage{
{
Expand All @@ -52,6 +54,7 @@ func TestBuildQuickSyncPipeline(t *testing.T) {
},
{
name: "with auto rollback",
index: 0,
autoRollback: true,
expected: []*model.PipelineStage{
{
Expand Down Expand Up @@ -82,7 +85,7 @@ func TestBuildQuickSyncPipeline(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
actual := buildQuickSyncPipeline(tt.autoRollback, now)
actual := buildQuickSyncPipeline(tt.index, tt.autoRollback, now)
assert.Equal(t, tt.expected, actual)
})
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/pipedv1/plugin/kubernetes/deployment/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (a *DeploymentService) BuildPipelineSyncStages(context.Context, *deployment
// BuildQuickSyncStages implements deployment.DeploymentServiceServer.
func (a *DeploymentService) BuildQuickSyncStages(ctx context.Context, request *deployment.BuildQuickSyncStagesRequest) (*deployment.BuildQuickSyncStagesResponse, error) {
now := time.Now()
stages := buildQuickSyncPipeline(request.GetRollback(), now)
stages := buildQuickSyncPipeline(request.GetStageIndex(), request.GetRollback(), now)
return &deployment.BuildQuickSyncStagesResponse{
Stages: stages,
}, nil
Expand Down

0 comments on commit c16aebb

Please sign in to comment.