Skip to content

Commit

Permalink
status subresource handling
Browse files Browse the repository at this point in the history
  • Loading branch information
qu1queee committed Jan 22, 2024
1 parent 6b33907 commit a5ef532
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/apis/build/v1beta1/build_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 55 additions & 0 deletions pkg/apis/build/v1beta1/buildrun_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit a5ef532

Please sign in to comment.