From a5ef5326496e69f88a3176e29fc623418d374825 Mon Sep 17 00:00:00 2001 From: encalada Date: Sun, 21 Jan 2024 14:43:50 +0100 Subject: [PATCH] status subresource handling --- pkg/apis/build/v1beta1/build_conversion.go | 6 ++ pkg/apis/build/v1beta1/buildrun_conversion.go | 55 +++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/pkg/apis/build/v1beta1/build_conversion.go b/pkg/apis/build/v1beta1/build_conversion.go index c0199aae74..c39d652d23 100644 --- a/pkg/apis/build/v1beta1/build_conversion.go +++ b/pkg/apis/build/v1beta1/build_conversion.go @@ -38,6 +38,12 @@ func (src *Build) ConvertTo(ctx context.Context, obj *unstructured.Unstructured) src.Spec.ConvertTo(&alphaBuild.Spec) + alphaBuild.Status = v1alpha1.BuildStatus{ + Registered: src.Status.Registered, + Reason: (*v1alpha1.BuildReason)(src.Status.Reason), + Message: src.Status.Message, + } + // convert annotation-controlled features if src.Spec.Retention != nil && src.Spec.Retention.AtBuildDeletion != nil { // We must create a new Map as otherwise the addition is not kept diff --git a/pkg/apis/build/v1beta1/buildrun_conversion.go b/pkg/apis/build/v1beta1/buildrun_conversion.go index 41180e9ae5..c9c234a4af 100644 --- a/pkg/apis/build/v1beta1/buildrun_conversion.go +++ b/pkg/apis/build/v1beta1/buildrun_conversion.go @@ -108,6 +108,61 @@ func (src *BuildRun) ConvertTo(ctx context.Context, obj *unstructured.Unstructur }) } + sourceStatus := []v1alpha1.SourceResult{} + + if src.Status.Source != nil && src.Status.Source.Git != nil { + sourceStatus = append(sourceStatus, v1alpha1.SourceResult{ + Git: (*v1alpha1.GitSourceResult)(src.Status.Source.Git), + }) + } + + if src.Status.Source != nil && src.Status.Source.OciArtifact != nil { + sourceStatus[0] = v1alpha1.SourceResult{ + Bundle: (*v1alpha1.BundleSourceResult)(src.Status.Source.OciArtifact), + } + } + + conditions := []v1alpha1.Condition{} + + for _, c := range src.Status.Conditions { + ct := v1alpha1.Condition{ + Type: v1alpha1.Type(c.Type), + Status: c.Status, + LastTransitionTime: c.LastTransitionTime, + Reason: c.Reason, + Message: c.Message, + } + conditions = append(conditions, ct) + } + + if src.Status.FailureDetails != nil { + alphaBuildRun.Status.FailureDetails = &v1alpha1.FailureDetails{ + Reason: src.Status.FailureDetails.Reason, + Message: src.Status.FailureDetails.Message, + Location: &v1alpha1.FailedAt{ + Pod: src.Status.FailureDetails.Location.Pod, + Container: src.Status.FailureDetails.Location.Container, + }, + } + } + + alphaBuildRun.Status = v1alpha1.BuildRunStatus{ + Sources: sourceStatus, + Output: (*v1alpha1.Output)(src.Status.Output), + Conditions: conditions, + LatestTaskRunRef: src.Status.TaskRunName, + StartTime: src.Status.StartTime, + CompletionTime: src.Status.CompletionTime, + } + + // TODO: add test case + + aux := &v1alpha1.BuildSpec{} + if src.Status.BuildSpec != nil { + src.Status.BuildSpec.ConvertTo(aux) + alphaBuildRun.Status.BuildSpec = aux + } + mapito, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&alphaBuildRun) if err != nil { ctxlog.Error(ctx, err, "failed structuring the newObject")