feat: add Runtime interface

Instead of passing around a struct, it is better if we pass around an
interface that describes the behavior we want. The Runtime interface
provides a common place to describe runtime specific parameters. This
initial implementation offers the runtime mode, the platform specifics,
and the config.

Signed-off-by: Andrew Rynhard <andrew@andrewrynhard.com>
This commit is contained in:
Andrew Rynhard 2019-10-11 04:36:00 +00:00
parent e6f980463f
commit 8153c2e2a9
62 changed files with 280 additions and 237 deletions

View File

@ -14,7 +14,7 @@ import (
"github.com/talos-systems/talos/internal/pkg/installer" "github.com/talos-systems/talos/internal/pkg/installer"
"github.com/talos-systems/talos/internal/pkg/kernel" "github.com/talos-systems/talos/internal/pkg/kernel"
"github.com/talos-systems/talos/internal/pkg/platform" "github.com/talos-systems/talos/internal/pkg/runtime/platform"
machineconfig "github.com/talos-systems/talos/pkg/config" machineconfig "github.com/talos-systems/talos/pkg/config"
"github.com/talos-systems/talos/pkg/config/types/v1alpha1" "github.com/talos-systems/talos/pkg/config/types/v1alpha1"
"github.com/talos-systems/talos/pkg/constants" "github.com/talos-systems/talos/pkg/constants"

View File

@ -24,8 +24,8 @@ func NewHandlerTask() phase.Task {
return &Handler{} return &Handler{}
} }
// RuntimeFunc returns the runtime function. // TaskFunc returns the runtime function.
func (task *Handler) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { func (task *Handler) TaskFunc(mode runtime.Mode) phase.TaskFunc {
switch mode { switch mode {
case runtime.Container: case runtime.Container:
return nil return nil
@ -34,7 +34,7 @@ func (task *Handler) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc {
} }
} }
func (task *Handler) standard(args *phase.RuntimeArgs) (err error) { func (task *Handler) standard(r runtime.Runtime) (err error) {
if err := listenForPowerButton(); err != nil { if err := listenForPowerButton(); err != nil {
log.Printf("WARNING: power off events will be ignored: %+v", err) log.Printf("WARNING: power off events will be ignored: %+v", err)
} }

View File

@ -20,15 +20,15 @@ func NewConfigTask() phase.Task {
return &Task{} return &Task{}
} }
// RuntimeFunc returns the runtime function. // TaskFunc returns the runtime function.
func (task *Task) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { func (task *Task) TaskFunc(mode runtime.Mode) phase.TaskFunc {
return task.standard return task.standard
} }
func (task *Task) standard(args *phase.RuntimeArgs) (err error) { func (task *Task) standard(r runtime.Runtime) (err error) {
var b []byte var b []byte
if b, err = args.Platform().Configuration(); err != nil { if b, err = r.Platform().Configuration(); err != nil {
return err return err
} }

View File

@ -23,15 +23,15 @@ func NewExtraDevicesTask() phase.Task {
return &ExtraDevices{} return &ExtraDevices{}
} }
// RuntimeFunc returns the runtime function. // TaskFunc returns the runtime function.
func (task *ExtraDevices) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { func (task *ExtraDevices) TaskFunc(mode runtime.Mode) phase.TaskFunc {
return task.runtime return task.runtime
} }
func (task *ExtraDevices) runtime(args *phase.RuntimeArgs) (err error) { func (task *ExtraDevices) runtime(r runtime.Runtime) (err error) {
mountpoints := mount.NewMountPoints() mountpoints := mount.NewMountPoints()
for _, extra := range args.Config().Machine().Install().ExtraDisks() { for _, extra := range r.Config().Machine().Install().ExtraDisks() {
for i, part := range extra.Partitions { for i, part := range extra.Partitions {
devname := fmt.Sprintf("%s%d", extra.Device, i+1) devname := fmt.Sprintf("%s%d", extra.Device, i+1)
mountpoints.Set(devname, mount.NewMountPoint(devname, part.MountPoint, "xfs", unix.MS_NOATIME, "")) mountpoints.Set(devname, mount.NewMountPoint(devname, part.MountPoint, "xfs", unix.MS_NOATIME, ""))

View File

@ -20,13 +20,13 @@ func NewExtraEnvVarsTask() phase.Task {
return &ExtraEnvVars{} return &ExtraEnvVars{}
} }
// RuntimeFunc returns the runtime function. // TaskFunc returns the runtime function.
func (task *ExtraEnvVars) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { func (task *ExtraEnvVars) TaskFunc(mode runtime.Mode) phase.TaskFunc {
return task.runtime return task.runtime
} }
func (task *ExtraEnvVars) runtime(args *phase.RuntimeArgs) (err error) { func (task *ExtraEnvVars) runtime(r runtime.Runtime) (err error) {
for key, val := range args.Config().Machine().Env() { for key, val := range r.Config().Machine().Env() {
if err = os.Setenv(key, val); err != nil { if err = os.Setenv(key, val); err != nil {
log.Printf("WARNING failed to set enivronment variable: %v", err) log.Printf("WARNING failed to set enivronment variable: %v", err)
} }

View File

@ -23,15 +23,15 @@ func NewExtraFilesTask() phase.Task {
return &ExtraFiles{} return &ExtraFiles{}
} }
// RuntimeFunc returns the runtime function. // TaskFunc returns the runtime function.
func (task *ExtraFiles) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { func (task *ExtraFiles) TaskFunc(mode runtime.Mode) phase.TaskFunc {
return task.runtime return task.runtime
} }
func (task *ExtraFiles) runtime(args *phase.RuntimeArgs) (err error) { func (task *ExtraFiles) runtime(r runtime.Runtime) (err error) {
var result *multierror.Error var result *multierror.Error
for _, f := range args.Config().Machine().Files() { for _, f := range r.Config().Machine().Files() {
p := filepath.Join("/var", f.Path) p := filepath.Join("/var", f.Path)
if err = os.MkdirAll(filepath.Dir(p), os.ModeDir); err != nil { if err = os.MkdirAll(filepath.Dir(p), os.ModeDir); err != nil {
result = multierror.Append(result, err) result = multierror.Append(result, err)

View File

@ -21,15 +21,15 @@ func NewSaveConfigTask() phase.Task {
return &SaveConfig{} return &SaveConfig{}
} }
// RuntimeFunc returns the runtime function. // TaskFunc returns the runtime function.
func (task *SaveConfig) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { func (task *SaveConfig) TaskFunc(mode runtime.Mode) phase.TaskFunc {
return task.runtime return task.runtime
} }
func (task *SaveConfig) runtime(args *phase.RuntimeArgs) (err error) { func (task *SaveConfig) runtime(r runtime.Runtime) (err error) {
log.Printf("saving config %s to disk\n", args.Config().Version()) log.Printf("saving config %s to disk\n", r.Config().Version())
s, err := args.Config().String() s, err := r.Config().String()
if err != nil { if err != nil {
return err return err
} }

View File

@ -26,9 +26,9 @@ func NewResetDiskTask(devname string) phase.Task {
} }
} }
// RuntimeFunc returns the runtime function. // TaskFunc returns the runtime function.
func (task *ResetDisk) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { func (task *ResetDisk) TaskFunc(mode runtime.Mode) phase.TaskFunc {
return func(args *phase.RuntimeArgs) error { return func(r runtime.Runtime) error {
return task.standard() return task.standard()
} }
} }

View File

@ -21,9 +21,9 @@ func NewCordonAndDrainTask() phase.Task {
return &CordonAndDrain{} return &CordonAndDrain{}
} }
// RuntimeFunc returns the runtime function. // TaskFunc returns the runtime function.
func (task *CordonAndDrain) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { func (task *CordonAndDrain) TaskFunc(mode runtime.Mode) phase.TaskFunc {
return func(args *phase.RuntimeArgs) error { return func(r runtime.Runtime) error {
return task.standard() return task.standard()
} }
} }

View File

@ -30,9 +30,9 @@ func NewKillKubernetesTasksTask() phase.Task {
return &KillKubernetesTasks{} return &KillKubernetesTasks{}
} }
// RuntimeFunc returns the runtime function. // TaskFunc returns the runtime function.
func (task *KillKubernetesTasks) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { func (task *KillKubernetesTasks) TaskFunc(mode runtime.Mode) phase.TaskFunc {
return func(args *phase.RuntimeArgs) error { return func(r runtime.Runtime) error {
return task.standard() return task.standard()
} }
} }

View File

@ -23,8 +23,8 @@ func NewUserDefinedNetworkTask() phase.Task {
return &UserDefinedNetwork{} return &UserDefinedNetwork{}
} }
// RuntimeFunc returns the runtime function. // TaskFunc returns the runtime function.
func (task *UserDefinedNetwork) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { func (task *UserDefinedNetwork) TaskFunc(mode runtime.Mode) phase.TaskFunc {
switch mode { switch mode {
case runtime.Container: case runtime.Container:
return nil return nil
@ -34,7 +34,7 @@ func (task *UserDefinedNetwork) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc
} }
// nolint: gocyclo // nolint: gocyclo
func (task *UserDefinedNetwork) runtime(args *phase.RuntimeArgs) (err error) { func (task *UserDefinedNetwork) runtime(r runtime.Runtime) (err error) {
nwd, err := networkd.New() nwd, err := networkd.New()
if err != nil { if err != nil {
return err return err

View File

@ -13,24 +13,24 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/talos-systems/talos/internal/pkg/kmsg" "github.com/talos-systems/talos/internal/pkg/kmsg"
"github.com/talos-systems/talos/internal/pkg/platform"
"github.com/talos-systems/talos/internal/pkg/runtime" "github.com/talos-systems/talos/internal/pkg/runtime"
"github.com/talos-systems/talos/internal/pkg/runtime/platform"
"github.com/talos-systems/talos/pkg/config" "github.com/talos-systems/talos/pkg/config"
) )
// RuntimeArgs represents the set of arguments passed into a RuntimeFunc. // RuntimeArgs represents the set of arguments passed into a TaskFunc.
type RuntimeArgs struct { type RuntimeArgs struct {
platform platform.Platform platform runtime.Platform
config config.Configurator config config.Configurator
} }
// RuntimeFunc defines the function that a task must return. The function // TaskFunc defines the function that a task must return. The function
// envelopes the task logic for a given runtime mode. // envelopes the task logic for a given runtime mode.
type RuntimeFunc func(*RuntimeArgs) error type TaskFunc func(runtime.Runtime) error
// Task represents a task within a Phase. // Task represents a task within a Phase.
type Task interface { type Task interface {
RuntimeFunc(runtime.Mode) RuntimeFunc TaskFunc(runtime.Mode) TaskFunc
} }
// Phase represents a phase in the boot process. // Phase represents a phase in the boot process.
@ -41,8 +41,8 @@ type Phase struct {
// Runner represents a management layer for phases. // Runner represents a management layer for phases.
type Runner struct { type Runner struct {
phases []*Phase phases []*Phase
args *RuntimeArgs runtime runtime.Runtime
} }
// NewRunner initializes and returns a Runner. // NewRunner initializes and returns a Runner.
@ -52,8 +52,7 @@ func NewRunner(config config.Configurator) (*Runner, error) {
return nil, err return nil, err
} }
mode := platform.Mode() switch platform.Mode() {
switch mode {
case runtime.Metal: case runtime.Metal:
fallthrough fallthrough
case runtime.Cloud: case runtime.Cloud:
@ -64,17 +63,14 @@ func NewRunner(config config.Configurator) (*Runner, error) {
} }
runner := &Runner{ runner := &Runner{
args: &RuntimeArgs{ runtime: runtime.NewRuntime(platform, config),
platform: platform,
config: config,
},
} }
return runner, nil return runner, nil
} }
// Platform returns the platform. // Platform returns the platform.
func (r *RuntimeArgs) Platform() platform.Platform { func (r *RuntimeArgs) Platform() runtime.Platform {
return r.platform return r.platform
} }
@ -139,13 +135,13 @@ func (r *Runner) runTask(task Task, errCh chan<- error) {
} }
}() }()
var f RuntimeFunc var f TaskFunc
if f = task.RuntimeFunc(r.args.Platform().Mode()); f == nil { if f = task.TaskFunc(r.runtime.Platform().Mode()); f == nil {
// A task is not defined for this runtime mode. // A task is not defined for this runtime mode.
return return
} }
err = f(r.args) err = f(r.runtime)
} }
// Add adds a phase to a Runner. // Add adds a phase to a Runner.

View File

@ -26,22 +26,22 @@ type regularTask struct {
errCh <-chan error errCh <-chan error
} }
func (t *regularTask) RuntimeFunc(runtime.Mode) phase.RuntimeFunc { func (t *regularTask) TaskFunc(runtime.Mode) phase.TaskFunc {
return func(*phase.RuntimeArgs) error { return func(runtime.Runtime) error {
return <-t.errCh return <-t.errCh
} }
} }
type nilTask struct{} type nilTask struct{}
func (t *nilTask) RuntimeFunc(runtime.Mode) phase.RuntimeFunc { func (t *nilTask) TaskFunc(runtime.Mode) phase.TaskFunc {
return nil return nil
} }
type panicTask struct{} type panicTask struct{}
func (t *panicTask) RuntimeFunc(runtime.Mode) phase.RuntimeFunc { func (t *panicTask) TaskFunc(runtime.Mode) phase.TaskFunc {
return func(*phase.RuntimeArgs) error { return func(runtime.Runtime) error {
panic("in task") panic("in task")
} }
} }

View File

@ -18,31 +18,31 @@ func NewPlatformTask() phase.Task {
return &Platform{} return &Platform{}
} }
// RuntimeFunc returns the runtime function. // TaskFunc returns the runtime function.
func (task *Platform) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { func (task *Platform) TaskFunc(mode runtime.Mode) phase.TaskFunc {
return task.runtime return task.runtime
} }
func (task *Platform) runtime(args *phase.RuntimeArgs) (err error) { func (task *Platform) runtime(r runtime.Runtime) (err error) {
i, err := initializer.New(args.Platform().Mode()) i, err := initializer.New(r.Platform().Mode())
if err != nil { if err != nil {
return err return err
} }
if err = i.Initialize(args.Platform(), args.Config().Machine().Install()); err != nil { if err = i.Initialize(r.Platform(), r.Config().Machine().Install()); err != nil {
return err return err
} }
hostname, err := args.Platform().Hostname() hostname, err := r.Platform().Hostname()
if err != nil { if err != nil {
return err return err
} }
if hostname != nil { if hostname != nil {
args.Config().Machine().Network().SetHostname(string(hostname)) r.Config().Machine().Network().SetHostname(string(hostname))
} }
addrs, err := args.Platform().ExternalIPs() addrs, err := r.Platform().ExternalIPs()
if err != nil { if err != nil {
return err return err
} }
@ -52,8 +52,8 @@ func (task *Platform) runtime(args *phase.RuntimeArgs) (err error) {
sans = append(sans, addr.String()) sans = append(sans, addr.String())
} }
args.Config().Machine().Security().SetCertSANs(sans) r.Config().Machine().Security().SetCertSANs(sans)
args.Config().Cluster().SetCertSANs(sans) r.Config().Cluster().SetCertSANs(sans)
return nil return nil
} }

View File

@ -21,8 +21,8 @@ func NewCheckInstallTask() phase.Task {
return &CheckInstall{} return &CheckInstall{}
} }
// RuntimeFunc returns the runtime function. // TaskFunc returns the runtime function.
func (task *CheckInstall) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { func (task *CheckInstall) TaskFunc(mode runtime.Mode) phase.TaskFunc {
switch mode { switch mode {
case runtime.Container: case runtime.Container:
return nil return nil
@ -31,7 +31,7 @@ func (task *CheckInstall) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc {
} }
} }
func (task *CheckInstall) standard(args *phase.RuntimeArgs) (err error) { func (task *CheckInstall) standard(r runtime.Runtime) (err error) {
_, err = os.Stat(filepath.Join(constants.BootMountPoint, "installed")) _, err = os.Stat(filepath.Join(constants.BootMountPoint, "installed"))
return err return err
} }

View File

@ -22,8 +22,8 @@ func NewHostnameTask() phase.Task {
return &Hostname{} return &Hostname{}
} }
// RuntimeFunc returns the runtime function. // TaskFunc returns the runtime function.
func (task *Hostname) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { func (task *Hostname) TaskFunc(mode runtime.Mode) phase.TaskFunc {
switch mode { switch mode {
case runtime.Container: case runtime.Container:
return nil return nil
@ -32,7 +32,7 @@ func (task *Hostname) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc {
} }
} }
func (task *Hostname) runtime(args *phase.RuntimeArgs) (err error) { func (task *Hostname) runtime(r runtime.Runtime) (err error) {
// Create /etc/hosts and set hostname. // Create /etc/hosts and set hostname.
// Priority is: // Priority is:
// 1. Config (explicitly defined by the user) // 1. Config (explicitly defined by the user)
@ -44,21 +44,21 @@ func (task *Hostname) runtime(args *phase.RuntimeArgs) (err error) {
var platformHostname []byte var platformHostname []byte
platformHostname, err = args.Platform().Hostname() platformHostname, err = r.Platform().Hostname()
if err != nil { if err != nil {
return err return err
} }
configHostname := args.Config().Machine().Network().Hostname() configHostname := r.Config().Machine().Network().Hostname()
switch { switch {
case configHostname != "": case configHostname != "":
log.Printf("using hostname from config: %s\n", configHostname) log.Printf("using hostname from config: %s\n", configHostname)
case kernelHostname != nil: case kernelHostname != nil:
args.Config().Machine().Network().SetHostname(*kernelHostname) r.Config().Machine().Network().SetHostname(*kernelHostname)
log.Printf("using hostname provide via kernel arg: %s\n", *kernelHostname) log.Printf("using hostname provide via kernel arg: %s\n", *kernelHostname)
case platformHostname != nil: case platformHostname != nil:
args.Config().Machine().Network().SetHostname(string(platformHostname)) r.Config().Machine().Network().SetHostname(string(platformHostname))
log.Printf("using hostname provided via platform: %s\n", string(platformHostname)) log.Printf("using hostname provided via platform: %s\n", string(platformHostname))
// case data.Networking.OS.Hostname != "": // case data.Networking.OS.Hostname != "":
@ -66,5 +66,5 @@ func (task *Hostname) runtime(args *phase.RuntimeArgs) (err error) {
// log.Printf("dhcp hostname %s:", data.Networking.OS.Hostname) // log.Printf("dhcp hostname %s:", data.Networking.OS.Hostname)
} //nolint: wsl } //nolint: wsl
return etc.Hosts(args.Config().Machine().Network().Hostname()) return etc.Hosts(r.Config().Machine().Network().Hostname())
} }

View File

@ -20,8 +20,8 @@ func NewMountBPFFSTask() phase.Task {
return &MountBPFFS{} return &MountBPFFS{}
} }
// RuntimeFunc returns the runtime function. // TaskFunc returns the runtime function.
func (task *MountBPFFS) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { func (task *MountBPFFS) TaskFunc(mode runtime.Mode) phase.TaskFunc {
switch mode { switch mode {
case runtime.Container: case runtime.Container:
return nil return nil
@ -30,7 +30,7 @@ func (task *MountBPFFS) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc {
} }
} }
func (task *MountBPFFS) runtime(args *phase.RuntimeArgs) (err error) { func (task *MountBPFFS) runtime(r runtime.Runtime) (err error) {
var mountpoints *mount.Points var mountpoints *mount.Points
mountpoints, err = bpffs.MountPoints() mountpoints, err = bpffs.MountPoints()

View File

@ -35,8 +35,8 @@ func NewMountCgroupsTask() phase.Task {
return &MountCgroups{} return &MountCgroups{}
} }
// RuntimeFunc returns the runtime function. // TaskFunc returns the runtime function.
func (task *MountCgroups) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { func (task *MountCgroups) TaskFunc(mode runtime.Mode) phase.TaskFunc {
switch mode { switch mode {
case runtime.Container: case runtime.Container:
return nil return nil
@ -45,7 +45,7 @@ func (task *MountCgroups) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc {
} }
} }
func (task *MountCgroups) runtime(args *phase.RuntimeArgs) (err error) { func (task *MountCgroups) runtime(r runtime.Runtime) (err error) {
var mountpoints *mount.Points var mountpoints *mount.Points
mountpoints, err = cgroups.MountPoints() mountpoints, err = cgroups.MountPoints()

View File

@ -20,8 +20,8 @@ func NewMountOverlayTask() phase.Task {
return &MountOverlay{} return &MountOverlay{}
} }
// RuntimeFunc returns the runtime function. // TaskFunc returns the runtime function.
func (task *MountOverlay) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { func (task *MountOverlay) TaskFunc(mode runtime.Mode) phase.TaskFunc {
switch mode { switch mode {
case runtime.Container: case runtime.Container:
return nil return nil
@ -30,7 +30,7 @@ func (task *MountOverlay) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc {
} }
} }
func (task *MountOverlay) standard(args *phase.RuntimeArgs) (err error) { func (task *MountOverlay) standard(r runtime.Runtime) (err error) {
var mountpoints *mount.Points var mountpoints *mount.Points
mountpoints, err = overlay.MountPoints() mountpoints, err = overlay.MountPoints()

View File

@ -19,8 +19,8 @@ func NewMountSharedTask() phase.Task {
return &MountShared{} return &MountShared{}
} }
// RuntimeFunc returns the runtime function. // TaskFunc returns the runtime function.
func (task *MountShared) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { func (task *MountShared) TaskFunc(mode runtime.Mode) phase.TaskFunc {
switch mode { switch mode {
case runtime.Container: case runtime.Container:
return task.container return task.container
@ -29,7 +29,7 @@ func (task *MountShared) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc {
} }
} }
func (task *MountShared) container(args *phase.RuntimeArgs) (err error) { func (task *MountShared) container(r runtime.Runtime) (err error) {
targets := []string{"/", "/var/lib/kubelet", "/etc/cni"} targets := []string{"/", "/var/lib/kubelet", "/etc/cni"}
for _, t := range targets { for _, t := range targets {
if err = unix.Mount("", t, "", unix.MS_SHARED, ""); err != nil { if err = unix.Mount("", t, "", unix.MS_SHARED, ""); err != nil {

View File

@ -22,8 +22,8 @@ func NewMountSubDevicesTask() phase.Task {
return &MountSubDevices{} return &MountSubDevices{}
} }
// RuntimeFunc returns the runtime function. // TaskFunc returns the runtime function.
func (task *MountSubDevices) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { func (task *MountSubDevices) TaskFunc(mode runtime.Mode) phase.TaskFunc {
switch mode { switch mode {
case runtime.Container: case runtime.Container:
return nil return nil
@ -32,7 +32,7 @@ func (task *MountSubDevices) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc {
} }
} }
func (task *MountSubDevices) runtime(args *phase.RuntimeArgs) (err error) { func (task *MountSubDevices) runtime(r runtime.Runtime) (err error) {
var mountpoints *mount.Points var mountpoints *mount.Points
mountpoints, err = virtual.SubMountPoints() mountpoints, err = virtual.SubMountPoints()

View File

@ -18,8 +18,8 @@ func NewNetworkConfigurationTask() phase.Task {
return &NetworkConfiguration{} return &NetworkConfiguration{}
} }
// RuntimeFunc returns the runtime function. // TaskFunc returns the runtime function.
func (task *NetworkConfiguration) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { func (task *NetworkConfiguration) TaskFunc(mode runtime.Mode) phase.TaskFunc {
switch mode { switch mode {
case runtime.Container: case runtime.Container:
return nil return nil
@ -28,7 +28,7 @@ func (task *NetworkConfiguration) RuntimeFunc(mode runtime.Mode) phase.RuntimeFu
} }
} }
func (task *NetworkConfiguration) runtime(args *phase.RuntimeArgs) (err error) { func (task *NetworkConfiguration) runtime(r runtime.Runtime) (err error) {
// Create /etc/resolv.conf. // Create /etc/resolv.conf.
if err = etc.ResolvConf(); err != nil { if err = etc.ResolvConf(); err != nil {
return err return err

View File

@ -18,12 +18,12 @@ func NewOSReleaseTask() phase.Task {
return &OSRelease{} return &OSRelease{}
} }
// RuntimeFunc returns the runtime function. // TaskFunc returns the runtime function.
func (task *OSRelease) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { func (task *OSRelease) TaskFunc(mode runtime.Mode) phase.TaskFunc {
return task.runtime return task.runtime
} }
func (task *OSRelease) runtime(args *phase.RuntimeArgs) (err error) { func (task *OSRelease) runtime(r runtime.Runtime) (err error) {
// Create /etc/os-release. // Create /etc/os-release.
return etc.OSRelease() return etc.OSRelease()
} }

View File

@ -21,12 +21,12 @@ func NewSystemDirectoryTask() phase.Task {
return &SystemDirectory{} return &SystemDirectory{}
} }
// RuntimeFunc returns the runtime function. // TaskFunc returns the runtime function.
func (task *SystemDirectory) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { func (task *SystemDirectory) TaskFunc(mode runtime.Mode) phase.TaskFunc {
return task.runtime return task.runtime
} }
func (task *SystemDirectory) runtime(args *phase.RuntimeArgs) (err error) { func (task *SystemDirectory) runtime(r runtime.Runtime) (err error) {
for _, p := range []string{"etc", "log"} { for _, p := range []string{"etc", "log"} {
if err = os.MkdirAll(filepath.Join(constants.SystemRunPath, p), 0700); err != nil { if err = os.MkdirAll(filepath.Join(constants.SystemRunPath, p), 0700); err != nil {
return err return err

View File

@ -20,8 +20,8 @@ func NewUnmountOverlayTask() phase.Task {
return &UnmountOverlay{} return &UnmountOverlay{}
} }
// RuntimeFunc returns the runtime function. // TaskFunc returns the runtime function.
func (task *UnmountOverlay) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { func (task *UnmountOverlay) TaskFunc(mode runtime.Mode) phase.TaskFunc {
switch mode { switch mode {
case runtime.Container: case runtime.Container:
return nil return nil
@ -30,7 +30,7 @@ func (task *UnmountOverlay) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc {
} }
} }
func (task *UnmountOverlay) standard(args *phase.RuntimeArgs) (err error) { func (task *UnmountOverlay) standard(r runtime.Runtime) (err error) {
var mountpoints *mount.Points var mountpoints *mount.Points
mountpoints, err = overlay.MountPoints() mountpoints, err = overlay.MountPoints()

View File

@ -27,8 +27,8 @@ func NewUnmountPodMountsTask() phase.Task {
return &UnmountPodMounts{} return &UnmountPodMounts{}
} }
// RuntimeFunc returns the runtime function. // TaskFunc returns the runtime function.
func (task *UnmountPodMounts) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { func (task *UnmountPodMounts) TaskFunc(mode runtime.Mode) phase.TaskFunc {
switch mode { switch mode {
case runtime.Container: case runtime.Container:
return nil return nil
@ -37,16 +37,16 @@ func (task *UnmountPodMounts) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc {
} }
} }
func (task *UnmountPodMounts) standard(args *phase.RuntimeArgs) (err error) { func (task *UnmountPodMounts) standard(r runtime.Runtime) (err error) {
var b []byte var b []byte
if b, err = ioutil.ReadFile("/proc/self/mounts"); err != nil { if b, err = ioutil.ReadFile("/proc/self/mounts"); err != nil {
return err return err
} }
r := bytes.NewReader(b) rdr := bytes.NewReader(b)
scanner := bufio.NewScanner(r) scanner := bufio.NewScanner(rdr)
for scanner.Scan() { for scanner.Scan() {
fields := strings.Fields(scanner.Text()) fields := strings.Fields(scanner.Text())

View File

@ -24,8 +24,8 @@ func NewUnmountSystemDisksTask(devname string) phase.Task {
} }
} }
// RuntimeFunc returns the runtime function. // TaskFunc returns the runtime function.
func (task *UnmountSystemDisks) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { func (task *UnmountSystemDisks) TaskFunc(mode runtime.Mode) phase.TaskFunc {
switch mode { switch mode {
case runtime.Container: case runtime.Container:
return nil return nil
@ -34,7 +34,7 @@ func (task *UnmountSystemDisks) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc
} }
} }
func (task *UnmountSystemDisks) standard(args *phase.RuntimeArgs) (err error) { func (task *UnmountSystemDisks) standard(r runtime.Runtime) (err error) {
var mountpoints *mount.Points var mountpoints *mount.Points
mountpoints, err = owned.MountPointsForDevice(task.devname) mountpoints, err = owned.MountPointsForDevice(task.devname)

View File

@ -19,12 +19,12 @@ func NewVarDirectoriesTask() phase.Task {
return &VarDirectories{} return &VarDirectories{}
} }
// RuntimeFunc returns the runtime function. // TaskFunc returns the runtime function.
func (task *VarDirectories) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { func (task *VarDirectories) TaskFunc(mode runtime.Mode) phase.TaskFunc {
return task.runtime return task.runtime
} }
func (task *VarDirectories) runtime(args *phase.RuntimeArgs) (err error) { func (task *VarDirectories) runtime(r runtime.Runtime) (err error) {
for _, p := range []string{"/var/log/pods", "/var/lib/kubelet", "/var/run/lock"} { for _, p := range []string{"/var/log/pods", "/var/lib/kubelet", "/var/run/lock"} {
if err = os.MkdirAll(p, 0700); err != nil { if err = os.MkdirAll(p, 0700); err != nil {
return err return err

View File

@ -18,8 +18,8 @@ func NewSecurityTask() phase.Task {
return &Security{} return &Security{}
} }
// RuntimeFunc returns the runtime function. // TaskFunc returns the runtime function.
func (task *Security) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { func (task *Security) TaskFunc(mode runtime.Mode) phase.TaskFunc {
switch mode { switch mode {
case runtime.Container: case runtime.Container:
return nil return nil
@ -28,7 +28,7 @@ func (task *Security) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc {
} }
} }
func (task *Security) runtime(args *phase.RuntimeArgs) (err error) { func (task *Security) runtime(r runtime.Runtime) (err error) {
if err = kspp.EnforceKSPPKernelParameters(); err != nil { if err = kspp.EnforceKSPPKernelParameters(); err != nil {
return err return err
} }

View File

@ -15,6 +15,7 @@ import (
"github.com/talos-systems/talos/internal/pkg/runtime" "github.com/talos-systems/talos/internal/pkg/runtime"
"github.com/talos-systems/talos/pkg/config/machine" "github.com/talos-systems/talos/pkg/config/machine"
"github.com/talos-systems/talos/pkg/kubernetes" "github.com/talos-systems/talos/pkg/kubernetes"
"github.com/talos-systems/talos/pkg/retry"
) )
// LabelNodeAsMaster represents the LabelNodeAsMaster task. // LabelNodeAsMaster represents the LabelNodeAsMaster task.
@ -25,19 +26,19 @@ func NewLabelNodeAsMasterTask() phase.Task {
return &LabelNodeAsMaster{} return &LabelNodeAsMaster{}
} }
// RuntimeFunc returns the runtime function. // TaskFunc returns the runtime function.
func (task *LabelNodeAsMaster) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { func (task *LabelNodeAsMaster) TaskFunc(mode runtime.Mode) phase.TaskFunc {
return task.standard return task.standard
} }
func (task *LabelNodeAsMaster) standard(args *phase.RuntimeArgs) (err error) { func (task *LabelNodeAsMaster) standard(r runtime.Runtime) (err error) {
if args.Config().Machine().Type() == machine.Worker { if r.Config().Machine().Type() == machine.Worker {
return nil return nil
} }
endpoint := net.ParseIP(args.Config().Cluster().Endpoint()) endpoint := net.ParseIP(r.Config().Cluster().Endpoint())
h, err := kubernetes.NewTemporaryClientFromPKI(args.Config().Cluster().CA().Crt, args.Config().Cluster().CA().Key, endpoint.String(), "6443") h, err := kubernetes.NewTemporaryClientFromPKI(r.Config().Cluster().CA().Crt, r.Config().Cluster().CA().Key, endpoint.String(), "6443")
if err != nil { if err != nil {
return err return err
} }
@ -47,13 +48,17 @@ func (task *LabelNodeAsMaster) standard(args *phase.RuntimeArgs) (err error) {
return err return err
} }
for i := 0; i < 200; i++ { err = retry.Constant(10*time.Minute, retry.WithUnits(3*time.Second)).Retry(func() error {
if err = h.LabelNodeAsMaster(hostname); err == nil { if err = h.LabelNodeAsMaster(hostname); err != nil {
return nil return retry.ExpectedError(err)
} }
time.Sleep(3 * time.Second) return nil
})
if err != nil {
return errors.Wrap(err, "failed to label node as master")
} }
return errors.New("failed to label node as master") return nil
} }

View File

@ -20,22 +20,22 @@ func NewStartServicesTask() phase.Task {
return &StartServices{} return &StartServices{}
} }
// RuntimeFunc returns the runtime function. // TaskFunc returns the runtime function.
func (task *StartServices) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { func (task *StartServices) TaskFunc(mode runtime.Mode) phase.TaskFunc {
return task.standard return task.standard
} }
func (task *StartServices) standard(args *phase.RuntimeArgs) (err error) { func (task *StartServices) standard(r runtime.Runtime) (err error) {
task.loadSystemServices(args) task.loadSystemServices(r)
task.loadKubernetesServices(args) task.loadKubernetesServices(r)
system.Services(args.Config()).StartAll() system.Services(r.Config()).StartAll()
return nil return nil
} }
func (task *StartServices) loadSystemServices(args *phase.RuntimeArgs) { func (task *StartServices) loadSystemServices(r runtime.Runtime) {
svcs := system.Services(args.Config()) svcs := system.Services(r.Config())
// Start the services common to all nodes. // Start the services common to all nodes.
svcs.Load( svcs.Load(
&services.MachinedAPI{}, &services.MachinedAPI{},
@ -44,7 +44,9 @@ func (task *StartServices) loadSystemServices(args *phase.RuntimeArgs) {
&services.Networkd{}, &services.Networkd{},
) )
if args.Platform().Mode() != runtime.Container { if r.Platform().Mode() != runtime.Container {
// udevd-trigger is causing stalls/unresponsive stuff when running in local mode
// TODO: investigate root cause, but workaround for now is to skip it in container mode
svcs.Load( svcs.Load(
&services.NTPd{}, &services.NTPd{},
&services.Udevd{}, &services.Udevd{},
@ -54,7 +56,7 @@ func (task *StartServices) loadSystemServices(args *phase.RuntimeArgs) {
// Start the services common to all control plane nodes. // Start the services common to all control plane nodes.
switch args.Config().Machine().Type() { switch r.Config().Machine().Type() {
case machine.Bootstrap: case machine.Bootstrap:
fallthrough fallthrough
case machine.ControlPlane: case machine.ControlPlane:
@ -65,13 +67,13 @@ func (task *StartServices) loadSystemServices(args *phase.RuntimeArgs) {
} }
} }
func (task *StartServices) loadKubernetesServices(args *phase.RuntimeArgs) { func (task *StartServices) loadKubernetesServices(r runtime.Runtime) {
svcs := system.Services(args.Config()) svcs := system.Services(r.Config())
svcs.Load( svcs.Load(
&services.Kubelet{}, &services.Kubelet{},
) )
if args.Config().Machine().Type() == machine.Bootstrap { if r.Config().Machine().Type() == machine.Bootstrap {
svcs.Load( svcs.Load(
&services.Bootkube{}, &services.Bootkube{},
) )

View File

@ -19,14 +19,14 @@ func NewStartSystemContainerdTask() phase.Task {
return &StartSystemContainerd{} return &StartSystemContainerd{}
} }
// RuntimeFunc returns the runtime function. // TaskFunc returns the runtime function.
func (task *StartSystemContainerd) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { func (task *StartSystemContainerd) TaskFunc(mode runtime.Mode) phase.TaskFunc {
return task.standard return task.standard
} }
func (task *StartSystemContainerd) standard(args *phase.RuntimeArgs) (err error) { func (task *StartSystemContainerd) standard(r runtime.Runtime) (err error) {
system.Services(args.Config()).LoadAndStart(&services.SystemContainerd{}) system.Services(r.Config()).LoadAndStart(&services.SystemContainerd{})
system.Services(args.Config()).LoadAndStart(&services.SystemContainerd{}) system.Services(r.Config()).LoadAndStart(&services.SystemContainerd{})
return nil return nil
} }

View File

@ -21,9 +21,9 @@ func NewStopContainerdTask() phase.Task {
return &StopContainerd{} return &StopContainerd{}
} }
// RuntimeFunc returns the runtime function. // TaskFunc returns the runtime function.
func (task *StopContainerd) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { func (task *StopContainerd) TaskFunc(mode runtime.Mode) phase.TaskFunc {
return func(args *phase.RuntimeArgs) error { return func(r runtime.Runtime) error {
return task.standard() return task.standard()
} }
} }

View File

@ -24,17 +24,17 @@ func NewStopNonCrucialServicesTask() phase.Task {
return &StopNonCrucialServices{} return &StopNonCrucialServices{}
} }
// RuntimeFunc returns the runtime function. // TaskFunc returns the runtime function.
func (task *StopNonCrucialServices) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { func (task *StopNonCrucialServices) TaskFunc(mode runtime.Mode) phase.TaskFunc {
return task.standard return task.standard
} }
func (task *StopNonCrucialServices) standard(args *phase.RuntimeArgs) (err error) { func (task *StopNonCrucialServices) standard(r runtime.Runtime) (err error) {
ctx := namespaces.WithNamespace(context.Background(), "k8s.io") ctx := namespaces.WithNamespace(context.Background(), "k8s.io")
services := []string{"osd", "udevd", "networkd", "ntpd"} services := []string{"osd", "udevd", "networkd", "ntpd"}
if args.Config().Machine().Type() == machine.Bootstrap || args.Config().Machine().Type() == machine.ControlPlane { if r.Config().Machine().Type() == machine.Bootstrap || r.Config().Machine().Type() == machine.ControlPlane {
services = append(services, "trustd") services = append(services, "trustd", "proxyd")
} }
for _, service := range services { for _, service := range services {

View File

@ -18,9 +18,9 @@ func NewStopServicesTask() phase.Task {
return &StopServices{} return &StopServices{}
} }
// RuntimeFunc returns the runtime function. // TaskFunc returns the runtime function.
func (task *StopServices) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { func (task *StopServices) TaskFunc(mode runtime.Mode) phase.TaskFunc {
return func(args *phase.RuntimeArgs) error { return func(r runtime.Runtime) error {
return task.standard() return task.standard()
} }
} }

View File

@ -23,8 +23,8 @@ func NewHandlerTask() phase.Task {
return &Handler{} return &Handler{}
} }
// RuntimeFunc returns the runtime function. // TaskFunc returns the runtime function.
func (task *Handler) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { func (task *Handler) TaskFunc(mode runtime.Mode) phase.TaskFunc {
switch mode { switch mode {
case runtime.Container: case runtime.Container:
return task.container return task.container
@ -33,7 +33,7 @@ func (task *Handler) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc {
} }
} }
func (task *Handler) container(args *phase.RuntimeArgs) (err error) { func (task *Handler) container(r runtime.Runtime) (err error) {
termCh := make(chan os.Signal, 1) termCh := make(chan os.Signal, 1)
signal.Notify(termCh, syscall.SIGTERM) signal.Notify(termCh, syscall.SIGTERM)

View File

@ -21,12 +21,12 @@ func NewSysctlsTask() phase.Task {
return &Task{} return &Task{}
} }
// RuntimeFunc returns the runtime function. // TaskFunc returns the runtime function.
func (task *Task) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { func (task *Task) TaskFunc(mode runtime.Mode) phase.TaskFunc {
return task.runtime return task.runtime
} }
func (task *Task) runtime(args *phase.RuntimeArgs) error { func (task *Task) runtime(r runtime.Runtime) error {
var multiErr *multierror.Error var multiErr *multierror.Error
if err := sysctl.WriteSystemProperty(&sysctl.SystemProperty{Key: "net.ipv4.ip_forward", Value: "1"}); err != nil { if err := sysctl.WriteSystemProperty(&sysctl.SystemProperty{Key: "net.ipv4.ip_forward", Value: "1"}); err != nil {

View File

@ -29,13 +29,13 @@ func NewLeaveEtcdTask() phase.Task {
return &LeaveEtcd{} return &LeaveEtcd{}
} }
// RuntimeFunc returns the runtime function. // TaskFunc returns the runtime function.
func (task *LeaveEtcd) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { func (task *LeaveEtcd) TaskFunc(mode runtime.Mode) phase.TaskFunc {
return task.standard return task.standard
} }
func (task *LeaveEtcd) standard(args *phase.RuntimeArgs) (err error) { func (task *LeaveEtcd) standard(r runtime.Runtime) (err error) {
if args.Config().Machine().Type() == machine.Worker { if r.Config().Machine().Type() == machine.Worker {
return nil return nil
} }

View File

@ -32,12 +32,12 @@ func NewUpgradeTask(devname string, req *machineapi.UpgradeRequest) phase.Task {
} }
} }
// RuntimeFunc returns the runtime function. // TaskFunc returns the runtime function.
func (task *Upgrade) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { func (task *Upgrade) TaskFunc(mode runtime.Mode) phase.TaskFunc {
return task.standard return task.standard
} }
func (task *Upgrade) standard(args *phase.RuntimeArgs) (err error) { func (task *Upgrade) standard(r runtime.Runtime) (err error) {
// TODO(andrewrynhard): To handle cases when the newer version changes the // TODO(andrewrynhard): To handle cases when the newer version changes the
// platform name, this should be determined in the installer container. // platform name, this should be determined in the installer container.
var config *string var config *string
@ -45,7 +45,7 @@ func (task *Upgrade) standard(args *phase.RuntimeArgs) (err error) {
return errors.Errorf("no config option was found") return errors.Errorf("no config option was found")
} }
if err = install.Install(task.ref, task.devname, strings.ToLower(args.Platform().Name())); err != nil { if err = install.Install(task.ref, task.devname, strings.ToLower(r.Platform().Name())); err != nil {
return err return err
} }

View File

@ -8,7 +8,7 @@ import (
"github.com/talos-systems/talos/internal/pkg/mount" "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"
"github.com/talos-systems/talos/internal/pkg/mount/manager/owned" "github.com/talos-systems/talos/internal/pkg/mount/manager/owned"
"github.com/talos-systems/talos/internal/pkg/platform" "github.com/talos-systems/talos/internal/pkg/runtime"
"github.com/talos-systems/talos/pkg/config/machine" "github.com/talos-systems/talos/pkg/config/machine"
) )
@ -16,7 +16,7 @@ import (
type Cloud struct{} type Cloud struct{}
// Initialize implements the Initializer interface. // Initialize implements the Initializer interface.
func (c *Cloud) Initialize(platform platform.Platform, install machine.Install) (err error) { func (c *Cloud) Initialize(platform runtime.Platform, install machine.Install) (err error) {
var mountpoints *mount.Points var mountpoints *mount.Points
mountpoints, err = owned.MountPointsFromLabels() mountpoints, err = owned.MountPointsFromLabels()

View File

@ -5,7 +5,7 @@
package container package container
import ( import (
"github.com/talos-systems/talos/internal/pkg/platform" "github.com/talos-systems/talos/internal/pkg/runtime"
"github.com/talos-systems/talos/pkg/config/machine" "github.com/talos-systems/talos/pkg/config/machine"
) )
@ -13,6 +13,6 @@ import (
type Container struct{} type Container struct{}
// Initialize implements the Initializer interface. // Initialize implements the Initializer interface.
func (c *Container) Initialize(platform platform.Platform, install machine.Install) (err error) { func (c *Container) Initialize(platform runtime.Platform, install machine.Install) (err error) {
return nil return nil
} }

View File

@ -5,7 +5,6 @@
package initializer package initializer
import ( import (
"github.com/talos-systems/talos/internal/pkg/platform"
"github.com/talos-systems/talos/internal/pkg/runtime" "github.com/talos-systems/talos/internal/pkg/runtime"
"github.com/talos-systems/talos/internal/pkg/runtime/initializer/cloud" "github.com/talos-systems/talos/internal/pkg/runtime/initializer/cloud"
"github.com/talos-systems/talos/internal/pkg/runtime/initializer/container" "github.com/talos-systems/talos/internal/pkg/runtime/initializer/container"
@ -17,7 +16,7 @@ import (
// Initializer defines a process for initializing the system based on the // Initializer defines a process for initializing the system based on the
// environment it is in. // environment it is in.
type Initializer interface { type Initializer interface {
Initialize(platform.Platform, machine.Install) error Initialize(runtime.Platform, machine.Install) error
} }
// New initializes and returns and Initializer based on the runtime mode. // New initializes and returns and Initializer based on the runtime mode.

View File

@ -17,7 +17,7 @@ import (
"github.com/talos-systems/talos/internal/pkg/installer" "github.com/talos-systems/talos/internal/pkg/installer"
"github.com/talos-systems/talos/internal/pkg/kernel" "github.com/talos-systems/talos/internal/pkg/kernel"
"github.com/talos-systems/talos/internal/pkg/platform" "github.com/talos-systems/talos/internal/pkg/runtime"
"github.com/talos-systems/talos/pkg/blockdevice/probe" "github.com/talos-systems/talos/pkg/blockdevice/probe"
"github.com/talos-systems/talos/pkg/config/machine" "github.com/talos-systems/talos/pkg/config/machine"
"github.com/talos-systems/talos/pkg/constants" "github.com/talos-systems/talos/pkg/constants"
@ -28,7 +28,7 @@ import (
type Interactive struct{} type Interactive struct{}
// Initialize implements the Initializer interface. // Initialize implements the Initializer interface.
func (i *Interactive) Initialize(platform platform.Platform, install machine.Install) (err error) { func (i *Interactive) Initialize(platform runtime.Platform, install machine.Install) (err error) {
var dev *probe.ProbedBlockDevice var dev *probe.ProbedBlockDevice
dev, err = probe.GetDevWithFileSystemLabel(constants.ISOFilesystemLabel) dev, err = probe.GetDevWithFileSystemLabel(constants.ISOFilesystemLabel)

View File

@ -13,7 +13,7 @@ import (
"github.com/talos-systems/talos/internal/pkg/mount" "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"
"github.com/talos-systems/talos/internal/pkg/mount/manager/owned" "github.com/talos-systems/talos/internal/pkg/mount/manager/owned"
"github.com/talos-systems/talos/internal/pkg/platform" "github.com/talos-systems/talos/internal/pkg/runtime"
"github.com/talos-systems/talos/pkg/config/machine" "github.com/talos-systems/talos/pkg/config/machine"
) )
@ -22,7 +22,7 @@ import (
type Metal struct{} type Metal struct{}
// Initialize implements the Initializer interface. // Initialize implements the Initializer interface.
func (b *Metal) Initialize(platform platform.Platform, install machine.Install) (err error) { func (b *Metal) Initialize(platform runtime.Platform, install machine.Install) (err error) {
// Attempt to discover a previous installation // Attempt to discover a previous installation
// An err case should only happen if no partitions // An err case should only happen if no partitions
// with matching labels were found // with matching labels were found

View File

@ -0,0 +1,18 @@
/* 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 runtime
import (
"net"
)
// Platform is an interface describing a platform.
type Platform interface {
Name() string
Configuration() ([]byte, error)
Hostname() ([]byte, error)
Mode() Mode
ExternalIPs() ([]net.IP, error)
}

View File

@ -46,11 +46,6 @@ func (a *Azure) Configuration() ([]byte, error) {
return config.Download(AzureUserDataEndpoint, config.WithHeaders(map[string]string{"Metadata": "true"}), config.WithFormat("base64")) return config.Download(AzureUserDataEndpoint, config.WithHeaders(map[string]string{"Metadata": "true"}), config.WithFormat("base64"))
} }
// Mode implements the platform.Platform interface.
func (a *Azure) Mode() runtime.Mode {
return runtime.Cloud
}
// Hostname gets the hostname from the Azure metadata endpoint. // Hostname gets the hostname from the Azure metadata endpoint.
func (a *Azure) Hostname() (hostname []byte, err error) { func (a *Azure) Hostname() (hostname []byte, err error) {
var ( var (
@ -82,6 +77,11 @@ func (a *Azure) Hostname() (hostname []byte, err error) {
return ioutil.ReadAll(resp.Body) return ioutil.ReadAll(resp.Body)
} }
// Mode implements the platform.Platform interface.
func (a *Azure) Mode() runtime.Mode {
return runtime.Cloud
}
// ExternalIPs provides any external addresses assigned to the instance // ExternalIPs provides any external addresses assigned to the instance
func (a *Azure) ExternalIPs() (addrs []net.IP, err error) { func (a *Azure) ExternalIPs() (addrs []net.IP, err error) {
var ( var (

View File

@ -36,16 +36,16 @@ func (c *Container) Configuration() ([]byte, error) {
return decoded, nil return decoded, nil
} }
// Mode implements the platform.Platform interface.
func (c *Container) Mode() runtime.Mode {
return runtime.Container
}
// Hostname implements the platform.Platform interface. // Hostname implements the platform.Platform interface.
func (c *Container) Hostname() (hostname []byte, err error) { func (c *Container) Hostname() (hostname []byte, err error) {
return nil, nil return nil, nil
} }
// Mode implements the platform.Platform interface.
func (c *Container) Mode() runtime.Mode {
return runtime.Container
}
// ExternalIPs provides any external addresses assigned to the instance // ExternalIPs provides any external addresses assigned to the instance
func (c *Container) ExternalIPs() (addrs []net.IP, err error) { func (c *Container) ExternalIPs() (addrs []net.IP, err error) {
return addrs, err return addrs, err

View File

@ -37,16 +37,16 @@ func (g *GCP) Configuration() ([]byte, error) {
return config.Download(GCUserDataEndpoint, config.WithHeaders(map[string]string{"Metadata-Flavor": "Google"})) return config.Download(GCUserDataEndpoint, config.WithHeaders(map[string]string{"Metadata-Flavor": "Google"}))
} }
// Mode implements the platform.Platform interface.
func (g *GCP) Mode() runtime.Mode {
return runtime.Cloud
}
// Hostname implements the platform.Platform interface. // Hostname implements the platform.Platform interface.
func (g *GCP) Hostname() (hostname []byte, err error) { func (g *GCP) Hostname() (hostname []byte, err error) {
return nil, nil return nil, nil
} }
// Mode implements the platform.Platform interface.
func (g *GCP) Mode() runtime.Mode {
return runtime.Cloud
}
// ExternalIPs provides any external addresses assigned to the instance // ExternalIPs provides any external addresses assigned to the instance
func (g *GCP) ExternalIPs() (addrs []net.IP, err error) { func (g *GCP) ExternalIPs() (addrs []net.IP, err error) {
var ( var (

View File

@ -41,16 +41,16 @@ func (i *ISO) Configuration() ([]byte, error) {
return b, nil return b, nil
} }
// Mode implements the platform.Platform interface.
func (i *ISO) Mode() runtime.Mode {
return runtime.Interactive
}
// Hostname implements the platform.Platform interface. // Hostname implements the platform.Platform interface.
func (i *ISO) Hostname() (hostname []byte, err error) { func (i *ISO) Hostname() (hostname []byte, err error) {
return nil, nil return nil, nil
} }
// Mode implements the platform.Platform interface.
func (i *ISO) Mode() runtime.Mode {
return runtime.Interactive
}
// ExternalIPs provides any external addresses assigned to the instance // ExternalIPs provides any external addresses assigned to the instance
func (i *ISO) ExternalIPs() (addrs []net.IP, err error) { func (i *ISO) ExternalIPs() (addrs []net.IP, err error) {
return addrs, err return addrs, err

View File

@ -46,16 +46,16 @@ func (b *Metal) Configuration() ([]byte, error) {
} }
} }
// Mode implements the platform.Platform interface.
func (b *Metal) Mode() runtime.Mode {
return runtime.Metal
}
// Hostname implements the platform.Platform interface. // Hostname implements the platform.Platform interface.
func (b *Metal) Hostname() (hostname []byte, err error) { func (b *Metal) Hostname() (hostname []byte, err error) {
return nil, nil return nil, nil
} }
// Mode implements the platform.Platform interface.
func (b *Metal) Mode() runtime.Mode {
return runtime.Cloud
}
// ExternalIPs provides any external addresses assigned to the instance // ExternalIPs provides any external addresses assigned to the instance
func (b *Metal) ExternalIPs() (addrs []net.IP, err error) { func (b *Metal) ExternalIPs() (addrs []net.IP, err error) {
return addrs, err return addrs, err

View File

@ -31,7 +31,7 @@ func (p *Packet) Configuration() ([]byte, error) {
// Mode implements the platform.Platform interface. // Mode implements the platform.Platform interface.
func (p *Packet) Mode() runtime.Mode { func (p *Packet) Mode() runtime.Mode {
return runtime.Metal return runtime.Cloud
} }
// Hostname implements the platform.Platform interface. // Hostname implements the platform.Platform interface.

View File

@ -5,38 +5,27 @@
package platform package platform
import ( import (
"net"
"os" "os"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/talos-systems/talos/internal/pkg/kernel" "github.com/talos-systems/talos/internal/pkg/kernel"
"github.com/talos-systems/talos/internal/pkg/platform/aws"
"github.com/talos-systems/talos/internal/pkg/platform/azure"
"github.com/talos-systems/talos/internal/pkg/platform/container"
"github.com/talos-systems/talos/internal/pkg/platform/gcp"
"github.com/talos-systems/talos/internal/pkg/platform/iso"
"github.com/talos-systems/talos/internal/pkg/platform/metal"
"github.com/talos-systems/talos/internal/pkg/platform/packet"
"github.com/talos-systems/talos/internal/pkg/platform/vmware"
"github.com/talos-systems/talos/internal/pkg/runtime" "github.com/talos-systems/talos/internal/pkg/runtime"
"github.com/talos-systems/talos/internal/pkg/runtime/platform/aws"
"github.com/talos-systems/talos/internal/pkg/runtime/platform/azure"
"github.com/talos-systems/talos/internal/pkg/runtime/platform/container"
"github.com/talos-systems/talos/internal/pkg/runtime/platform/gcp"
"github.com/talos-systems/talos/internal/pkg/runtime/platform/iso"
"github.com/talos-systems/talos/internal/pkg/runtime/platform/metal"
"github.com/talos-systems/talos/internal/pkg/runtime/platform/packet"
"github.com/talos-systems/talos/internal/pkg/runtime/platform/vmware"
"github.com/talos-systems/talos/pkg/constants" "github.com/talos-systems/talos/pkg/constants"
) )
// Platform is an interface describing a platform.
type Platform interface {
Name() string
Configuration() ([]byte, error)
Mode() runtime.Mode
Hostname() ([]byte, error)
ExternalIPs() ([]net.IP, error)
}
// NewPlatform is a helper func for discovering the current platform. // NewPlatform is a helper func for discovering the current platform.
// //
// nolint: gocyclo // nolint: gocyclo
func NewPlatform() (p Platform, err error) { func NewPlatform() (p runtime.Platform, err error) {
var platform string var platform string
if p := kernel.ProcCmdline().Get(constants.KernelParamPlatform).First(); p != nil { if p := kernel.ProcCmdline().Get(constants.KernelParamPlatform).First(); p != nil {
platform = *p platform = *p

View File

@ -65,16 +65,16 @@ func (v *VMware) Configuration() ([]byte, error) {
return nil, nil return nil, nil
} }
// Mode implements the platform.Platform interface.
func (v *VMware) Mode() runtime.Mode {
return runtime.Cloud
}
// Hostname implements the platform.Platform interface. // Hostname implements the platform.Platform interface.
func (v *VMware) Hostname() (hostname []byte, err error) { func (v *VMware) Hostname() (hostname []byte, err error) {
return nil, nil return nil, nil
} }
// Mode implements the platform.Platform interface.
func (v *VMware) Mode() runtime.Mode {
return runtime.Cloud
}
// ExternalIPs provides any external addresses assigned to the instance // ExternalIPs provides any external addresses assigned to the instance
func (v *VMware) ExternalIPs() (addrs []net.IP, err error) { func (v *VMware) ExternalIPs() (addrs []net.IP, err error) {
return addrs, err return addrs, err

View File

@ -4,6 +4,10 @@
package runtime package runtime
import (
"github.com/talos-systems/talos/pkg/config"
)
// Mode is a runtime mode. // Mode is a runtime mode.
type Mode int type Mode int
@ -22,3 +26,33 @@ const (
func (m Mode) String() string { func (m Mode) String() string {
return [...]string{"Cloud", "Container", "Interactive", "Metal"}[m] return [...]string{"Cloud", "Container", "Interactive", "Metal"}[m]
} }
// Runtime defines the runtime parameters.
type Runtime interface {
Platform() Platform
Config() config.Configurator
}
// NewRuntime initializes and returns the runtime interface.
func NewRuntime(p Platform, c config.Configurator) Runtime {
return &DefaultRuntime{
p: p,
c: c,
}
}
// DefaultRuntime implements the Runtime interface.
type DefaultRuntime struct {
p Platform
c config.Configurator
}
// Platform implements the Runtime interface.
func (d *DefaultRuntime) Platform() Platform {
return d.p
}
// Config implements the Runtime interface.
func (d *DefaultRuntime) Config() config.Configurator {
return d.c
}