Finalizer example possible bug #4290
-
The finalizer example in the book performs a Since the code roughly does func (r *CronJobReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
//...
if cronJob.ObjectMeta.DeletionTimestamp.IsZero() {
if !controllerutil.ContainsFinalizer(cronJob, myFinalizerName) {
controllerutil.AddFinalizer(cronJob, myFinalizerName)
if err := r.Update(ctx, cronJob); err != nil {
return ctrl.Result{}, err
}
}
}
// reconciliation logic
} Wouldn't that code as is cause an error when the reconciliation logic attempt to update the status (e.g. here)? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi @lorenzofelletti, The best approach would be to refactor the code of the CronJob and MultiVersion samples to follow the structure generated by the DeployImage plugin (which scaffolds the code to manage an image provided via the command line). Example:
The best practice is to fetch the resource before updating it. This avoids scenarios where an update fails due to an intermediate change, which could cause the reconciliation process to restart. Refer to the example below for guidance: To align with the above examples, we have indeed some refactoring tasks: If you wish to work on and help us improve the CronJob and MultiVersion in order of them be exactly the same controller and controller test scaffold done by DeployImage plugin with only the required logic for this example on top that would be great. Help is more than welcome. |
Beta Was this translation helpful? Give feedback.
-
Furthermore we created the issue : #4291 If you see that is required please feel free to re-open this one. |
Beta Was this translation helpful? Give feedback.
Hi @lorenzofelletti,
The best approach would be to refactor the code of the CronJob and MultiVersion samples to follow the structure generated by the DeployImage plugin (which scaffolds the code to manage an image provided via the command line).
Example:
The best practice is to fetch the resource before updating it. This avoids scenarios where an update fails due to an intermediate change, which could cause the reconciliation process to restart. Refer to the example below for guidance:
kubebuilder/testdata/project-v4-with-plugins/internal/controller/busybox_controller.go
Lines 101 to 118 in 5…