From c4ca5c3db41181d5b5255e62980aa8c4259e680a Mon Sep 17 00:00:00 2001 From: Khanh Tran <32532742+khanhtc1202@users.noreply.github.com> Date: Mon, 30 Sep 2024 17:17:04 +0900 Subject: [PATCH] Add requires for stages in case of multi plugins quicksync pattern (#5239) Signed-off-by: khanhtc1202 --- pkg/app/pipedv1/controller/planner.go | 12 ++++++++++++ pkg/app/pipedv1/controller/planner_test.go | 10 ++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/pkg/app/pipedv1/controller/planner.go b/pkg/app/pipedv1/controller/planner.go index 13efadba7a..fe079f7fc8 100644 --- a/pkg/app/pipedv1/controller/planner.go +++ b/pkg/app/pipedv1/controller/planner.go @@ -422,6 +422,18 @@ func (p *planner) buildQuickSyncStages(ctx context.Context, cfg *config.GenericA sort.Sort(model.PipelineStages(stages)) sort.Sort(model.PipelineStages(rollbackStages)) + // In case there is more than one forward stage, build requires for each stage + // based on the order of stages. + if len(stages) > 1 { + preStageID := "" + for _, s := range stages { + if preStageID != "" { + s.Requires = []string{preStageID} + } + preStageID = s.Id + } + } + stages = append(stages, rollbackStages...) if len(stages) == 0 { return nil, fmt.Errorf("unable to build quick sync stages for deployment") diff --git a/pkg/app/pipedv1/controller/planner_test.go b/pkg/app/pipedv1/controller/planner_test.go index 9f57817686..8b0bdc9966 100644 --- a/pkg/app/pipedv1/controller/planner_test.go +++ b/pkg/app/pipedv1/controller/planner_test.go @@ -185,8 +185,9 @@ func TestBuildQuickSyncStages(t *testing.T) { Index: 0, }, { - Id: "plugin-2-stage-1", - Index: 1, + Id: "plugin-2-stage-1", + Index: 1, + Requires: []string{"plugin-1-stage-1"}, }, { Id: "plugin-1-rollback", @@ -244,8 +245,9 @@ func TestBuildQuickSyncStages(t *testing.T) { Index: 0, }, { - Id: "plugin-2-stage-1", - Index: 1, + Id: "plugin-2-stage-1", + Index: 1, + Requires: []string{"plugin-1-stage-1"}, }, }, },