refactor: improve metal platform

This brings in a few minor improvements to the metal platform. The first
is to use talos.config=metal-iso to indicate that the machine's config
can be found in an ISO image. The second is a fix to ensure that /mnt
exists.

This adds support for creating more than one node using the qemu-boot.sh
script.

Signed-off-by: Andrew Rynhard <andrew@andrewrynhard.com>
This commit is contained in:
Andrew Rynhard 2019-10-15 02:03:38 +00:00
parent 63c7ea4987
commit 10b6202c4f
4 changed files with 39 additions and 39 deletions

View File

@ -220,7 +220,7 @@ COPY hack/containerd.toml /etc/containerd-system.toml
RUN touch /rootfs/etc/resolv.conf
RUN touch /rootfs/etc/hosts
RUN touch /rootfs/etc/os-release
RUN mkdir -pv /rootfs/{boot,usr/local/share}
RUN mkdir -pv /rootfs/{boot,usr/local/share,mnt}
RUN mkdir -pv /rootfs/{etc/kubernetes/manifests,etc/cni,usr/libexec/kubernetes}
RUN ln -s /etc/ssl /rootfs/etc/pki
RUN ln -s /etc/ssl /rootfs/usr/share/ca-certificates

View File

@ -7,8 +7,7 @@ package metal
import (
"io/ioutil"
"net"
"os"
"path"
"path/filepath"
"github.com/pkg/errors"
"golang.org/x/sys/unix"
@ -39,37 +38,12 @@ func (b *Metal) Configuration() ([]byte, error) {
return nil, errors.Errorf("no config option was found")
}
if *option == constants.UserDataCIData {
var dev *probe.ProbedBlockDevice
dev, err := probe.GetDevWithFileSystemLabel(constants.UserDataCIData)
if err != nil {
return nil, errors.Errorf("failed to find %s iso: %v", constants.UserDataCIData, err)
}
if err = os.Mkdir(mnt, 0700); err != nil {
return nil, errors.Errorf("failed to mkdir: %v", err)
}
if err = unix.Mount(dev.Path, mnt, dev.SuperBlock.Type(), unix.MS_RDONLY, ""); err != nil {
return nil, errors.Errorf("failed to mount iso: %v", err)
}
var b []byte
b, err = ioutil.ReadFile(path.Join(mnt, "user-data"))
if err != nil {
return nil, errors.Errorf("read config: %s", err.Error())
}
if err = unix.Unmount(mnt, 0); err != nil {
return nil, errors.Errorf("failed to unmount: %v", err)
}
return b, nil
switch *option {
case constants.MetalConfigISOLabel:
return readConfigFromISO()
default:
return config.Download(*option)
}
return config.Download(*option)
}
// Mode implements the platform.Platform interface.
@ -86,3 +60,27 @@ func (b *Metal) Hostname() (hostname []byte, err error) {
func (b *Metal) ExternalIPs() (addrs []net.IP, err error) {
return addrs, err
}
func readConfigFromISO() (b []byte, err error) {
var dev *probe.ProbedBlockDevice
dev, err = probe.GetDevWithFileSystemLabel(constants.MetalConfigISOLabel)
if err != nil {
return nil, errors.Errorf("failed to find %s iso: %v", constants.MetalConfigISOLabel, err)
}
if err = unix.Mount(dev.Path, mnt, dev.SuperBlock.Type(), unix.MS_RDONLY, ""); err != nil {
return nil, errors.Errorf("failed to mount iso: %v", err)
}
b, err = ioutil.ReadFile(filepath.Join(mnt, filepath.Base(constants.ConfigPath)))
if err != nil {
return nil, errors.Errorf("read config: %s", err.Error())
}
if err = unix.Unmount(mnt, 0); err != nil {
return nil, errors.Errorf("failed to unmount: %v", err)
}
return b, nil
}

View File

@ -5,6 +5,7 @@
package metal
import (
"errors"
"strings"
"github.com/talos-systems/talos/internal/pkg/event"
@ -29,14 +30,16 @@ func (b *Metal) Initialize(platform platform.Platform, install machine.Install)
mountpoints, err = owned.MountPointsFromLabels()
if err != nil {
// if install.Image() == "" {
// install.Image() = fmt.Sprintf("%s:%s", constants.DefaultInstallerImageRepository, version.Tag)
// }
if install.Image() == "" {
return errors.New("an install image is required")
}
if err = installer.Install(install.Image(), install.Disk(), strings.ToLower(platform.Name())); err != nil {
return err
}
event.Bus().Notify(event.Event{Type: event.Reboot})
// Prevent the task from returning to prevent the next phase from
// running.
select {}

View File

@ -158,9 +158,8 @@ const (
// ConfigPath is the path to the downloaded config.
ConfigPath = "/run/config.yaml"
// UserDataCIData is the volume label for NoCloud cloud-init.
// See https://cloudinit.readthedocs.io/en/latest/topics/datasources/nocloud.html#datasource-nocloud.
UserDataCIData = "cidata"
// MetalConfigISOLabel is the volume label for ISO based configuration.
MetalConfigISOLabel = "metal-iso"
// ConfigGuestInfo is the name of the VMware guestinfo config strategy.
ConfigGuestInfo = "guestinfo"