Skip to content

Commit

Permalink
Merge pull request #19 from ibrokethecloud/recreate-machine
Browse files Browse the repository at this point in the history
improve machine reconcile when inventory spec changes
  • Loading branch information
bk201 authored Jul 31, 2023
2 parents 3f487d8 + d418e33 commit 707d3ed
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions pkg/controllers/inventory_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,14 +407,30 @@ func (r *InventoryReconciler) hasMachineSpecChanged(ctx context.Context, iObj *s
existingObj := &rufio.Machine{}
err := r.Get(ctx, types.NamespacedName{Name: i.Name, Namespace: i.Namespace}, existingObj)
if err != nil {
if apierrors.IsNotFound(err) {
return r.checkAndResetInventory(ctx, i)
}
return err
}

if !reflect.DeepEqual(existingObj.Spec, i.Spec.BaseboardManagementSpec) && seederv1alpha1.BMCObjectCreated.IsTrue(i) {
seederv1alpha1.BMCObjectCreated.False(i)
err := r.Delete(ctx, existingObj)
if err != nil {
return err
}
return r.checkAndResetInventory(ctx, i)
}

return nil
}

func (r *InventoryReconciler) checkAndResetInventory(ctx context.Context, iObj *seederv1alpha1.Inventory) error {
i := iObj.DeepCopy()
if i.Status.Status == seederv1alpha1.InventoryReady || util.ConditionExists(i, seederv1alpha1.BMCObjectCreated) || util.ConditionExists(i, seederv1alpha1.MachineNotContactable) {
util.RemoveCondition(i, seederv1alpha1.BMCObjectCreated)
util.RemoveCondition(i, seederv1alpha1.MachineNotContactable)
i.Status.Status = ""
return r.Status().Update(ctx, i)
}

return nil
}

0 comments on commit 707d3ed

Please sign in to comment.