Skip to content

Commit

Permalink
PR review
Browse files Browse the repository at this point in the history
Signed-off-by: odubajDT <[email protected]>
  • Loading branch information
odubajDT committed Feb 26, 2024
1 parent 81222c7 commit 3e87685
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 9 deletions.
3 changes: 2 additions & 1 deletion lifecycle-operator/apis/lifecycle/v1beta1/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ func GetOverallState(s StatusSummary) KeptnState {
return StateSucceeded
}

func GetOverallStateBlockedDeployment(state KeptnState, blockedDeployment bool) KeptnState {
func GetOverallStateBlockedDeployment(s StatusSummary, blockedDeployment bool) KeptnState {
state := GetOverallState(s)
if !blockedDeployment && state == StateFailed {
return StateWarning
}
Expand Down
40 changes: 36 additions & 4 deletions lifecycle-operator/apis/lifecycle/v1beta1/common/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,42 @@ func Test_GeOverallState(t *testing.T) {
}

func Test_GeOverallStateBlockedDeployment(t *testing.T) {
require.Equal(t, StateFailed, GetOverallStateBlockedDeployment(StateFailed, true))
require.Equal(t, StateWarning, GetOverallStateBlockedDeployment(StateFailed, false))
require.Equal(t, StateSucceeded, GetOverallStateBlockedDeployment(StateSucceeded, true))
require.Equal(t, StateSucceeded, GetOverallStateBlockedDeployment(StateSucceeded, false))
tests := []struct {
Name string
Summary StatusSummary
Block bool
Want KeptnState
}{
{
Name: "failed blocking",
Summary: StatusSummary{0, 0, 1, 0, 0, 0, 0},
Block: true,
Want: StateFailed,
},
{
Name: "succeeded blocking",
Summary: StatusSummary{1, 0, 0, 1, 0, 0, 0},
Block: true,
Want: StateSucceeded,
},
{
Name: "failed non-blocking",
Summary: StatusSummary{0, 0, 1, 0, 0, 0, 0},
Block: false,
Want: StateWarning,
},
{
Name: "succeeded non-blocking",
Summary: StatusSummary{1, 0, 0, 1, 0, 0, 0},
Block: false,
Want: StateSucceeded,
},
}
for _, tt := range tests {
t.Run(tt.Name, func(t *testing.T) {
require.Equal(t, GetOverallStateBlockedDeployment(tt.Summary, tt.Block), tt.Want)
})
}
}

func Test_TruncateString(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (r *KeptnAppVersionReconciler) reconcilePhase(ctx context.Context, phaseCtx
if err != nil {
return apicommon.StateUnknown, err
}
overallState := apicommon.GetOverallStateBlockedDeployment(apicommon.GetOverallState(state), r.Config.GetBlockDeployment())
overallState := apicommon.GetOverallStateBlockedDeployment(state, r.Config.GetBlockDeployment())

switch checkType {
case apicommon.PreDeploymentCheckType:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (r *KeptnAppVersionReconciler) reconcilePrePostEvaluation(ctx context.Conte
return apicommon.StateUnknown, err
}

overallState := apicommon.GetOverallStateBlockedDeployment(apicommon.GetOverallState(state), r.Config.GetBlockDeployment())
overallState := apicommon.GetOverallStateBlockedDeployment(state, r.Config.GetBlockDeployment())

switch checkType {
case apicommon.PreDeploymentEvaluationCheckType:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (r *KeptnWorkloadVersionReconciler) reconcilePrePostDeployment(ctx context.
return apicommon.StateUnknown, err
}

overallState := apicommon.GetOverallStateBlockedDeployment(apicommon.GetOverallState(state), r.Config.GetBlockDeployment())
overallState := apicommon.GetOverallStateBlockedDeployment(state, r.Config.GetBlockDeployment())

switch checkType {
case apicommon.PreDeploymentCheckType:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (r *KeptnWorkloadVersionReconciler) reconcilePrePostEvaluation(ctx context.
return apicommon.StateUnknown, err
}

overallState := apicommon.GetOverallStateBlockedDeployment(apicommon.GetOverallState(state), r.Config.GetBlockDeployment())
overallState := apicommon.GetOverallStateBlockedDeployment(state, r.Config.GetBlockDeployment())

switch checkType {
case apicommon.PreDeploymentEvaluationCheckType:
Expand Down

0 comments on commit 3e87685

Please sign in to comment.