Andrey Smirnov 565c747582 fix: install sequence stuck on event bus
machined's main.go waits for boot sequence to finish, while metal
platform initializer tries to send a message to the event bus without
any listeners, so this is pure deadlock.

Resolve that by panicking from initializer, this aborts phase and
sequence, and leads to reboot on panic. Not really clean as it leaves
scary stacktraces in the dmesg, but it works. Cleanup might be done by
introducing error value for reboot, and ignoring it when printing the
errors.

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
2020-01-21 16:28:00 -06:00

48 lines
1.3 KiB
Go

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package metal
import (
"errors"
"github.com/talos-systems/talos/internal/pkg/install"
"github.com/talos-systems/talos/internal/pkg/mount"
"github.com/talos-systems/talos/internal/pkg/mount/manager"
"github.com/talos-systems/talos/internal/pkg/mount/manager/owned"
"github.com/talos-systems/talos/internal/pkg/runtime"
)
// Metal represents an initializer that performs a full installation to a
// disk.
type Metal struct{}
// Initialize implements the Initializer interface.
func (b *Metal) Initialize(r runtime.Runtime) (err error) {
// Attempt to discover a previous installation
// An err case should only happen if no partitions
// with matching labels were found
var mountpoints *mount.Points
mountpoints, err = owned.MountPointsFromLabels()
if err != nil {
if r.Config().Machine().Install().Image() == "" {
return errors.New("an install image is required")
}
if err = install.RunInstallerContainer(r); err != nil {
return err
}
panic(runtime.ErrReboot)
}
m := manager.NewManager(mountpoints)
if err = m.MountAll(); err != nil {
return err
}
return nil
}