Skip to content

Commit

Permalink
fix(controller): Promotion on verification failure (#3098)
Browse files Browse the repository at this point in the history
Signed-off-by: Hidde Beydals <[email protected]>
(cherry picked from commit 2655a03)
  • Loading branch information
hiddeco authored and github-actions[bot] committed Dec 9, 2024
1 parent 1689f86 commit 53e3945
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 4 deletions.
9 changes: 5 additions & 4 deletions internal/controller/stages/regular_stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,12 +637,13 @@ func (r *RegularStageReconciler) syncPromotions(
}

// If we are in a healthy state, the current Freight needs to be verified
// before we can allow the next Promotion to start. If we are unhealthy,
// then we can allow the next Promotion to start immediately as the
// expectation is that the Promotion can fix the issue.
// before we can allow the next Promotion to start. If we are unhealthy
// or the verification failed, then we can allow the next Promotion to
// start immediately as the expectation is that the Promotion can fix the
// issue.
if stage.Status.Health == nil || stage.Status.Health.Status != kargoapi.HealthStateUnhealthy {
curVI := curFreight.VerificationHistory.Current()
if curVI == nil || curVI.Phase != kargoapi.VerificationPhaseSuccessful {
if curVI == nil || !curVI.Phase.IsTerminal() {
logger.Debug("current Freight needs to be verified before allowing new promotions to start")
conditions.Delete(&newStatus, kargoapi.ConditionTypePromoting)
return newStatus, hasNonTerminalPromotions, nil
Expand Down
59 changes: 59 additions & 0 deletions internal/controller/stages/regular_stages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,65 @@ func TestRegularStageReconciler_syncPromotions(t *testing.T) {
assert.Contains(t, promotingCond.Message, "Pending")
},
},
{
name: "allows promotion when verification failed",
stage: &kargoapi.Stage{
ObjectMeta: metav1.ObjectMeta{
Namespace: "fake-project",
Name: "test-stage",
},
Status: kargoapi.StageStatus{
Health: &kargoapi.Health{
Status: kargoapi.HealthStateHealthy,
},
FreightHistory: kargoapi.FreightHistory{
{
ID: "current-collection",
Freight: map[string]kargoapi.FreightReference{
"warehouse-1": {Name: "current-freight"},
},
VerificationHistory: []kargoapi.VerificationInfo{
{
Phase: kargoapi.VerificationPhaseFailed,
},
},
},
},
},
},
objects: []client.Object{
&kargoapi.Promotion{
ObjectMeta: metav1.ObjectMeta{
Name: "pending-promotion",
Namespace: "fake-project",
},
Spec: kargoapi.PromotionSpec{
Stage: "test-stage",
},
Status: kargoapi.PromotionStatus{
Phase: kargoapi.PromotionPhasePending,
Freight: &kargoapi.FreightReference{
Name: "new-freight",
},
},
},
},
assertions: func(t *testing.T, status kargoapi.StageStatus, hasPendingPromotions bool, err error) {
require.NoError(t, err)
assert.True(t, hasPendingPromotions)

// Should allow promotion since there's no verification to wait for
require.NotNil(t, status.CurrentPromotion)
assert.Equal(t, "pending-promotion", status.CurrentPromotion.Name)
assert.Equal(t, "new-freight", status.CurrentPromotion.Freight.Name)

promotingCond := conditions.Get(&status, kargoapi.ConditionTypePromoting)
require.NotNil(t, promotingCond)
assert.Equal(t, metav1.ConditionTrue, promotingCond.Status)
assert.Equal(t, "ActivePromotion", promotingCond.Reason)
assert.Contains(t, promotingCond.Message, "Pending")
},
},
{
name: "skips older promotions after last promotion",
stage: &kargoapi.Stage{
Expand Down

0 comments on commit 53e3945

Please sign in to comment.