Skip to content

Commit 2749e4c

Browse files
xiujuan95qu1queee
authored andcommitted
Add missing buildRun condition updates on errors
- When we implemented conditions in BuildRun we forgot to update the succeeded condition on errors. This commit fixes this. - Fix a typo of isOwnedByBuild func. Signed-off-by: Enrique Encalada <encalada@de.ibm.com>
1 parent bc82723 commit 2749e4c

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

pkg/controller/buildrun/buildrun_controller.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,11 +679,21 @@ func (r *ReconcileBuildRun) createTaskRun(ctx context.Context, build *buildv1alp
679679
return generatedTaskRun, nil
680680
}
681681

682+
// updateBuildRunErrorStatus updates buildRun status fields
682683
func (r *ReconcileBuildRun) updateBuildRunErrorStatus(ctx context.Context, buildRun *buildv1alpha1.BuildRun, errorMessage string) error {
684+
// these two fields are deprecated and will be removed soon
683685
buildRun.Status.Succeeded = corev1.ConditionFalse
684686
buildRun.Status.Reason = errorMessage
687+
685688
now := metav1.Now()
686689
buildRun.Status.CompletionTime = &now
690+
buildRun.Status.SetCondition(&buildv1alpha1.Condition{
691+
LastTransitionTime: now,
692+
Type: buildv1alpha1.Succeeded,
693+
Status: corev1.ConditionFalse,
694+
Reason: "Failed",
695+
Message: errorMessage,
696+
})
687697
ctxlog.Debug(ctx, "updating buildRun status", namespace, buildRun.Namespace, name, buildRun.Name)
688698
updateErr := r.client.Status().Update(ctx, buildRun)
689699
return updateErr
@@ -699,7 +709,7 @@ func isGeneratedServiceAccountUsed(buildRun *buildv1alpha1.BuildRun) bool {
699709
return buildRun.Spec.ServiceAccount != nil && buildRun.Spec.ServiceAccount.Generate
700710
}
701711

702-
/// isOwnedByBuild cheks if the controllerReferences contains a well known owner Kind
712+
/// isOwnedByBuild checks if the controllerReferences contains a well known owner Kind
703713
func isOwnedByBuild(build *buildv1alpha1.Build, controlledReferences []metav1.OwnerReference) bool {
704714
for _, ref := range controlledReferences {
705715
if ref.Kind == build.Kind && ref.Name == build.Name {

0 commit comments

Comments
 (0)