Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(operator): include detailed information about task/evaluation failure in span #445

Merged
merged 12 commits into from
Nov 22, 2022
Merged
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
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