Skip to content

Commit

Permalink
Merge pull request #60 from jumpstarter-dev/lease-ref
Browse files Browse the repository at this point in the history
Only update exporter leaseRef when changed
  • Loading branch information
mangelajo authored Oct 18, 2024
2 parents d64f032 + 01ea493 commit a0d1329
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions internal/controller/exporter_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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).
Expand Down

0 comments on commit a0d1329

Please sign in to comment.