Skip to content

Commit

Permalink
fix(operator): Fixed typo in pre and post deployment checks + sorting…
Browse files Browse the repository at this point in the history
… the PhaseItem interface functions according to topic (#405)
  • Loading branch information
odubajDT authored Nov 14, 2022
1 parent cf74540 commit ca8f11d
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 126 deletions.
40 changes: 20 additions & 20 deletions operator/api/v1alpha1/keptnappversion_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ func (a *KeptnAppVersion) SetEndTime() {
}
}

func (a KeptnAppVersion) GetStartTime() time.Time {
return a.Status.StartTime.Time
}

func (a KeptnAppVersion) GetEndTime() time.Time {
return a.Status.EndTime.Time
}

func (a *KeptnAppVersion) IsStartTimeSet() bool {
return !a.Status.StartTime.IsZero()
}
Expand All @@ -194,6 +202,10 @@ func (a *KeptnAppVersion) IsEndTimeSet() bool {
return !a.Status.EndTime.IsZero()
}

func (a *KeptnAppVersion) Complete() {
a.SetEndTime()
}

func (a KeptnAppVersion) GetActiveMetricsAttributes() []attribute.KeyValue {
return []attribute.KeyValue{
common.AppName.String(a.Spec.AppName),
Expand Down Expand Up @@ -275,14 +287,6 @@ func (a *KeptnAppVersion) SetState(state common.KeptnState) {
a.Status.Status = state
}

func (a KeptnAppVersion) GetStartTime() time.Time {
return a.Status.StartTime.Time
}

func (a KeptnAppVersion) GetEndTime() time.Time {
return a.Status.EndTime.Time
}

func (a KeptnAppVersion) GetCurrentPhase() string {
return a.Status.CurrentPhase
}
Expand All @@ -291,18 +295,10 @@ func (a *KeptnAppVersion) SetCurrentPhase(phase string) {
a.Status.CurrentPhase = phase
}

func (a *KeptnAppVersion) Complete() {
a.SetEndTime()
}

func (a KeptnAppVersion) GetVersion() string {
return a.Spec.Version
}

func (a KeptnAppVersion) GetSpanKey(phase string) string {
return fmt.Sprintf("%s.%s.%s.%s", a.Spec.TraceId["traceparent"], a.Spec.AppName, a.Spec.Version, phase)
}

func (a KeptnAppVersion) GenerateTask(traceContextCarrier propagation.MapCarrier, taskDefinition string, checkType common.CheckType) KeptnTask {
return KeptnTask{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -321,10 +317,6 @@ func (a KeptnAppVersion) GenerateTask(traceContextCarrier propagation.MapCarrier
}
}

func (a KeptnAppVersion) SetSpanAttributes(span trace.Span) {
span.SetAttributes(a.GetSpanAttributes()...)
}

func (a KeptnAppVersion) GenerateEvaluation(traceContextCarrier propagation.MapCarrier, evaluationDefinition string, checkType common.CheckType) KeptnEvaluation {
return KeptnEvaluation{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -356,6 +348,14 @@ func (a KeptnAppVersion) GetSpanAttributes() []attribute.KeyValue {
}
}

func (a KeptnAppVersion) SetSpanAttributes(span trace.Span) {
span.SetAttributes(a.GetSpanAttributes()...)
}

func (a KeptnAppVersion) GetSpanKey(phase string) string {
return fmt.Sprintf("%s.%s.%s.%s", a.Spec.TraceId["traceparent"], a.Spec.AppName, a.Spec.Version, phase)
}

func (v KeptnAppVersion) GetWorkloadNameOfApp(workloadName string) string {
return fmt.Sprintf("%s-%s", v.Spec.AppName, workloadName)
}
41 changes: 0 additions & 41 deletions operator/api/v1alpha1/keptnappversion_types_test.go

This file was deleted.

56 changes: 28 additions & 28 deletions operator/api/v1alpha1/keptnworkloadinstance_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,18 @@ func (w *KeptnWorkloadInstance) IsEndTimeSet() bool {
return !w.Status.EndTime.IsZero()
}

func (w KeptnWorkloadInstance) GetStartTime() time.Time {
return w.Status.StartTime.Time
}

func (w KeptnWorkloadInstance) GetEndTime() time.Time {
return w.Status.EndTime.Time
}

func (w *KeptnWorkloadInstance) Complete() {
w.SetEndTime()
}

func (t *TaskStatus) SetStartTime() {
if t.StartTime.IsZero() {
t.StartTime = metav1.NewTime(time.Now().UTC())
Expand Down Expand Up @@ -307,14 +319,6 @@ func (w KeptnWorkloadInstance) GetNamespace() string {
return w.Namespace
}

func (w KeptnWorkloadInstance) GetStartTime() time.Time {
return w.Status.StartTime.Time
}

func (w KeptnWorkloadInstance) GetEndTime() time.Time {
return w.Status.EndTime.Time
}

func (w *KeptnWorkloadInstance) SetState(state common.KeptnState) {
w.Status.Status = state
}
Expand All @@ -327,22 +331,10 @@ func (w *KeptnWorkloadInstance) SetCurrentPhase(phase string) {
w.Status.CurrentPhase = phase
}

func (w *KeptnWorkloadInstance) Complete() {
w.SetEndTime()
}

func (w KeptnWorkloadInstance) GetVersion() string {
return w.Spec.Version
}

func (w KeptnWorkloadInstance) GetSpanKey(phase string) string {
return fmt.Sprintf("%s.%s.%s.%s", w.Spec.TraceId["traceparent"], w.Spec.WorkloadName, w.Spec.Version, phase)
}

func (w KeptnWorkloadInstance) GetSpanName(phase string) string {
return fmt.Sprintf("%s/%s", w.Spec.WorkloadName, phase)
}

func (w KeptnWorkloadInstance) GenerateTask(traceContextCarrier propagation.MapCarrier, taskDefinition string, checkType common.CheckType) KeptnTask {
return KeptnTask{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -352,8 +344,8 @@ func (w KeptnWorkloadInstance) GenerateTask(traceContextCarrier propagation.MapC
},
Spec: KeptnTaskSpec{
AppName: w.GetAppName(),
WorkloadVersion: w.GetParentName(),
Workload: w.GetVersion(),
WorkloadVersion: w.GetVersion(),
Workload: w.GetParentName(),
TaskDefinition: taskDefinition,
Parameters: TaskParameters{},
SecureParameters: SecureParameters{},
Expand All @@ -362,10 +354,6 @@ func (w KeptnWorkloadInstance) GenerateTask(traceContextCarrier propagation.MapC
}
}

func (w KeptnWorkloadInstance) SetSpanAttributes(span trace.Span) {
span.SetAttributes(w.GetSpanAttributes()...)
}

func (w KeptnWorkloadInstance) GenerateEvaluation(traceContextCarrier propagation.MapCarrier, evaluationDefinition string, checkType common.CheckType) KeptnEvaluation {
return KeptnEvaluation{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -375,8 +363,8 @@ func (w KeptnWorkloadInstance) GenerateEvaluation(traceContextCarrier propagatio
},
Spec: KeptnEvaluationSpec{
AppName: w.GetAppName(),
WorkloadVersion: w.GetParentName(),
Workload: w.GetVersion(),
WorkloadVersion: w.GetVersion(),
Workload: w.GetParentName(),
EvaluationDefinition: evaluationDefinition,
Type: checkType,
RetryInterval: metav1.Duration{
Expand All @@ -394,3 +382,15 @@ func (w KeptnWorkloadInstance) GetSpanAttributes() []attribute.KeyValue {
common.WorkloadNamespace.String(w.Namespace),
}
}

func (w KeptnWorkloadInstance) GetSpanKey(phase string) string {
return fmt.Sprintf("%s.%s.%s.%s", w.Spec.TraceId["traceparent"], w.Spec.WorkloadName, w.Spec.Version, phase)
}

func (w KeptnWorkloadInstance) GetSpanName(phase string) string {
return fmt.Sprintf("%s/%s", w.Spec.WorkloadName, phase)
}

func (w KeptnWorkloadInstance) SetSpanAttributes(span trace.Span) {
span.SetAttributes(w.GetSpanAttributes()...)
}
36 changes: 36 additions & 0 deletions operator/api/v1alpha1/tests/keptnappversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,39 @@ func TestKeptnAppVersion(t *testing.T) {
common.AppNamespace.String("namespace"),
}, app.GetSpanAttributes())
}

func TestKeptnAppVersion_GetWorkloadNameOfApp(t *testing.T) {
type fields struct {
Spec v1alpha1.KeptnAppVersionSpec
}
type args struct {
workloadName string
}
tests := []struct {
name string
fields fields
args args
want string
}{
{
name: "",
fields: fields{
Spec: v1alpha1.KeptnAppVersionSpec{AppName: "my-app"},
},
args: args{
workloadName: "my-workload",
},
want: "my-app-my-workload",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
v := v1alpha1.KeptnAppVersion{
Spec: tt.fields.Spec,
}
if got := v.GetWorkloadNameOfApp(tt.args.workloadName); got != tt.want {
t.Errorf("GetWorkloadNameOfApp() = %v, want %v", got, tt.want)
}
})
}
}
8 changes: 4 additions & 4 deletions operator/api/v1alpha1/tests/keptnworkloadinstance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ func TestKeptnWorkloadInstance(t *testing.T) {
task := workload.GenerateTask(map[string]string{}, "taskdef", common.PostDeploymentCheckType)
require.Equal(t, v1alpha1.KeptnTaskSpec{
AppName: workload.GetAppName(),
WorkloadVersion: workload.GetParentName(),
Workload: workload.GetVersion(),
WorkloadVersion: workload.GetVersion(),
Workload: workload.GetParentName(),
TaskDefinition: "taskdef",
Parameters: v1alpha1.TaskParameters{},
SecureParameters: v1alpha1.SecureParameters{},
Expand All @@ -196,8 +196,8 @@ func TestKeptnWorkloadInstance(t *testing.T) {
evaluation := workload.GenerateEvaluation(map[string]string{}, "taskdef", common.PostDeploymentCheckType)
require.Equal(t, v1alpha1.KeptnEvaluationSpec{
AppName: workload.GetAppName(),
WorkloadVersion: workload.GetParentName(),
Workload: workload.GetVersion(),
WorkloadVersion: workload.GetVersion(),
Workload: workload.GetParentName(),
EvaluationDefinition: "taskdef",
Type: common.PostDeploymentCheckType,
RetryInterval: metav1.Duration{
Expand Down
4 changes: 2 additions & 2 deletions operator/controllers/common/evaluationhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ func (r EvaluationHandler) ReconcileEvaluations(ctx context.Context, reconcileOb
evaluations = piWrapper.GetPreDeploymentEvaluations()
statuses = piWrapper.GetPreDeploymentEvaluationTaskStatus()
case apicommon.PostDeploymentEvaluationCheckType:
evaluations = piWrapper.GetPreDeploymentEvaluations()
statuses = piWrapper.GetPreDeploymentEvaluationTaskStatus()
evaluations = piWrapper.GetPostDeploymentEvaluations()
statuses = piWrapper.GetPostDeploymentEvaluationTaskStatus()
}

var summary apicommon.StatusSummary
Expand Down
Loading

0 comments on commit ca8f11d

Please sign in to comment.