Skip to content

Commit

Permalink
feat(operator): include detailed information about task/evaluation fa…
Browse files Browse the repository at this point in the history
…ilure in span (#445)

Fixes #396
  • Loading branch information
odubajDT authored Nov 22, 2022
1 parent 8872b3c commit 94de8d6
Show file tree
Hide file tree
Showing 7 changed files with 600 additions and 4 deletions.
8 changes: 4 additions & 4 deletions operator/api/v1alpha1/common/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/stretchr/testify/require"
)

func TestKeptnKeptnState_IsCompleted(t *testing.T) {
func TestKeptnState_IsCompleted(t *testing.T) {
tests := []struct {
State KeptnState
Want bool
Expand Down Expand Up @@ -36,7 +36,7 @@ func TestKeptnKeptnState_IsCompleted(t *testing.T) {
}
}

func TestKeptnKeptnState_IsSucceeded(t *testing.T) {
func TestKeptnState_IsSucceeded(t *testing.T) {
tests := []struct {
State KeptnState
Want bool
Expand All @@ -57,7 +57,7 @@ func TestKeptnKeptnState_IsSucceeded(t *testing.T) {
}
}

func TestKeptnKeptnState_IsFailed(t *testing.T) {
func TestKeptnState_IsFailed(t *testing.T) {
tests := []struct {
State KeptnState
Want bool
Expand All @@ -78,7 +78,7 @@ func TestKeptnKeptnState_IsFailed(t *testing.T) {
}
}

func TestKeptnKeptnState_IsCancelled(t *testing.T) {
func TestKeptnState_IsCancelled(t *testing.T) {
tests := []struct {
State KeptnState
Want bool
Expand Down
26 changes: 26 additions & 0 deletions operator/api/v1alpha1/common/phases.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,38 @@
package common

import "strings"

type KeptnPhase KeptnPhaseType

type KeptnPhaseType struct {
LongName string
ShortName string
}

func (p KeptnPhaseType) IsEvaluation() bool {
return strings.Contains(p.ShortName, "DeployEvaluations")
}

func (p KeptnPhaseType) IsPreEvaluation() bool {
return strings.Contains(p.ShortName, "PreDeployEvaluations")
}

func (p KeptnPhaseType) IsPostEvaluation() bool {
return strings.Contains(p.ShortName, "PostDeployEvaluations")
}

func (p KeptnPhaseType) IsTask() bool {
return strings.Contains(p.ShortName, "DeployTasks")
}

func (p KeptnPhaseType) IsPreTask() bool {
return strings.Contains(p.ShortName, "PreDeployTasks")
}

func (p KeptnPhaseType) IsPostTask() bool {
return strings.Contains(p.ShortName, "PostDeployTasks")
}

var (
PhaseWorkloadPreDeployment = KeptnPhaseType{LongName: "Workload Pre-Deployment Tasks", ShortName: "WorkloadPreDeployTasks"}
PhaseWorkloadPostDeployment = KeptnPhaseType{LongName: "Workload Post-Deployment Tasks", ShortName: "WorkloadPostDeployTasks"}
Expand Down
229 changes: 229 additions & 0 deletions operator/api/v1alpha1/common/phases_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
package common

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestKeptnPhaseType_IsEvaluation(t *testing.T) {
tests := []struct {
State KeptnPhaseType
Want bool
}{
{
State: PhaseWorkloadDeployment,
Want: false,
},
{
State: PhaseWorkloadPostEvaluation,
Want: true,
},
{
State: PhaseWorkloadPreEvaluation,
Want: true,
},
{
State: PhaseAppPostEvaluation,
Want: true,
},
{
State: PhaseAppPreEvaluation,
Want: true,
},
{
State: PhaseAppPreDeployment,
Want: false,
},
}
for _, tt := range tests {
t.Run("", func(t *testing.T) {
require.Equal(t, tt.State.IsEvaluation(), tt.Want)
})
}
}

func TestKeptnPhaseType_IsPreEvaluation(t *testing.T) {
tests := []struct {
State KeptnPhaseType
Want bool
}{
{
State: PhaseWorkloadDeployment,
Want: false,
},
{
State: PhaseWorkloadPostEvaluation,
Want: false,
},
{
State: PhaseWorkloadPreEvaluation,
Want: true,
},
{
State: PhaseAppPostEvaluation,
Want: false,
},
{
State: PhaseAppPreEvaluation,
Want: true,
},
{
State: PhaseAppPreDeployment,
Want: false,
},
}
for _, tt := range tests {
t.Run("", func(t *testing.T) {
require.Equal(t, tt.State.IsPreEvaluation(), tt.Want)
})
}
}

func TestKeptnPhaseType_IsPostEvaluation(t *testing.T) {
tests := []struct {
State KeptnPhaseType
Want bool
}{
{
State: PhaseWorkloadDeployment,
Want: false,
},
{
State: PhaseWorkloadPostEvaluation,
Want: true,
},
{
State: PhaseWorkloadPreEvaluation,
Want: false,
},
{
State: PhaseAppPostEvaluation,
Want: true,
},
{
State: PhaseAppPreEvaluation,
Want: false,
},
{
State: PhaseAppPreDeployment,
Want: false,
},
}
for _, tt := range tests {
t.Run("", func(t *testing.T) {
require.Equal(t, tt.State.IsPostEvaluation(), tt.Want)
})
}
}

func TestKeptnPhaseType_IsTask(t *testing.T) {
tests := []struct {
State KeptnPhaseType
Want bool
}{
{
State: PhaseWorkloadDeployment,
Want: false,
},
{
State: PhaseWorkloadPostDeployment,
Want: true,
},
{
State: PhaseWorkloadPreDeployment,
Want: true,
},
{
State: PhaseAppPostDeployment,
Want: true,
},
{
State: PhaseAppPreDeployment,
Want: true,
},
{
State: PhaseAppPreEvaluation,
Want: false,
},
}
for _, tt := range tests {
t.Run("", func(t *testing.T) {
require.Equal(t, tt.State.IsTask(), tt.Want)
})
}
}

func TestKeptnPhaseType_IsPreTask(t *testing.T) {
tests := []struct {
State KeptnPhaseType
Want bool
}{
{
State: PhaseWorkloadDeployment,
Want: false,
},
{
State: PhaseWorkloadPostDeployment,
Want: false,
},
{
State: PhaseWorkloadPreDeployment,
Want: true,
},
{
State: PhaseAppPostDeployment,
Want: false,
},
{
State: PhaseAppPreDeployment,
Want: true,
},
{
State: PhaseAppPreEvaluation,
Want: false,
},
}
for _, tt := range tests {
t.Run("", func(t *testing.T) {
require.Equal(t, tt.State.IsPreTask(), tt.Want)
})
}
}

func TestKeptnPhaseType_IsPostTask(t *testing.T) {
tests := []struct {
State KeptnPhaseType
Want bool
}{
{
State: PhaseWorkloadDeployment,
Want: false,
},
{
State: PhaseWorkloadPostDeployment,
Want: true,
},
{
State: PhaseWorkloadPreDeployment,
Want: false,
},
{
State: PhaseAppPostDeployment,
Want: true,
},
{
State: PhaseAppPreDeployment,
Want: false,
},
{
State: PhaseAppPreEvaluation,
Want: false,
},
}
for _, tt := range tests {
t.Run("", func(t *testing.T) {
require.Equal(t, tt.State.IsPostTask(), tt.Want)
})
}
}
1 change: 1 addition & 0 deletions operator/api/v1alpha1/keptntask_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type KeptnTaskStatus struct {
JobName string `json:"jobName,omitempty"`
// +kubebuilder:default:=Pending
Status common.KeptnState `json:"status,omitempty"`
Message string `json:"message,omitempty"`
StartTime metav1.Time `json:"startTime,omitempty"`
EndTime metav1.Time `json:"endTime,omitempty"`
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
Expand Down
2 changes: 2 additions & 0 deletions operator/config/crd/bases/lifecycle.keptn.sh_keptntasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ spec:
type: string
jobName:
type: string
message:
type: string
startTime:
format: date-time
type: string
Expand Down
Loading

0 comments on commit 94de8d6

Please sign in to comment.