diff --git a/cmd/root.go b/cmd/root.go index dfe5f6cb..fb145f96 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -126,6 +126,7 @@ func Run(spec *Specification, hal hal.InBand) (*event.EventEmitter, error) { if err != nil { return eventEmitter, errors.Wrap(err, "fetch") } + if m != nil && m.Allocation != nil && m.Allocation.Reinstall != nil && *m.Allocation.Reinstall { hammer.FilesystemLayout = m.Allocation.Filesystemlayout primaryDiskWiped := false @@ -143,9 +144,22 @@ func Run(spec *Specification, hal hal.InBand) (*event.EventEmitter, error) { return eventEmitter, err } - err = storage.WipeDisks() - if err != nil { - return eventEmitter, errors.Wrap(err, "wipe") + wipeDisks := false + if m == nil || m.Allocation == nil { + // the machine belongs to no one, we can safely erase disks + wipeDisks = true + } + if m != nil && m.Allocation != nil && !*m.Allocation.Succeeded { + // the allocation has not succeeded, we're running in a crash loop + // in this case, we start all over again + wipeDisks = true + } + + if wipeDisks { + err = storage.WipeDisks() + if err != nil { + return eventEmitter, errors.Wrap(err, "wipe") + } } err = hammer.ConfigureBIOS()