-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: unify EvaluationStatus and TaskStatus to single structure (#569)
BREAKING CHANGE: Evaluation and Task statuses in KeptnWorkloadInstance/KeptnAppVersion use the same structure
- Loading branch information
Showing
51 changed files
with
2,248 additions
and
618 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
228 changes: 228 additions & 0 deletions
228
operator/apis/lifecycle/v1alpha1/keptnappversion_conversion.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,228 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/keptn/lifecycle-toolkit/operator/apis/lifecycle/v1alpha1/common" | ||
"github.com/keptn/lifecycle-toolkit/operator/apis/lifecycle/v1alpha2" | ||
v1alpha2common "github.com/keptn/lifecycle-toolkit/operator/apis/lifecycle/v1alpha2/common" | ||
"go.opentelemetry.io/otel/propagation" | ||
"sigs.k8s.io/controller-runtime/pkg/conversion" | ||
) | ||
|
||
// ConvertTo converts the src v1alpha1.KeptnAppVersion to the hub version (v1alpha2.KeptnAppVersion) | ||
func (src *KeptnAppVersion) ConvertTo(dstRaw conversion.Hub) error { | ||
dst, ok := dstRaw.(*v1alpha2.KeptnAppVersion) | ||
|
||
if !ok { | ||
return fmt.Errorf("type %T %w", dstRaw, common.ErrCannotCastKeptnAppVersion) | ||
} | ||
|
||
// Copy equal stuff to new object | ||
// DO NOT COPY TypeMeta | ||
dst.ObjectMeta = src.ObjectMeta | ||
|
||
dst.Spec.Version = src.Spec.Version | ||
for _, srcWl := range src.Spec.Workloads { | ||
dst.Spec.Workloads = append(dst.Spec.Workloads, v1alpha2.KeptnWorkloadRef{ | ||
Name: srcWl.Name, | ||
Version: srcWl.Version, | ||
}) | ||
} | ||
dst.Spec.PreDeploymentTasks = src.Spec.PreDeploymentTasks | ||
dst.Spec.PostDeploymentTasks = src.Spec.PostDeploymentTasks | ||
dst.Spec.PreDeploymentEvaluations = src.Spec.PreDeploymentEvaluations | ||
dst.Spec.PostDeploymentEvaluations = src.Spec.PostDeploymentEvaluations | ||
|
||
dst.Spec.AppName = src.Spec.AppName | ||
dst.Spec.PreviousVersion = src.Spec.PreviousVersion | ||
|
||
dst.Spec.TraceId = make(map[string]string, len(src.Spec.TraceId)) | ||
for k, v := range src.Spec.TraceId { | ||
dst.Spec.TraceId[k] = v | ||
} | ||
|
||
dst.Status.PreDeploymentStatus = v1alpha2common.KeptnState(src.Status.PreDeploymentStatus) | ||
dst.Status.PostDeploymentStatus = v1alpha2common.KeptnState(src.Status.PostDeploymentStatus) | ||
dst.Status.PreDeploymentEvaluationStatus = v1alpha2common.KeptnState(src.Status.PreDeploymentEvaluationStatus) | ||
dst.Status.PostDeploymentEvaluationStatus = v1alpha2common.KeptnState(src.Status.PostDeploymentEvaluationStatus) | ||
dst.Status.WorkloadOverallStatus = v1alpha2common.KeptnState(src.Status.WorkloadOverallStatus) | ||
dst.Status.Status = v1alpha2common.KeptnState(src.Status.Status) | ||
|
||
for _, srcWls := range src.Status.WorkloadStatus { | ||
dst.Status.WorkloadStatus = append(dst.Status.WorkloadStatus, v1alpha2.WorkloadStatus{ | ||
Workload: v1alpha2.KeptnWorkloadRef{ | ||
Name: srcWls.Workload.Name, | ||
Version: srcWls.Workload.Version, | ||
}, | ||
Status: v1alpha2common.KeptnState(srcWls.Status), | ||
}) | ||
} | ||
|
||
dst.Status.CurrentPhase = src.Status.CurrentPhase | ||
|
||
// Set sensible defaults for new fields | ||
dst.Spec.Revision = 1 | ||
|
||
// Convert changed fields | ||
for _, item := range src.Status.PreDeploymentTaskStatus { | ||
dst.Status.PreDeploymentTaskStatus = append(dst.Status.PreDeploymentTaskStatus, v1alpha2.ItemStatus{ | ||
DefinitionName: item.TaskDefinitionName, | ||
Status: v1alpha2common.KeptnState(item.Status), | ||
Name: item.TaskName, | ||
StartTime: item.StartTime, | ||
EndTime: item.EndTime, | ||
}) | ||
} | ||
|
||
for _, item := range src.Status.PostDeploymentTaskStatus { | ||
dst.Status.PostDeploymentTaskStatus = append(dst.Status.PostDeploymentTaskStatus, v1alpha2.ItemStatus{ | ||
DefinitionName: item.TaskDefinitionName, | ||
Status: v1alpha2common.KeptnState(item.Status), | ||
Name: item.TaskName, | ||
StartTime: item.StartTime, | ||
EndTime: item.EndTime, | ||
}) | ||
} | ||
|
||
for _, item := range src.Status.PreDeploymentEvaluationTaskStatus { | ||
dst.Status.PreDeploymentEvaluationTaskStatus = append(dst.Status.PreDeploymentEvaluationTaskStatus, v1alpha2.ItemStatus{ | ||
DefinitionName: item.EvaluationDefinitionName, | ||
Status: v1alpha2common.KeptnState(item.Status), | ||
Name: item.EvaluationName, | ||
StartTime: item.StartTime, | ||
EndTime: item.EndTime, | ||
}) | ||
} | ||
|
||
for _, item := range src.Status.PostDeploymentEvaluationTaskStatus { | ||
dst.Status.PostDeploymentEvaluationTaskStatus = append(dst.Status.PostDeploymentEvaluationTaskStatus, v1alpha2.ItemStatus{ | ||
DefinitionName: item.EvaluationDefinitionName, | ||
Status: v1alpha2common.KeptnState(item.Status), | ||
Name: item.EvaluationName, | ||
StartTime: item.StartTime, | ||
EndTime: item.EndTime, | ||
}) | ||
} | ||
|
||
dst.Status.PhaseTraceIDs = make(v1alpha2common.PhaseTraceID, len(src.Status.PhaseTraceIDs)) | ||
for k, v := range src.Status.PhaseTraceIDs { | ||
c := make(propagation.MapCarrier, len(v)) | ||
for k1, v1 := range v { | ||
c[k1] = v1 | ||
} | ||
dst.Status.PhaseTraceIDs[k] = c | ||
} | ||
|
||
dst.Status.StartTime = src.Status.StartTime | ||
dst.Status.EndTime = src.Status.EndTime | ||
|
||
return nil | ||
} | ||
|
||
// ConvertFrom converts from the hub version (v1alpha2.KeptnAppVersion) to this version (v1alpha1.KeptnAppVersion) | ||
func (dst *KeptnAppVersion) ConvertFrom(srcRaw conversion.Hub) error { | ||
src, ok := srcRaw.(*v1alpha2.KeptnAppVersion) | ||
|
||
if !ok { | ||
return fmt.Errorf("type %T %w", srcRaw, common.ErrCannotCastKeptnAppVersion) | ||
} | ||
|
||
// Copy equal stuff to new object | ||
// DO NOT COPY TypeMeta | ||
dst.ObjectMeta = src.ObjectMeta | ||
|
||
dst.Spec.Version = src.Spec.Version | ||
for _, srcWl := range src.Spec.Workloads { | ||
dst.Spec.Workloads = append(dst.Spec.Workloads, KeptnWorkloadRef{ | ||
Name: srcWl.Name, | ||
Version: srcWl.Version, | ||
}) | ||
} | ||
dst.Spec.PreDeploymentTasks = src.Spec.PreDeploymentTasks | ||
dst.Spec.PostDeploymentTasks = src.Spec.PostDeploymentTasks | ||
dst.Spec.PreDeploymentEvaluations = src.Spec.PreDeploymentEvaluations | ||
dst.Spec.PostDeploymentEvaluations = src.Spec.PostDeploymentEvaluations | ||
|
||
dst.Spec.AppName = src.Spec.AppName | ||
dst.Spec.PreviousVersion = src.Spec.PreviousVersion | ||
|
||
dst.Spec.TraceId = make(map[string]string, len(src.Spec.TraceId)) | ||
for k, v := range src.Spec.TraceId { | ||
dst.Spec.TraceId[k] = v | ||
} | ||
|
||
dst.Status.PreDeploymentStatus = common.KeptnState(src.Status.PreDeploymentStatus) | ||
dst.Status.PostDeploymentStatus = common.KeptnState(src.Status.PostDeploymentStatus) | ||
dst.Status.PreDeploymentEvaluationStatus = common.KeptnState(src.Status.PreDeploymentEvaluationStatus) | ||
dst.Status.PostDeploymentEvaluationStatus = common.KeptnState(src.Status.PostDeploymentEvaluationStatus) | ||
dst.Status.WorkloadOverallStatus = common.KeptnState(src.Status.WorkloadOverallStatus) | ||
dst.Status.Status = common.KeptnState(src.Status.Status) | ||
|
||
for _, srcWls := range src.Status.WorkloadStatus { | ||
dst.Status.WorkloadStatus = append(dst.Status.WorkloadStatus, WorkloadStatus{ | ||
Workload: KeptnWorkloadRef{ | ||
Name: srcWls.Workload.Name, | ||
Version: srcWls.Workload.Version, | ||
}, | ||
Status: common.KeptnState(srcWls.Status), | ||
}) | ||
} | ||
|
||
dst.Status.CurrentPhase = src.Status.CurrentPhase | ||
|
||
// Convert changed fields | ||
for _, item := range src.Status.PreDeploymentTaskStatus { | ||
dst.Status.PreDeploymentTaskStatus = append(dst.Status.PreDeploymentTaskStatus, TaskStatus{ | ||
TaskDefinitionName: item.DefinitionName, | ||
Status: common.KeptnState(item.Status), | ||
TaskName: item.Name, | ||
StartTime: item.StartTime, | ||
EndTime: item.EndTime, | ||
}) | ||
} | ||
|
||
for _, item := range src.Status.PostDeploymentTaskStatus { | ||
dst.Status.PostDeploymentTaskStatus = append(dst.Status.PostDeploymentTaskStatus, TaskStatus{ | ||
TaskDefinitionName: item.DefinitionName, | ||
Status: common.KeptnState(item.Status), | ||
TaskName: item.Name, | ||
StartTime: item.StartTime, | ||
EndTime: item.EndTime, | ||
}) | ||
} | ||
|
||
for _, item := range src.Status.PreDeploymentEvaluationTaskStatus { | ||
dst.Status.PreDeploymentEvaluationTaskStatus = append(dst.Status.PreDeploymentEvaluationTaskStatus, EvaluationStatus{ | ||
EvaluationDefinitionName: item.DefinitionName, | ||
Status: common.KeptnState(item.Status), | ||
EvaluationName: item.Name, | ||
StartTime: item.StartTime, | ||
EndTime: item.EndTime, | ||
}) | ||
} | ||
|
||
for _, item := range src.Status.PostDeploymentEvaluationTaskStatus { | ||
dst.Status.PostDeploymentEvaluationTaskStatus = append(dst.Status.PostDeploymentEvaluationTaskStatus, EvaluationStatus{ | ||
EvaluationDefinitionName: item.DefinitionName, | ||
Status: common.KeptnState(item.Status), | ||
EvaluationName: item.Name, | ||
StartTime: item.StartTime, | ||
EndTime: item.EndTime, | ||
}) | ||
} | ||
|
||
dst.Status.PhaseTraceIDs = make(common.PhaseTraceID, len(src.Status.PhaseTraceIDs)) | ||
for k, v := range src.Status.PhaseTraceIDs { | ||
c := make(propagation.MapCarrier, len(v)) | ||
for k1, v1 := range v { | ||
c[k1] = v1 | ||
} | ||
dst.Status.PhaseTraceIDs[k] = c | ||
} | ||
|
||
dst.Status.StartTime = src.Status.StartTime | ||
dst.Status.EndTime = src.Status.EndTime | ||
|
||
return nil | ||
} |
Oops, something went wrong.