@@ -67,10 +67,46 @@ type FunctionReconciler struct {
6767// +kubebuilder:rbac:groups=tekton.dev,resources=taskruns,verbs=get;list;watch
6868// +kubebuilder:rbac:groups=rbac.authorization.k8s.io,resources=rolebindings,verbs=get;list;watch;create;update;patch;delete
6969
70- // Reconcile a Function
70+ // Reconcile a Function with status update on error
7171func (r * FunctionReconciler ) Reconcile (ctx context.Context , req ctrl.Request ) (ctrl.Result , error ) {
7272 logger := logf .FromContext (ctx )
7373
74+ reconcileRes , reconcileErr := r .reconcile (ctx , req )
75+
76+ function := & v1alpha1.Function {}
77+ if err := r .Get (ctx , req .NamespacedName , function ); err != nil {
78+ // we can't get the function to update the status -> return early
79+ if apierrors .IsNotFound (err ) {
80+ // function was already deleted -> nothing to update
81+ return ctrl.Result {}, nil
82+ }
83+ logger .Error (err , "Unable to fetch Function to update status condition" , "reconcileError" , reconcileErr )
84+ return reconcileRes , reconcileErr
85+ }
86+
87+ statusUpdated := false
88+ if reconcileErr != nil {
89+ // update status condition with error
90+ statusUpdated = function .Status .MarkDeployFailed ("ReconcileError" , "%s" , reconcileErr .Error ())
91+ } else {
92+ // clear previous errors
93+ statusUpdated = function .Status .MarkDeploySucceeded ()
94+ }
95+
96+ if statusUpdated {
97+ // update status
98+ if err := r .Status ().Update (ctx , function ); err != nil {
99+ logger .Error (err , "Unable to update Function status conditions" , "functionName" , function .Name , "functionNamespace" , function .Namespace )
100+ return reconcileRes , reconcileErr
101+ }
102+ }
103+
104+ return reconcileRes , reconcileErr
105+ }
106+
107+ func (r * FunctionReconciler ) reconcile (ctx context.Context , req ctrl.Request ) (ctrl.Result , error ) {
108+ logger := logf .FromContext (ctx )
109+
74110 function := & v1alpha1.Function {}
75111 err := r .Get (ctx , req .NamespacedName , function )
76112 if err != nil {
0 commit comments