Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions deploy/crds/shipwright.io_buildruns.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14103,6 +14103,22 @@ spec:
- type
type: object
type: array
executor:
description: Executor is the name and kind of the resource responsible
for executing this BuildRun.
properties:
kind:
description: Kind is the kind of the object that was created to
execute the BuildRun (e.g., "TaskRun", "PipelineRun")
type: string
name:
description: Name is the name of the TaskRun or PipelineRun that
was created to execute this BuildRun
type: string
required:
- kind
- name
type: object
failureDetails:
description: FailureDetails contains error details that are collected
and surfaced from TaskRun
Expand Down Expand Up @@ -14192,8 +14208,10 @@ spec:
format: date-time
type: string
taskRunName:
description: TaskRunName is the name of the TaskRun responsible for
executing this BuildRun.
description: |-
TaskRunName is the name of the TaskRun responsible for executing this BuildRun.

Deprecated: Use Executor instead to describe the taskrun.
type: string
type: object
required:
Expand Down
26 changes: 24 additions & 2 deletions pkg/apis/build/v1beta1/buildrun_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,21 @@ func (src *BuildRun) ConvertTo(ctx context.Context, obj *unstructured.Unstructur
}
}

// Handle conversion of BuildExecutor to TaskRunName for backward compatibility
var taskRunName *string
if src.Status.Executor != nil {
// If Executor is set, use its Name field
taskRunName = &src.Status.Executor.Name
} else {
// Fall back to the deprecated TaskRunName field
taskRunName = src.Status.TaskRunName // nolint:staticcheck
}

alphaBuildRun.Status = v1alpha1.BuildRunStatus{
Sources: sourceStatus,
Output: output,
Conditions: conditions,
LatestTaskRunRef: src.Status.TaskRunName,
LatestTaskRunRef: taskRunName,
StartTime: src.Status.StartTime,
CompletionTime: src.Status.CompletionTime,
}
Expand Down Expand Up @@ -248,11 +258,23 @@ func (src *BuildRun) ConvertFrom(ctx context.Context, obj *unstructured.Unstruct
}
}

// Handle conversion from v1alpha1 LatestTaskRunRef to v1beta1 BuildExecutor
var executor *BuildExecutor
if alphaBuildRun.Status.LatestTaskRunRef != nil {
// Convert the old TaskRunName to new BuildExecutor structure
// Since v1alpha1 only had TaskRun support, we default to "TaskRun" kind
executor = &BuildExecutor{
Name: *alphaBuildRun.Status.LatestTaskRunRef,
Kind: "TaskRun", // Default to TaskRun for backward compatibility
}
}

src.Status = BuildRunStatus{
Source: sourceStatus,
Output: output,
Conditions: conditions,
TaskRunName: alphaBuildRun.Status.LatestTaskRunRef,
TaskRunName: alphaBuildRun.Status.LatestTaskRunRef, // nolint:staticcheck // Keep for backward compatibility
Executor: executor, // New field with enhanced information
StartTime: alphaBuildRun.Status.StartTime,
CompletionTime: alphaBuildRun.Status.CompletionTime,
FailureDetails: src.Status.FailureDetails,
Expand Down
14 changes: 14 additions & 0 deletions pkg/apis/build/v1beta1/buildrun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,15 @@ type BuildRunStatus struct {

// TaskRunName is the name of the TaskRun responsible for executing this BuildRun.
//
// Deprecated: Use Executor instead to describe the taskrun.
// +optional
TaskRunName *string `json:"taskRunName,omitempty"`

// Executor is the name and kind of the resource responsible for executing this BuildRun.
//
// +optional
Executor *BuildExecutor `json:"executor,omitempty"`

// StartTime is the time the build is actually started.
// +optional
StartTime *metav1.Time `json:"startTime,omitempty"`
Expand Down Expand Up @@ -449,3 +455,11 @@ func (buildrunSpec *BuildRunSpec) BuildName() string {
// Only BuildRuns with a ReferencedBuild can actually return a proper Build name
return ""
}

// BuildExecutor defines the name and kind of the build runner.
type BuildExecutor struct {
// Name is the name of the TaskRun or PipelineRun that was created to execute this BuildRun
Name string `json:"name"`
// Kind is the kind of the object that was created to execute the BuildRun (e.g., "TaskRun", "PipelineRun")
Kind string `json:"kind"`
}
1 change: 1 addition & 0 deletions pkg/apis/build/v1beta1/zz_generated.deepcopy.go

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

17 changes: 14 additions & 3 deletions pkg/reconciler/buildrun/buildrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req
}

// if this is a build run event after we've set the task run ref, get the task run using the task run name stored in the build run
// nolint:staticcheck
if getBuildRunErr == nil && apierrors.IsNotFound(getTaskRunErr) && buildRun.Status.TaskRunName != nil {
lastTaskRun, getTaskRunErr = r.taskRunnerFactory.GetImageBuildRunner(ctx, r.client, types.NamespacedName{Name: *buildRun.Status.TaskRunName, Namespace: request.Namespace})
}
Expand Down Expand Up @@ -352,8 +353,12 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req
return reconcile.Result{}, err
}

// Set the LastTaskRunRef in the BuildRun status
buildRun.Status.TaskRunName = &generatedTaskRun.Name
// Set the TaskRunName and BuildExecutor in the BuildRun status
buildRun.Status.TaskRunName = &generatedTaskRun.Name // nolint:staticcheck
buildRun.Status.Executor = &buildv1beta1.BuildExecutor{
Name: generatedTaskRun.Name,
Kind: "TaskRun",
}
ctxlog.Info(ctx, "updating BuildRun status with TaskRun name", namespace, request.Namespace, name, request.Name, "TaskRun", generatedTaskRun.Name)
if err = r.client.Status().Update(ctx, buildRun); err != nil {
// we ignore the error here to prevent another reconciliation that would create another TaskRun,
Expand Down Expand Up @@ -443,7 +448,13 @@ func (r *ReconcileBuildRun) Reconcile(ctx context.Context, request reconcile.Req
}

taskRunName := lastTaskRun.GetName()
buildRun.Status.TaskRunName = &taskRunName
buildRun.Status.TaskRunName = &taskRunName // nolint:staticcheck
if buildRun.Status.Executor == nil {
buildRun.Status.Executor = &buildv1beta1.BuildExecutor{
Name: lastTaskRun.GetName(),
Kind: "TaskRun",
}
}

taskRunStartTime := lastTaskRun.GetStartTime()
if buildRun.Status.StartTime == nil && taskRunStartTime != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/buildrun/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func add(mgr manager.Manager, r reconcile.Reconciler, maxConcurrentReconciles in
CreateFunc: func(e event.TypedCreateEvent[*buildv1beta1.BuildRun]) bool {
// The CreateFunc is also called when the controller is started and iterates over all objects. For those BuildRuns that have a TaskRun referenced already,
// we do not need to do a further reconciliation. BuildRun updates then only happen from the TaskRun.
return e.Object.Status.TaskRunName == nil && e.Object.Status.CompletionTime == nil
return e.Object.Status.TaskRunName == nil && e.Object.Status.CompletionTime == nil // nolint:staticcheck
},
UpdateFunc: func(e event.TypedUpdateEvent[*buildv1beta1.BuildRun]) bool {
// Only reconcile a BuildRun update when
Expand Down
1 change: 1 addition & 0 deletions test/utils/v1beta1/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func (t *TestBuild) LookupTaskRunUsingBuildRun(buildRun *buildv1beta1.BuildRun)
return nil, fmt.Errorf("no BuildRun specified to lookup TaskRun")
}

// nolint:staticcheck
if buildRun.Status.TaskRunName != nil {
return t.LookupTaskRun(types.NamespacedName{Namespace: buildRun.Namespace, Name: *buildRun.Status.TaskRunName})
}
Expand Down
2 changes: 1 addition & 1 deletion test/v1beta1_samples/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ func (c *Catalog) StubBuildRunStatus(reason string, name *string, condition buil
if !tolerateEmptyStatus {
Expect(object.Status.GetCondition(build.Succeeded).Status).To(Equal(condition.Status))
Expect(object.Status.GetCondition(build.Succeeded).Reason).To(Equal(condition.Reason))
Expect(object.Status.TaskRunName).To(Equal(name))
Expect(object.Status.TaskRunName).To(Equal(name)) // nolint:staticcheck
}
if object.Status.BuildSpec != nil {
Expect(*object.Status.BuildSpec).To(Equal(buildSpec))
Expand Down