diff --git a/internal/controller/exporter_controller.go b/internal/controller/exporter_controller.go index aaecb81..83ac7d3 100644 --- a/internal/controller/exporter_controller.go +++ b/internal/controller/exporter_controller.go @@ -82,17 +82,20 @@ func (r *ExporterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c return ctrl.Result{}, err } - exporter.Status.LeaseRef = nil + var leaseRef *corev1.LocalObjectReference for _, lease := range leases.Items { if !lease.Status.Ended && lease.Status.ExporterRef != nil { if lease.Status.ExporterRef.Name == exporter.Name { - exporter.Status.LeaseRef = &corev1.LocalObjectReference{Name: lease.Name} + leaseRef = &corev1.LocalObjectReference{Name: lease.Name} } } } - if err = r.Status().Update(ctx, exporter); err != nil { - logger.Error(err, "reconcile: unable to update Exporter with leaseRef", "exporter", req.NamespacedName) - return ctrl.Result{}, err + if !compareLocalObjectReference(exporter.Status.LeaseRef, leaseRef) { + exporter.Status.LeaseRef = leaseRef + if err = r.Status().Update(ctx, exporter); err != nil { + logger.Error(err, "reconcile: unable to update Exporter with leaseRef", "exporter", req.NamespacedName) + return ctrl.Result{}, err + } } if exporter.Status.Credential == nil { @@ -159,6 +162,16 @@ func (r *ExporterReconciler) secretForExporter(exporter *jumpstarterdevv1alpha1. return secret, nil } +func compareLocalObjectReference(a, b *corev1.LocalObjectReference) bool { + if a == nil && b == nil { + return true + } + if a == nil || b == nil { + return false + } + return *a == *b +} + // SetupWithManager sets up the controller with the Manager. func (r *ExporterReconciler) SetupWithManager(mgr ctrl.Manager) error { return ctrl.NewControllerManagedBy(mgr).