Skip to content

Commit

Permalink
polishing + phase tests
Browse files Browse the repository at this point in the history
Signed-off-by: odubajDT <[email protected]>
  • Loading branch information
odubajDT committed Nov 22, 2022
1 parent a155945 commit 8c1dee7
Show file tree
Hide file tree
Showing 14 changed files with 111 additions and 32 deletions.
36 changes: 34 additions & 2 deletions operator/api/v1alpha1/common/phases.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,37 @@ func (p KeptnPhaseType) IsPostTask() bool {
return strings.Contains(p.ShortName, "PostDeployTasks")
}

func GetShortPhaseName(phase string) string {
var phases = []KeptnPhaseType{
PhaseWorkloadPreDeployment,
PhaseWorkloadPostDeployment,
PhaseWorkloadPreEvaluation,
PhaseWorkloadPostEvaluation,
PhaseWorkloadDeployment,
PhaseAppPreDeployment,
PhaseAppPostDeployment,
PhaseAppPreEvaluation,
PhaseAppPostEvaluation,
PhaseAppDeployment,
PhaseCompleted,
PhaseCancelled,
}

for _, p := range phases {
if phase == p.ShortName {
return p.ShortName
}
}

for _, p := range phases {
if phase == p.LongName {
return p.ShortName
}
}

return ""
}

var (
PhaseWorkloadPreDeployment = KeptnPhaseType{LongName: "Workload Pre-Deployment Tasks", ShortName: "WorkloadPreDeployTasks"}
PhaseWorkloadPostDeployment = KeptnPhaseType{LongName: "Workload Post-Deployment Tasks", ShortName: "WorkloadPostDeployTasks"}
Expand All @@ -55,9 +86,10 @@ var (
type PhaseTraceID map[string]propagation.MapCarrier

func (pid PhaseTraceID) SetPhaseTraceID(phase string, carrier propagation.MapCarrier) {
pid[phase] = carrier
pid[GetShortPhaseName(phase)] = carrier

}

func (pid PhaseTraceID) GetPhaseTraceID(phase string) propagation.MapCarrier {
return pid[phase]
return pid[GetShortPhaseName(phase)]
}
46 changes: 46 additions & 0 deletions operator/api/v1alpha1/common/phases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/propagation"
)

func TestKeptnPhaseType_IsEvaluation(t *testing.T) {
Expand Down Expand Up @@ -227,3 +228,48 @@ func TestKeptnPhaseType_IsPostTask(t *testing.T) {
})
}
}

func TestPhaseTraceID(t *testing.T) {
trace := PhaseTraceID{}

trace.SetPhaseTraceID(PhaseAppDeployment.LongName, propagation.MapCarrier{
"name": "trace",
"name2": "trace2",
})

require.Equal(t, PhaseTraceID{
PhaseAppDeployment.ShortName: propagation.MapCarrier{
"name": "trace",
"name2": "trace2",
},
}, trace)

trace.SetPhaseTraceID(PhaseWorkloadDeployment.ShortName, propagation.MapCarrier{
"name3": "trace3",
})

require.Equal(t, PhaseTraceID{
PhaseAppDeployment.ShortName: propagation.MapCarrier{
"name": "trace",
"name2": "trace2",
},
PhaseWorkloadDeployment.ShortName: propagation.MapCarrier{
"name3": "trace3",
},
}, trace)

require.Equal(t, propagation.MapCarrier{
"name": "trace",
"name2": "trace2",
}, trace.GetPhaseTraceID(PhaseAppDeployment.LongName))

require.Equal(t, propagation.MapCarrier{
"name3": "trace3",
}, trace.GetPhaseTraceID(PhaseWorkloadDeployment.ShortName))
}

func TestGetShortPhaseName(t *testing.T) {
require.Equal(t, "WorkloadPreDeployTasks", GetShortPhaseName("WorkloadPreDeployTasks"))
require.Equal(t, "WorkloadPreDeployTasks", GetShortPhaseName("Workload Pre-Deployment Tasks"))
require.Equal(t, "", GetShortPhaseName("Workload Pre-Deploycdddment Tasks"))
}
18 changes: 9 additions & 9 deletions operator/api/v1alpha1/keptnappversion_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ type KeptnAppVersionStatus struct {
// +kubebuilder:default:=Pending
PostDeploymentEvaluationStatus common.KeptnState `json:"postDeploymentEvaluationStatus,omitempty"`
// +kubebuilder:default:=Pending
WorkloadOverallStatus common.KeptnState `json:"workloadOverallStatus,omitempty"`
WorkloadStatus []WorkloadStatus `json:"workloadStatus,omitempty"`
CurrentPhase string `json:"currentPhase,omitempty"`
PreDeploymentTaskStatus []TaskStatus `json:"preDeploymentTaskStatus,omitempty"`
PostDeploymentTaskStatus []TaskStatus `json:"postDeploymentTaskStatus,omitempty"`
PreDeploymentEvaluationTaskStatus []EvaluationStatus `json:"preDeploymentEvaluationTaskStatus,omitempty"`
PostDeploymentEvaluationTaskStatus []EvaluationStatus `json:"postDeploymentEvaluationTaskStatus,omitempty"`
PhaseTraceIDs map[string]propagation.MapCarrier `json:"phaseTraceIDs,omitempty"`
WorkloadOverallStatus common.KeptnState `json:"workloadOverallStatus,omitempty"`
WorkloadStatus []WorkloadStatus `json:"workloadStatus,omitempty"`
CurrentPhase string `json:"currentPhase,omitempty"`
PreDeploymentTaskStatus []TaskStatus `json:"preDeploymentTaskStatus,omitempty"`
PostDeploymentTaskStatus []TaskStatus `json:"postDeploymentTaskStatus,omitempty"`
PreDeploymentEvaluationTaskStatus []EvaluationStatus `json:"preDeploymentEvaluationTaskStatus,omitempty"`
PostDeploymentEvaluationTaskStatus []EvaluationStatus `json:"postDeploymentEvaluationTaskStatus,omitempty"`
PhaseTraceIDs common.PhaseTraceID `json:"phaseTraceIDs,omitempty"`
// +kubebuilder:default:=Pending
Status common.KeptnState `json:"status,omitempty"`

Expand Down Expand Up @@ -378,7 +378,7 @@ func (a *KeptnAppVersion) CancelRemainingPhases(phase common.KeptnPhaseType) {

func (a *KeptnAppVersion) SetPhaseTraceID(phase string, carrier propagation.MapCarrier) {
if a.Status.PhaseTraceIDs == nil {
a.Status.PhaseTraceIDs = map[string]propagation.MapCarrier{}
a.Status.PhaseTraceIDs = common.PhaseTraceID{}
}
a.Status.PhaseTraceIDs[phase] = carrier
}
20 changes: 10 additions & 10 deletions operator/api/v1alpha1/keptnworkloadinstance_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ type KeptnWorkloadInstanceStatus struct {
// +kubebuilder:default:=Pending
PostDeploymentEvaluationStatus common.KeptnState `json:"postDeploymentEvaluationStatus,omitempty"`
// +kubebuilder:default:=Pending
PostDeploymentStatus common.KeptnState `json:"postDeploymentStatus,omitempty"`
PreDeploymentTaskStatus []TaskStatus `json:"preDeploymentTaskStatus,omitempty"`
PostDeploymentTaskStatus []TaskStatus `json:"postDeploymentTaskStatus,omitempty"`
PreDeploymentEvaluationTaskStatus []EvaluationStatus `json:"preDeploymentEvaluationTaskStatus,omitempty"`
PostDeploymentEvaluationTaskStatus []EvaluationStatus `json:"postDeploymentEvaluationTaskStatus,omitempty"`
StartTime metav1.Time `json:"startTime,omitempty"`
EndTime metav1.Time `json:"endTime,omitempty"`
CurrentPhase string `json:"currentPhase,omitempty"`
PhaseTraceIDs map[string]propagation.MapCarrier `json:"phaseTraceIDs,omitempty"`
PostDeploymentStatus common.KeptnState `json:"postDeploymentStatus,omitempty"`
PreDeploymentTaskStatus []TaskStatus `json:"preDeploymentTaskStatus,omitempty"`
PostDeploymentTaskStatus []TaskStatus `json:"postDeploymentTaskStatus,omitempty"`
PreDeploymentEvaluationTaskStatus []EvaluationStatus `json:"preDeploymentEvaluationTaskStatus,omitempty"`
PostDeploymentEvaluationTaskStatus []EvaluationStatus `json:"postDeploymentEvaluationTaskStatus,omitempty"`
StartTime metav1.Time `json:"startTime,omitempty"`
EndTime metav1.Time `json:"endTime,omitempty"`
CurrentPhase string `json:"currentPhase,omitempty"`
PhaseTraceIDs common.PhaseTraceID `json:"phaseTraceIDs,omitempty"`
// +kubebuilder:default:=Pending
Status common.KeptnState `json:"status,omitempty"`
}
Expand Down Expand Up @@ -418,7 +418,7 @@ func (w *KeptnWorkloadInstance) CancelRemainingPhases(phase common.KeptnPhaseTyp

func (w *KeptnWorkloadInstance) SetPhaseTraceID(phase string, carrier propagation.MapCarrier) {
if w.Status.PhaseTraceIDs == nil {
w.Status.PhaseTraceIDs = map[string]propagation.MapCarrier{}
w.Status.PhaseTraceIDs = common.PhaseTraceID{}
}
w.Status.PhaseTraceIDs[phase] = carrier
}
5 changes: 3 additions & 2 deletions operator/api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.9.2
controller-gen.kubebuilder.io/version: v0.10.0
creationTimestamp: null
name: keptnapps.lifecycle.keptn.sh
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.9.2
controller-gen.kubebuilder.io/version: v0.10.0
creationTimestamp: null
name: keptnappversions.lifecycle.keptn.sh
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.9.2
controller-gen.kubebuilder.io/version: v0.10.0
creationTimestamp: null
name: keptnevaluationdefinitions.lifecycle.keptn.sh
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.9.2
controller-gen.kubebuilder.io/version: v0.10.0
creationTimestamp: null
name: keptnevaluationproviders.lifecycle.keptn.sh
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.9.2
controller-gen.kubebuilder.io/version: v0.10.0
creationTimestamp: null
name: keptnevaluations.lifecycle.keptn.sh
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.9.2
controller-gen.kubebuilder.io/version: v0.10.0
creationTimestamp: null
name: keptntaskdefinitions.lifecycle.keptn.sh
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.9.2
controller-gen.kubebuilder.io/version: v0.10.0
creationTimestamp: null
name: keptntasks.lifecycle.keptn.sh
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.9.2
controller-gen.kubebuilder.io/version: v0.10.0
creationTimestamp: null
name: keptnworkloadinstances.lifecycle.keptn.sh
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.9.2
controller-gen.kubebuilder.io/version: v0.10.0
creationTimestamp: null
name: keptnworkloads.lifecycle.keptn.sh
spec:
Expand Down

0 comments on commit 8c1dee7

Please sign in to comment.