Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
fix(shipyard-controller): Consider parallel stages when trying to set…
Browse files Browse the repository at this point in the history
… overall sequence state to finished (#7237)

Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
  • Loading branch information
bacherfl committed Mar 23, 2022
1 parent 752d7d6 commit 5ac31c4
Show file tree
Hide file tree
Showing 6 changed files with 476 additions and 1 deletion.
9 changes: 9 additions & 0 deletions shipyard-controller/handler/sequencehooks/sequencestate.go
Expand Up @@ -235,6 +235,15 @@ func (smv *SequenceStateMaterializedView) updateOverallSequenceState(eventScope
return
}

// if the sequence should be set to 'finished' we need to ensure that all sequences in all stages are finished
if status == models.SequenceFinished {
for index := range state.Stages {
// if we still have an unfinished stage, we can not set the overall sequence state to 'finished'
if state.Stages[index].State == models.SequenceTriggeredState {
return
}
}
}
state.State = status
if err := smv.SequenceStateRepo.UpdateSequenceState(*state); err != nil {
log.Errorf("could not update sequence state: %s", err.Error())
Expand Down
56 changes: 55 additions & 1 deletion shipyard-controller/handler/sequencehooks/sequencestate_test.go
Expand Up @@ -228,7 +228,16 @@ func TestSequenceStateMaterializedView_OnSequenceFinished(t *testing.T) {
Project: "my-project",
Shkeptncontext: "my-context",
State: "triggered",
Stages: nil,
Stages: []models.SequenceStateStage{
{
Name: "dev",
State: "succeeded",
},
{
Name: "dev",
State: "succeeded",
},
},
},
},
}, nil
Expand All @@ -251,6 +260,51 @@ func TestSequenceStateMaterializedView_OnSequenceFinished(t *testing.T) {
},
expectUpdateToBeCalled: true,
},
{
name: "try to finish sequence - not all stages finished yet",
fields: SequenceStateMVTestFields{
SequenceStateRepo: &db_mock.SequenceStateRepoMock{
FindSequenceStatesFunc: func(filter models.StateFilter) (*models.SequenceStates, error) {
return &models.SequenceStates{
States: []models.SequenceState{
{
Name: "my-sequence",
Service: "my-service",
Project: "my-project",
Shkeptncontext: "my-context",
State: "triggered",
Stages: []models.SequenceStateStage{
{
Name: "dev",
State: "succeeded",
},
{
Name: "dev",
State: "triggered",
},
},
},
},
}, nil
},
UpdateSequenceStateFunc: func(state models.SequenceState) error {
return nil
},
},
},
args: args{
event: models.Event{
Data: keptnv2.EventData{
Project: "my-project",
Stage: "my-stage",
Service: "my-service",
},
Shkeptncontext: "my-context",
Type: common.Stringp("my-type"),
},
},
expectUpdateToBeCalled: false,
},
{
name: "invalid event scope - do not update",
fields: SequenceStateMVTestFields{
Expand Down

0 comments on commit 5ac31c4

Please sign in to comment.