You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by as...@apache.org on 2021/03/12 15:39:36 UTC

[camel-k] 05/10: fix: Correctly publish routine Build status change

This is an automated email from the ASF dual-hosted git repository.

astefanutti pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 18392f6ddfa0b33e45794fc7a581f990cc9690db
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Thu Mar 11 12:37:40 2021 +0100

    fix: Correctly publish routine Build status change
---
 pkg/controller/build/schedule_routine.go | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/pkg/controller/build/schedule_routine.go b/pkg/controller/build/schedule_routine.go
index 7797991..24ce3d7 100644
--- a/pkg/controller/build/schedule_routine.go
+++ b/pkg/controller/build/schedule_routine.go
@@ -25,6 +25,7 @@ import (
 
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 	"k8s.io/apimachinery/pkg/types"
+
 	"sigs.k8s.io/controller-runtime/pkg/client"
 
 	v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
@@ -85,10 +86,7 @@ func (action *scheduleRoutineAction) Handle(ctx context.Context, build *v1.Build
 
 	// Transition the build to pending state
 	// This must be done in the critical section rather than delegated to the controller
-	target := build.DeepCopy()
-	target.Status.Phase = v1.BuildPhasePending
-	action.L.Info("Build state transition", "phase", target.Status.Phase)
-	err = action.client.Status().Update(ctx, target)
+	err = action.updateBuildStatus(ctx, build, v1.BuildStatus{Phase: v1.BuildPhasePending})
 	if err != nil {
 		return nil, err
 	}
@@ -96,8 +94,6 @@ func (action *scheduleRoutineAction) Handle(ctx context.Context, build *v1.Build
 	// Report the duration the Build has been waiting in the build queue
 	queueDuration.Observe(time.Now().Sub(getBuildQueuingTime(build)).Seconds())
 
-	camelevent.NotifyBuildUpdated(ctx, action.client, action.recorder, build, target)
-
 	// Start the build asynchronously to avoid blocking the reconcile loop
 	action.routines.Store(build.Name, true)
 
@@ -173,6 +169,9 @@ func (action *scheduleRoutineAction) updateBuildStatus(ctx context.Context, buil
 		action.L.Errorf(err, "Cannot update build status: %s", build.Name)
 		return err
 	}
+	if target.Status.Phase != build.Status.Phase {
+		action.L.Info("Build state transition", "phase", target.Status.Phase)
+	}
 	camelevent.NotifyBuildUpdated(ctx, action.client, action.recorder, build, target)
 	build.Status = target.Status
 	return nil