Skip to content

Commit 2d01967

Browse files
committed
fix(vmip): fix double create VirtualMachineIPLease
Signed-off-by: Dmitry Lopatin <dmitry.lopatin@flant.com>
1 parent ce873a2 commit 2d01967

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

images/virtualization-artifact/pkg/controller/vmip/internal/iplease_handler.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23+
"time"
2324

2425
corev1 "k8s.io/api/core/v1"
2526
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -183,7 +184,7 @@ func (h IPLeaseHandler) createNewLease(ctx context.Context, state state.VMIPStat
183184

184185
h.recorder.Event(vmip, corev1.EventTypeNormal, virtv2.ReasonBound, "VirtualMachineIPAddress is bound to a new VirtualMachineIPAddressLease.")
185186

186-
return reconcile.Result{}, nil
187+
return reconcile.Result{RequeueAfter: 2 * time.Second}, nil
187188
}
188189

189190
func (h IPLeaseHandler) Name() string {

images/virtualization-artifact/pkg/controller/vmiplease/vmiplease_reconciler.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,6 @@ func (r *Reconciler) Reconcile(ctx context.Context, req reconcile.Request) (reco
109109
return h.Handle(ctx, s)
110110
})
111111
rec.SetResourceUpdater(func(ctx context.Context) error {
112-
if s.ShouldDeletion() {
113-
return r.client.Delete(ctx, lease.Changed())
114-
}
115-
116112
if !reflect.DeepEqual(lease.Current().Spec, lease.Changed().Spec) {
117113
leaseStatus := lease.Changed().Status.DeepCopy()
118114
err = r.client.Update(ctx, lease.Changed())
@@ -122,7 +118,16 @@ func (r *Reconciler) Reconcile(ctx context.Context, req reconcile.Request) (reco
122118
lease.Changed().Status = *leaseStatus
123119
}
124120

125-
return lease.Update(ctx)
121+
err = lease.Update(ctx)
122+
if err != nil {
123+
return err
124+
}
125+
126+
if s.ShouldDeletion() {
127+
return r.client.Delete(ctx, lease.Changed())
128+
}
129+
130+
return nil
126131
})
127132

128133
return rec.Reconcile(ctx)

0 commit comments

Comments
 (0)