Skip to content

Commit

Permalink
re-introduces patchMachineStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
srm09 committed Nov 5, 2020
1 parent 047d3e1 commit aafcd97
Showing 1 changed file with 19 additions and 28 deletions.
47 changes: 19 additions & 28 deletions controllers/machineset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,34 +248,29 @@ func (r *MachineSetReconciler) reconcile(ctx context.Context, cluster *clusterv1
}

syncErr := r.syncReplicas(ctx, machineSet, filteredMachines)
if syncErr != nil {
return ctrl.Result{}, errors.Wrapf(syncErr, "failed to sync MachineSet replicas")
}

ms := machineSet.DeepCopy()
newStatus, err := r.calculateStatus(ctx, cluster, ms, filteredMachines)
if err != nil {
return ctrl.Result{}, errors.Wrapf(err, "failed to calculate MachineSet's Status")
}
// add the newly calculated status to the machine set
newStatus.DeepCopyInto(&ms.Status)

// Always updates status as machines come up or die.
//updatedMS, err := r.patchMachineSetStatus(ctx, machineSet, newStatus)
//if err != nil {
// if syncErr != nil {
// return ctrl.Result{}, errors.Wrapf(err, "failed to sync machines: %v. failed to patch MachineSet's Status", syncErr)
// }
// return ctrl.Result{}, errors.Wrap(err, "failed to patch MachineSet's Status")
//}

//if syncErr != nil {
// return ctrl.Result{}, errors.Wrapf(syncErr, "failed to sync MachineSet replicas")
//}
updatedMS, err := r.patchMachineSetStatus(ctx, machineSet, newStatus)
if err != nil {
if syncErr != nil {
return ctrl.Result{}, errors.Wrapf(err, "failed to sync machines: %v. failed to patch MachineSet's Status", syncErr)
}
return ctrl.Result{}, errors.Wrap(err, "failed to patch MachineSet's Status")
}

if syncErr != nil {
return ctrl.Result{}, errors.Wrapf(syncErr, "failed to sync MachineSet replicas")
}

var replicas int32
if ms.Spec.Replicas != nil {
replicas = *ms.Spec.Replicas
if updatedMS.Spec.Replicas != nil {
replicas = *updatedMS.Spec.Replicas
}

// Resync the MachineSet after MinReadySeconds as a last line of defense to guard against clock-skew.
Expand All @@ -285,15 +280,15 @@ func (r *MachineSetReconciler) reconcile(ctx context.Context, cluster *clusterv1
// exceeds MinReadySeconds could be incorrect.
// To avoid an available replica stuck in the ready state, we force a reconcile after MinReadySeconds,
// at which point it should confirm any available replica to be available.
if ms.Spec.MinReadySeconds > 0 &&
ms.Status.ReadyReplicas == replicas &&
ms.Status.AvailableReplicas != replicas {
if updatedMS.Spec.MinReadySeconds > 0 &&
updatedMS.Status.ReadyReplicas == replicas &&
updatedMS.Status.AvailableReplicas != replicas {

return ctrl.Result{RequeueAfter: time.Duration(ms.Spec.MinReadySeconds) * time.Second}, nil
return ctrl.Result{RequeueAfter: time.Duration(updatedMS.Spec.MinReadySeconds) * time.Second}, nil
}

// Quickly reconcile until the nodes become Ready.
if ms.Status.ReadyReplicas != replicas {
if updatedMS.Status.ReadyReplicas != replicas {
log.V(4).Info("Some nodes are not ready yet, requeuing until they are ready")
return ctrl.Result{RequeueAfter: 15 * time.Second}, nil
}
Expand Down Expand Up @@ -656,8 +651,6 @@ func (r *MachineSetReconciler) patchMachineSetStatus(ctx context.Context, ms *cl
return ms, nil
}

patch := client.MergeFrom(ms.DeepCopyObject())

// Save the generation number we acted on, otherwise we might wrongfully indicate
// that we've seen a spec update when we retry.
newStatus.ObservedGeneration = ms.Generation
Expand All @@ -675,9 +668,7 @@ func (r *MachineSetReconciler) patchMachineSetStatus(ctx context.Context, ms *cl
fmt.Sprintf("sequence No: %v->%v", ms.Status.ObservedGeneration, newStatus.ObservedGeneration))

newStatus.DeepCopyInto(&ms.Status)
if err := r.Client.Status().Patch(ctx, ms, patch); err != nil {
return nil, err
}

return ms, nil
}

Expand Down

0 comments on commit aafcd97

Please sign in to comment.