diff --git a/cmd/osctl/cmd/install_linux.go b/cmd/osctl/cmd/install_linux.go index 8e1cea09c..bda180412 100644 --- a/cmd/osctl/cmd/install_linux.go +++ b/cmd/osctl/cmd/install_linux.go @@ -14,7 +14,7 @@ import ( "github.com/talos-systems/talos/internal/pkg/installer" "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" "github.com/talos-systems/talos/pkg/config/types/v1alpha1" "github.com/talos-systems/talos/pkg/constants" diff --git a/internal/app/machined/internal/phase/acpi/acpi.go b/internal/app/machined/internal/phase/acpi/acpi.go index 4c9203396..84cd14a02 100644 --- a/internal/app/machined/internal/phase/acpi/acpi.go +++ b/internal/app/machined/internal/phase/acpi/acpi.go @@ -24,8 +24,8 @@ func NewHandlerTask() phase.Task { return &Handler{} } -// RuntimeFunc returns the runtime function. -func (task *Handler) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { +// TaskFunc returns the runtime function. +func (task *Handler) TaskFunc(mode runtime.Mode) phase.TaskFunc { switch mode { case runtime.Container: 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 { log.Printf("WARNING: power off events will be ignored: %+v", err) } diff --git a/internal/app/machined/internal/phase/config/config.go b/internal/app/machined/internal/phase/config/config.go index 483d1194b..4f00534da 100644 --- a/internal/app/machined/internal/phase/config/config.go +++ b/internal/app/machined/internal/phase/config/config.go @@ -20,15 +20,15 @@ func NewConfigTask() phase.Task { return &Task{} } -// RuntimeFunc returns the runtime function. -func (task *Task) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { +// TaskFunc returns the runtime function. +func (task *Task) TaskFunc(mode runtime.Mode) phase.TaskFunc { return task.standard } -func (task *Task) standard(args *phase.RuntimeArgs) (err error) { +func (task *Task) standard(r runtime.Runtime) (err error) { var b []byte - if b, err = args.Platform().Configuration(); err != nil { + if b, err = r.Platform().Configuration(); err != nil { return err } diff --git a/internal/app/machined/internal/phase/config/extra_devices.go b/internal/app/machined/internal/phase/config/extra_devices.go index fdc9f47be..fb8b67ef8 100644 --- a/internal/app/machined/internal/phase/config/extra_devices.go +++ b/internal/app/machined/internal/phase/config/extra_devices.go @@ -23,15 +23,15 @@ func NewExtraDevicesTask() phase.Task { return &ExtraDevices{} } -// RuntimeFunc returns the runtime function. -func (task *ExtraDevices) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { +// TaskFunc returns the runtime function. +func (task *ExtraDevices) TaskFunc(mode runtime.Mode) phase.TaskFunc { return task.runtime } -func (task *ExtraDevices) runtime(args *phase.RuntimeArgs) (err error) { +func (task *ExtraDevices) runtime(r runtime.Runtime) (err error) { 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 { devname := fmt.Sprintf("%s%d", extra.Device, i+1) mountpoints.Set(devname, mount.NewMountPoint(devname, part.MountPoint, "xfs", unix.MS_NOATIME, "")) diff --git a/internal/app/machined/internal/phase/config/extra_env_vars.go b/internal/app/machined/internal/phase/config/extra_env_vars.go index 25a958258..ed22c00cc 100644 --- a/internal/app/machined/internal/phase/config/extra_env_vars.go +++ b/internal/app/machined/internal/phase/config/extra_env_vars.go @@ -20,13 +20,13 @@ func NewExtraEnvVarsTask() phase.Task { return &ExtraEnvVars{} } -// RuntimeFunc returns the runtime function. -func (task *ExtraEnvVars) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { +// TaskFunc returns the runtime function. +func (task *ExtraEnvVars) TaskFunc(mode runtime.Mode) phase.TaskFunc { return task.runtime } -func (task *ExtraEnvVars) runtime(args *phase.RuntimeArgs) (err error) { - for key, val := range args.Config().Machine().Env() { +func (task *ExtraEnvVars) runtime(r runtime.Runtime) (err error) { + for key, val := range r.Config().Machine().Env() { if err = os.Setenv(key, val); err != nil { log.Printf("WARNING failed to set enivronment variable: %v", err) } diff --git a/internal/app/machined/internal/phase/config/extra_files.go b/internal/app/machined/internal/phase/config/extra_files.go index 7dee13a7c..a11e22c1f 100644 --- a/internal/app/machined/internal/phase/config/extra_files.go +++ b/internal/app/machined/internal/phase/config/extra_files.go @@ -23,15 +23,15 @@ func NewExtraFilesTask() phase.Task { return &ExtraFiles{} } -// RuntimeFunc returns the runtime function. -func (task *ExtraFiles) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { +// TaskFunc returns the runtime function. +func (task *ExtraFiles) TaskFunc(mode runtime.Mode) phase.TaskFunc { 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 - for _, f := range args.Config().Machine().Files() { + for _, f := range r.Config().Machine().Files() { p := filepath.Join("/var", f.Path) if err = os.MkdirAll(filepath.Dir(p), os.ModeDir); err != nil { result = multierror.Append(result, err) diff --git a/internal/app/machined/internal/phase/config/save_config.go b/internal/app/machined/internal/phase/config/save_config.go index a37c4d2fb..390d6df4f 100644 --- a/internal/app/machined/internal/phase/config/save_config.go +++ b/internal/app/machined/internal/phase/config/save_config.go @@ -21,15 +21,15 @@ func NewSaveConfigTask() phase.Task { return &SaveConfig{} } -// RuntimeFunc returns the runtime function. -func (task *SaveConfig) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { +// TaskFunc returns the runtime function. +func (task *SaveConfig) TaskFunc(mode runtime.Mode) phase.TaskFunc { return task.runtime } -func (task *SaveConfig) runtime(args *phase.RuntimeArgs) (err error) { - log.Printf("saving config %s to disk\n", args.Config().Version()) +func (task *SaveConfig) runtime(r runtime.Runtime) (err error) { + log.Printf("saving config %s to disk\n", r.Config().Version()) - s, err := args.Config().String() + s, err := r.Config().String() if err != nil { return err } diff --git a/internal/app/machined/internal/phase/disk/reset.go b/internal/app/machined/internal/phase/disk/reset.go index 8502f9956..5105882fc 100644 --- a/internal/app/machined/internal/phase/disk/reset.go +++ b/internal/app/machined/internal/phase/disk/reset.go @@ -26,9 +26,9 @@ func NewResetDiskTask(devname string) phase.Task { } } -// RuntimeFunc returns the runtime function. -func (task *ResetDisk) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { - return func(args *phase.RuntimeArgs) error { +// TaskFunc returns the runtime function. +func (task *ResetDisk) TaskFunc(mode runtime.Mode) phase.TaskFunc { + return func(r runtime.Runtime) error { return task.standard() } } diff --git a/internal/app/machined/internal/phase/kubernetes/cordon_and_drain.go b/internal/app/machined/internal/phase/kubernetes/cordon_and_drain.go index d9c4f2831..86cce60cd 100644 --- a/internal/app/machined/internal/phase/kubernetes/cordon_and_drain.go +++ b/internal/app/machined/internal/phase/kubernetes/cordon_and_drain.go @@ -21,9 +21,9 @@ func NewCordonAndDrainTask() phase.Task { return &CordonAndDrain{} } -// RuntimeFunc returns the runtime function. -func (task *CordonAndDrain) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { - return func(args *phase.RuntimeArgs) error { +// TaskFunc returns the runtime function. +func (task *CordonAndDrain) TaskFunc(mode runtime.Mode) phase.TaskFunc { + return func(r runtime.Runtime) error { return task.standard() } } diff --git a/internal/app/machined/internal/phase/kubernetes/tasks.go b/internal/app/machined/internal/phase/kubernetes/tasks.go index c31e1a985..8c56f0761 100644 --- a/internal/app/machined/internal/phase/kubernetes/tasks.go +++ b/internal/app/machined/internal/phase/kubernetes/tasks.go @@ -30,9 +30,9 @@ func NewKillKubernetesTasksTask() phase.Task { return &KillKubernetesTasks{} } -// RuntimeFunc returns the runtime function. -func (task *KillKubernetesTasks) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { - return func(args *phase.RuntimeArgs) error { +// TaskFunc returns the runtime function. +func (task *KillKubernetesTasks) TaskFunc(mode runtime.Mode) phase.TaskFunc { + return func(r runtime.Runtime) error { return task.standard() } } diff --git a/internal/app/machined/internal/phase/network/network.go b/internal/app/machined/internal/phase/network/network.go index 00c12586c..576084dd5 100644 --- a/internal/app/machined/internal/phase/network/network.go +++ b/internal/app/machined/internal/phase/network/network.go @@ -23,8 +23,8 @@ func NewUserDefinedNetworkTask() phase.Task { return &UserDefinedNetwork{} } -// RuntimeFunc returns the runtime function. -func (task *UserDefinedNetwork) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { +// TaskFunc returns the runtime function. +func (task *UserDefinedNetwork) TaskFunc(mode runtime.Mode) phase.TaskFunc { switch mode { case runtime.Container: return nil @@ -34,7 +34,7 @@ func (task *UserDefinedNetwork) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc } // nolint: gocyclo -func (task *UserDefinedNetwork) runtime(args *phase.RuntimeArgs) (err error) { +func (task *UserDefinedNetwork) runtime(r runtime.Runtime) (err error) { nwd, err := networkd.New() if err != nil { return err diff --git a/internal/app/machined/internal/phase/phase.go b/internal/app/machined/internal/phase/phase.go index c36e9859f..61f842ef2 100644 --- a/internal/app/machined/internal/phase/phase.go +++ b/internal/app/machined/internal/phase/phase.go @@ -13,24 +13,24 @@ import ( "github.com/pkg/errors" "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/platform" "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 { - platform platform.Platform + platform runtime.Platform 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. -type RuntimeFunc func(*RuntimeArgs) error +type TaskFunc func(runtime.Runtime) error // Task represents a task within a Phase. type Task interface { - RuntimeFunc(runtime.Mode) RuntimeFunc + TaskFunc(runtime.Mode) TaskFunc } // Phase represents a phase in the boot process. @@ -41,8 +41,8 @@ type Phase struct { // Runner represents a management layer for phases. type Runner struct { - phases []*Phase - args *RuntimeArgs + phases []*Phase + runtime runtime.Runtime } // NewRunner initializes and returns a Runner. @@ -52,8 +52,7 @@ func NewRunner(config config.Configurator) (*Runner, error) { return nil, err } - mode := platform.Mode() - switch mode { + switch platform.Mode() { case runtime.Metal: fallthrough case runtime.Cloud: @@ -64,17 +63,14 @@ func NewRunner(config config.Configurator) (*Runner, error) { } runner := &Runner{ - args: &RuntimeArgs{ - platform: platform, - config: config, - }, + runtime: runtime.NewRuntime(platform, config), } return runner, nil } // Platform returns the platform. -func (r *RuntimeArgs) Platform() platform.Platform { +func (r *RuntimeArgs) Platform() runtime.Platform { return r.platform } @@ -139,13 +135,13 @@ func (r *Runner) runTask(task Task, errCh chan<- error) { } }() - var f RuntimeFunc - if f = task.RuntimeFunc(r.args.Platform().Mode()); f == nil { + var f TaskFunc + if f = task.TaskFunc(r.runtime.Platform().Mode()); f == nil { // A task is not defined for this runtime mode. return } - err = f(r.args) + err = f(r.runtime) } // Add adds a phase to a Runner. diff --git a/internal/app/machined/internal/phase/phase_test.go b/internal/app/machined/internal/phase/phase_test.go index 151814ae0..4a994e858 100644 --- a/internal/app/machined/internal/phase/phase_test.go +++ b/internal/app/machined/internal/phase/phase_test.go @@ -26,22 +26,22 @@ type regularTask struct { errCh <-chan error } -func (t *regularTask) RuntimeFunc(runtime.Mode) phase.RuntimeFunc { - return func(*phase.RuntimeArgs) error { +func (t *regularTask) TaskFunc(runtime.Mode) phase.TaskFunc { + return func(runtime.Runtime) error { return <-t.errCh } } type nilTask struct{} -func (t *nilTask) RuntimeFunc(runtime.Mode) phase.RuntimeFunc { +func (t *nilTask) TaskFunc(runtime.Mode) phase.TaskFunc { return nil } type panicTask struct{} -func (t *panicTask) RuntimeFunc(runtime.Mode) phase.RuntimeFunc { - return func(*phase.RuntimeArgs) error { +func (t *panicTask) TaskFunc(runtime.Mode) phase.TaskFunc { + return func(runtime.Runtime) error { panic("in task") } } diff --git a/internal/app/machined/internal/phase/platform/platform.go b/internal/app/machined/internal/phase/platform/platform.go index a2f6b6a5c..08eb33ebb 100644 --- a/internal/app/machined/internal/phase/platform/platform.go +++ b/internal/app/machined/internal/phase/platform/platform.go @@ -18,31 +18,31 @@ func NewPlatformTask() phase.Task { return &Platform{} } -// RuntimeFunc returns the runtime function. -func (task *Platform) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { +// TaskFunc returns the runtime function. +func (task *Platform) TaskFunc(mode runtime.Mode) phase.TaskFunc { return task.runtime } -func (task *Platform) runtime(args *phase.RuntimeArgs) (err error) { - i, err := initializer.New(args.Platform().Mode()) +func (task *Platform) runtime(r runtime.Runtime) (err error) { + i, err := initializer.New(r.Platform().Mode()) if err != nil { 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 } - hostname, err := args.Platform().Hostname() + hostname, err := r.Platform().Hostname() if err != nil { return err } 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 { return err } @@ -52,8 +52,8 @@ func (task *Platform) runtime(args *phase.RuntimeArgs) (err error) { sans = append(sans, addr.String()) } - args.Config().Machine().Security().SetCertSANs(sans) - args.Config().Cluster().SetCertSANs(sans) + r.Config().Machine().Security().SetCertSANs(sans) + r.Config().Cluster().SetCertSANs(sans) return nil } diff --git a/internal/app/machined/internal/phase/rootfs/check_install.go b/internal/app/machined/internal/phase/rootfs/check_install.go index 04644489f..5f4d24aeb 100644 --- a/internal/app/machined/internal/phase/rootfs/check_install.go +++ b/internal/app/machined/internal/phase/rootfs/check_install.go @@ -21,8 +21,8 @@ func NewCheckInstallTask() phase.Task { return &CheckInstall{} } -// RuntimeFunc returns the runtime function. -func (task *CheckInstall) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { +// TaskFunc returns the runtime function. +func (task *CheckInstall) TaskFunc(mode runtime.Mode) phase.TaskFunc { switch mode { case runtime.Container: 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")) return err } diff --git a/internal/app/machined/internal/phase/rootfs/hostname.go b/internal/app/machined/internal/phase/rootfs/hostname.go index a0d69f73f..02fbfb4d4 100644 --- a/internal/app/machined/internal/phase/rootfs/hostname.go +++ b/internal/app/machined/internal/phase/rootfs/hostname.go @@ -22,8 +22,8 @@ func NewHostnameTask() phase.Task { return &Hostname{} } -// RuntimeFunc returns the runtime function. -func (task *Hostname) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { +// TaskFunc returns the runtime function. +func (task *Hostname) TaskFunc(mode runtime.Mode) phase.TaskFunc { switch mode { case runtime.Container: 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. // Priority is: // 1. Config (explicitly defined by the user) @@ -44,21 +44,21 @@ func (task *Hostname) runtime(args *phase.RuntimeArgs) (err error) { var platformHostname []byte - platformHostname, err = args.Platform().Hostname() + platformHostname, err = r.Platform().Hostname() if err != nil { return err } - configHostname := args.Config().Machine().Network().Hostname() + configHostname := r.Config().Machine().Network().Hostname() switch { case configHostname != "": log.Printf("using hostname from config: %s\n", configHostname) 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) 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)) // 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) } //nolint: wsl - return etc.Hosts(args.Config().Machine().Network().Hostname()) + return etc.Hosts(r.Config().Machine().Network().Hostname()) } diff --git a/internal/app/machined/internal/phase/rootfs/mount_bpffs.go b/internal/app/machined/internal/phase/rootfs/mount_bpffs.go index 5660f6766..8b17b7882 100644 --- a/internal/app/machined/internal/phase/rootfs/mount_bpffs.go +++ b/internal/app/machined/internal/phase/rootfs/mount_bpffs.go @@ -20,8 +20,8 @@ func NewMountBPFFSTask() phase.Task { return &MountBPFFS{} } -// RuntimeFunc returns the runtime function. -func (task *MountBPFFS) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { +// TaskFunc returns the runtime function. +func (task *MountBPFFS) TaskFunc(mode runtime.Mode) phase.TaskFunc { switch mode { case runtime.Container: 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 mountpoints, err = bpffs.MountPoints() diff --git a/internal/app/machined/internal/phase/rootfs/mount_cgroups.go b/internal/app/machined/internal/phase/rootfs/mount_cgroups.go index 9445b6d37..79c33e761 100644 --- a/internal/app/machined/internal/phase/rootfs/mount_cgroups.go +++ b/internal/app/machined/internal/phase/rootfs/mount_cgroups.go @@ -35,8 +35,8 @@ func NewMountCgroupsTask() phase.Task { return &MountCgroups{} } -// RuntimeFunc returns the runtime function. -func (task *MountCgroups) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { +// TaskFunc returns the runtime function. +func (task *MountCgroups) TaskFunc(mode runtime.Mode) phase.TaskFunc { switch mode { case runtime.Container: 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 mountpoints, err = cgroups.MountPoints() diff --git a/internal/app/machined/internal/phase/rootfs/mount_overlays.go b/internal/app/machined/internal/phase/rootfs/mount_overlays.go index 2960c10e7..5960b73f2 100644 --- a/internal/app/machined/internal/phase/rootfs/mount_overlays.go +++ b/internal/app/machined/internal/phase/rootfs/mount_overlays.go @@ -20,8 +20,8 @@ func NewMountOverlayTask() phase.Task { return &MountOverlay{} } -// RuntimeFunc returns the runtime function. -func (task *MountOverlay) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { +// TaskFunc returns the runtime function. +func (task *MountOverlay) TaskFunc(mode runtime.Mode) phase.TaskFunc { switch mode { case runtime.Container: 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 mountpoints, err = overlay.MountPoints() diff --git a/internal/app/machined/internal/phase/rootfs/mount_shared.go b/internal/app/machined/internal/phase/rootfs/mount_shared.go index 63f28725c..594cc6f5d 100644 --- a/internal/app/machined/internal/phase/rootfs/mount_shared.go +++ b/internal/app/machined/internal/phase/rootfs/mount_shared.go @@ -19,8 +19,8 @@ func NewMountSharedTask() phase.Task { return &MountShared{} } -// RuntimeFunc returns the runtime function. -func (task *MountShared) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { +// TaskFunc returns the runtime function. +func (task *MountShared) TaskFunc(mode runtime.Mode) phase.TaskFunc { switch mode { case runtime.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"} for _, t := range targets { if err = unix.Mount("", t, "", unix.MS_SHARED, ""); err != nil { diff --git a/internal/app/machined/internal/phase/rootfs/mount_sub_devices.go b/internal/app/machined/internal/phase/rootfs/mount_sub_devices.go index 6e0cd4972..f48a2b84b 100644 --- a/internal/app/machined/internal/phase/rootfs/mount_sub_devices.go +++ b/internal/app/machined/internal/phase/rootfs/mount_sub_devices.go @@ -22,8 +22,8 @@ func NewMountSubDevicesTask() phase.Task { return &MountSubDevices{} } -// RuntimeFunc returns the runtime function. -func (task *MountSubDevices) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { +// TaskFunc returns the runtime function. +func (task *MountSubDevices) TaskFunc(mode runtime.Mode) phase.TaskFunc { switch mode { case runtime.Container: 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 mountpoints, err = virtual.SubMountPoints() diff --git a/internal/app/machined/internal/phase/rootfs/network_configuration.go b/internal/app/machined/internal/phase/rootfs/network_configuration.go index 60ffd28cc..fd43c0ad1 100644 --- a/internal/app/machined/internal/phase/rootfs/network_configuration.go +++ b/internal/app/machined/internal/phase/rootfs/network_configuration.go @@ -18,8 +18,8 @@ func NewNetworkConfigurationTask() phase.Task { return &NetworkConfiguration{} } -// RuntimeFunc returns the runtime function. -func (task *NetworkConfiguration) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { +// TaskFunc returns the runtime function. +func (task *NetworkConfiguration) TaskFunc(mode runtime.Mode) phase.TaskFunc { switch mode { case runtime.Container: 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. if err = etc.ResolvConf(); err != nil { return err diff --git a/internal/app/machined/internal/phase/rootfs/os_release.go b/internal/app/machined/internal/phase/rootfs/os_release.go index e40dfdb6b..82aa9e630 100644 --- a/internal/app/machined/internal/phase/rootfs/os_release.go +++ b/internal/app/machined/internal/phase/rootfs/os_release.go @@ -18,12 +18,12 @@ func NewOSReleaseTask() phase.Task { return &OSRelease{} } -// RuntimeFunc returns the runtime function. -func (task *OSRelease) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { +// TaskFunc returns the runtime function. +func (task *OSRelease) TaskFunc(mode runtime.Mode) phase.TaskFunc { 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. return etc.OSRelease() } diff --git a/internal/app/machined/internal/phase/rootfs/system_directory.go b/internal/app/machined/internal/phase/rootfs/system_directory.go index 9c46898a0..852c4f144 100644 --- a/internal/app/machined/internal/phase/rootfs/system_directory.go +++ b/internal/app/machined/internal/phase/rootfs/system_directory.go @@ -21,12 +21,12 @@ func NewSystemDirectoryTask() phase.Task { return &SystemDirectory{} } -// RuntimeFunc returns the runtime function. -func (task *SystemDirectory) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { +// TaskFunc returns the runtime function. +func (task *SystemDirectory) TaskFunc(mode runtime.Mode) phase.TaskFunc { 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"} { if err = os.MkdirAll(filepath.Join(constants.SystemRunPath, p), 0700); err != nil { return err diff --git a/internal/app/machined/internal/phase/rootfs/unmount_overlays.go b/internal/app/machined/internal/phase/rootfs/unmount_overlays.go index 6a5d4ad18..5c569dc4a 100644 --- a/internal/app/machined/internal/phase/rootfs/unmount_overlays.go +++ b/internal/app/machined/internal/phase/rootfs/unmount_overlays.go @@ -20,8 +20,8 @@ func NewUnmountOverlayTask() phase.Task { return &UnmountOverlay{} } -// RuntimeFunc returns the runtime function. -func (task *UnmountOverlay) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { +// TaskFunc returns the runtime function. +func (task *UnmountOverlay) TaskFunc(mode runtime.Mode) phase.TaskFunc { switch mode { case runtime.Container: 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 mountpoints, err = overlay.MountPoints() diff --git a/internal/app/machined/internal/phase/rootfs/unmount_pod_mounts.go b/internal/app/machined/internal/phase/rootfs/unmount_pod_mounts.go index 02c91e477..9dd912a87 100644 --- a/internal/app/machined/internal/phase/rootfs/unmount_pod_mounts.go +++ b/internal/app/machined/internal/phase/rootfs/unmount_pod_mounts.go @@ -27,8 +27,8 @@ func NewUnmountPodMountsTask() phase.Task { return &UnmountPodMounts{} } -// RuntimeFunc returns the runtime function. -func (task *UnmountPodMounts) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { +// TaskFunc returns the runtime function. +func (task *UnmountPodMounts) TaskFunc(mode runtime.Mode) phase.TaskFunc { switch mode { case runtime.Container: 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 if b, err = ioutil.ReadFile("/proc/self/mounts"); err != nil { return err } - r := bytes.NewReader(b) + rdr := bytes.NewReader(b) - scanner := bufio.NewScanner(r) + scanner := bufio.NewScanner(rdr) for scanner.Scan() { fields := strings.Fields(scanner.Text()) diff --git a/internal/app/machined/internal/phase/rootfs/unmount_system_disks.go b/internal/app/machined/internal/phase/rootfs/unmount_system_disks.go index f8206f741..2c54bcfe5 100644 --- a/internal/app/machined/internal/phase/rootfs/unmount_system_disks.go +++ b/internal/app/machined/internal/phase/rootfs/unmount_system_disks.go @@ -24,8 +24,8 @@ func NewUnmountSystemDisksTask(devname string) phase.Task { } } -// RuntimeFunc returns the runtime function. -func (task *UnmountSystemDisks) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { +// TaskFunc returns the runtime function. +func (task *UnmountSystemDisks) TaskFunc(mode runtime.Mode) phase.TaskFunc { switch mode { case runtime.Container: 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 mountpoints, err = owned.MountPointsForDevice(task.devname) diff --git a/internal/app/machined/internal/phase/rootfs/var_directories.go b/internal/app/machined/internal/phase/rootfs/var_directories.go index 79ca68f28..b9912c795 100644 --- a/internal/app/machined/internal/phase/rootfs/var_directories.go +++ b/internal/app/machined/internal/phase/rootfs/var_directories.go @@ -19,12 +19,12 @@ func NewVarDirectoriesTask() phase.Task { return &VarDirectories{} } -// RuntimeFunc returns the runtime function. -func (task *VarDirectories) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { +// TaskFunc returns the runtime function. +func (task *VarDirectories) TaskFunc(mode runtime.Mode) phase.TaskFunc { 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"} { if err = os.MkdirAll(p, 0700); err != nil { return err diff --git a/internal/app/machined/internal/phase/security/security.go b/internal/app/machined/internal/phase/security/security.go index 4629e11e2..21708aef4 100644 --- a/internal/app/machined/internal/phase/security/security.go +++ b/internal/app/machined/internal/phase/security/security.go @@ -18,8 +18,8 @@ func NewSecurityTask() phase.Task { return &Security{} } -// RuntimeFunc returns the runtime function. -func (task *Security) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { +// TaskFunc returns the runtime function. +func (task *Security) TaskFunc(mode runtime.Mode) phase.TaskFunc { switch mode { case runtime.Container: 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 { return err } diff --git a/internal/app/machined/internal/phase/services/post_boot.go b/internal/app/machined/internal/phase/services/post_boot.go index d92f0aefc..11db14625 100644 --- a/internal/app/machined/internal/phase/services/post_boot.go +++ b/internal/app/machined/internal/phase/services/post_boot.go @@ -15,6 +15,7 @@ import ( "github.com/talos-systems/talos/internal/pkg/runtime" "github.com/talos-systems/talos/pkg/config/machine" "github.com/talos-systems/talos/pkg/kubernetes" + "github.com/talos-systems/talos/pkg/retry" ) // LabelNodeAsMaster represents the LabelNodeAsMaster task. @@ -25,19 +26,19 @@ func NewLabelNodeAsMasterTask() phase.Task { return &LabelNodeAsMaster{} } -// RuntimeFunc returns the runtime function. -func (task *LabelNodeAsMaster) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { +// TaskFunc returns the runtime function. +func (task *LabelNodeAsMaster) TaskFunc(mode runtime.Mode) phase.TaskFunc { return task.standard } -func (task *LabelNodeAsMaster) standard(args *phase.RuntimeArgs) (err error) { - if args.Config().Machine().Type() == machine.Worker { +func (task *LabelNodeAsMaster) standard(r runtime.Runtime) (err error) { + if r.Config().Machine().Type() == machine.Worker { 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 { return err } @@ -47,13 +48,17 @@ func (task *LabelNodeAsMaster) standard(args *phase.RuntimeArgs) (err error) { return err } - for i := 0; i < 200; i++ { - if err = h.LabelNodeAsMaster(hostname); err == nil { - return nil + err = retry.Constant(10*time.Minute, retry.WithUnits(3*time.Second)).Retry(func() error { + if err = h.LabelNodeAsMaster(hostname); err != 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 } diff --git a/internal/app/machined/internal/phase/services/start_services.go b/internal/app/machined/internal/phase/services/start_services.go index 33ac60a20..43e77d860 100644 --- a/internal/app/machined/internal/phase/services/start_services.go +++ b/internal/app/machined/internal/phase/services/start_services.go @@ -20,22 +20,22 @@ func NewStartServicesTask() phase.Task { return &StartServices{} } -// RuntimeFunc returns the runtime function. -func (task *StartServices) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { +// TaskFunc returns the runtime function. +func (task *StartServices) TaskFunc(mode runtime.Mode) phase.TaskFunc { return task.standard } -func (task *StartServices) standard(args *phase.RuntimeArgs) (err error) { - task.loadSystemServices(args) - task.loadKubernetesServices(args) +func (task *StartServices) standard(r runtime.Runtime) (err error) { + task.loadSystemServices(r) + task.loadKubernetesServices(r) - system.Services(args.Config()).StartAll() + system.Services(r.Config()).StartAll() return nil } -func (task *StartServices) loadSystemServices(args *phase.RuntimeArgs) { - svcs := system.Services(args.Config()) +func (task *StartServices) loadSystemServices(r runtime.Runtime) { + svcs := system.Services(r.Config()) // Start the services common to all nodes. svcs.Load( &services.MachinedAPI{}, @@ -44,7 +44,9 @@ func (task *StartServices) loadSystemServices(args *phase.RuntimeArgs) { &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( &services.NTPd{}, &services.Udevd{}, @@ -54,7 +56,7 @@ func (task *StartServices) loadSystemServices(args *phase.RuntimeArgs) { // Start the services common to all control plane nodes. - switch args.Config().Machine().Type() { + switch r.Config().Machine().Type() { case machine.Bootstrap: fallthrough case machine.ControlPlane: @@ -65,13 +67,13 @@ func (task *StartServices) loadSystemServices(args *phase.RuntimeArgs) { } } -func (task *StartServices) loadKubernetesServices(args *phase.RuntimeArgs) { - svcs := system.Services(args.Config()) +func (task *StartServices) loadKubernetesServices(r runtime.Runtime) { + svcs := system.Services(r.Config()) svcs.Load( &services.Kubelet{}, ) - if args.Config().Machine().Type() == machine.Bootstrap { + if r.Config().Machine().Type() == machine.Bootstrap { svcs.Load( &services.Bootkube{}, ) diff --git a/internal/app/machined/internal/phase/services/start_system_containerd.go b/internal/app/machined/internal/phase/services/start_system_containerd.go index ccb66b26a..52959028b 100644 --- a/internal/app/machined/internal/phase/services/start_system_containerd.go +++ b/internal/app/machined/internal/phase/services/start_system_containerd.go @@ -19,14 +19,14 @@ func NewStartSystemContainerdTask() phase.Task { return &StartSystemContainerd{} } -// RuntimeFunc returns the runtime function. -func (task *StartSystemContainerd) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { +// TaskFunc returns the runtime function. +func (task *StartSystemContainerd) TaskFunc(mode runtime.Mode) phase.TaskFunc { return task.standard } -func (task *StartSystemContainerd) standard(args *phase.RuntimeArgs) (err error) { - system.Services(args.Config()).LoadAndStart(&services.SystemContainerd{}) - system.Services(args.Config()).LoadAndStart(&services.SystemContainerd{}) +func (task *StartSystemContainerd) standard(r runtime.Runtime) (err error) { + system.Services(r.Config()).LoadAndStart(&services.SystemContainerd{}) + system.Services(r.Config()).LoadAndStart(&services.SystemContainerd{}) return nil } diff --git a/internal/app/machined/internal/phase/services/stop_containerd.go b/internal/app/machined/internal/phase/services/stop_containerd.go index 70754e6df..096d9983e 100644 --- a/internal/app/machined/internal/phase/services/stop_containerd.go +++ b/internal/app/machined/internal/phase/services/stop_containerd.go @@ -21,9 +21,9 @@ func NewStopContainerdTask() phase.Task { return &StopContainerd{} } -// RuntimeFunc returns the runtime function. -func (task *StopContainerd) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { - return func(args *phase.RuntimeArgs) error { +// TaskFunc returns the runtime function. +func (task *StopContainerd) TaskFunc(mode runtime.Mode) phase.TaskFunc { + return func(r runtime.Runtime) error { return task.standard() } } diff --git a/internal/app/machined/internal/phase/services/stop_non_crucial_services.go b/internal/app/machined/internal/phase/services/stop_non_crucial_services.go index cfa013b2e..9f64fa553 100644 --- a/internal/app/machined/internal/phase/services/stop_non_crucial_services.go +++ b/internal/app/machined/internal/phase/services/stop_non_crucial_services.go @@ -24,17 +24,17 @@ func NewStopNonCrucialServicesTask() phase.Task { return &StopNonCrucialServices{} } -// RuntimeFunc returns the runtime function. -func (task *StopNonCrucialServices) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { +// TaskFunc returns the runtime function. +func (task *StopNonCrucialServices) TaskFunc(mode runtime.Mode) phase.TaskFunc { 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") services := []string{"osd", "udevd", "networkd", "ntpd"} - if args.Config().Machine().Type() == machine.Bootstrap || args.Config().Machine().Type() == machine.ControlPlane { - services = append(services, "trustd") + if r.Config().Machine().Type() == machine.Bootstrap || r.Config().Machine().Type() == machine.ControlPlane { + services = append(services, "trustd", "proxyd") } for _, service := range services { diff --git a/internal/app/machined/internal/phase/services/stop_services.go b/internal/app/machined/internal/phase/services/stop_services.go index 4e7bc03e3..78215a6f8 100644 --- a/internal/app/machined/internal/phase/services/stop_services.go +++ b/internal/app/machined/internal/phase/services/stop_services.go @@ -18,9 +18,9 @@ func NewStopServicesTask() phase.Task { return &StopServices{} } -// RuntimeFunc returns the runtime function. -func (task *StopServices) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { - return func(args *phase.RuntimeArgs) error { +// TaskFunc returns the runtime function. +func (task *StopServices) TaskFunc(mode runtime.Mode) phase.TaskFunc { + return func(r runtime.Runtime) error { return task.standard() } } diff --git a/internal/app/machined/internal/phase/signal/signal.go b/internal/app/machined/internal/phase/signal/signal.go index 7d91c922c..018003d52 100644 --- a/internal/app/machined/internal/phase/signal/signal.go +++ b/internal/app/machined/internal/phase/signal/signal.go @@ -23,8 +23,8 @@ func NewHandlerTask() phase.Task { return &Handler{} } -// RuntimeFunc returns the runtime function. -func (task *Handler) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { +// TaskFunc returns the runtime function. +func (task *Handler) TaskFunc(mode runtime.Mode) phase.TaskFunc { switch mode { case runtime.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) signal.Notify(termCh, syscall.SIGTERM) diff --git a/internal/app/machined/internal/phase/sysctls/sysctls.go b/internal/app/machined/internal/phase/sysctls/sysctls.go index 4a66424ec..ee650fbbb 100644 --- a/internal/app/machined/internal/phase/sysctls/sysctls.go +++ b/internal/app/machined/internal/phase/sysctls/sysctls.go @@ -21,12 +21,12 @@ func NewSysctlsTask() phase.Task { return &Task{} } -// RuntimeFunc returns the runtime function. -func (task *Task) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { +// TaskFunc returns the runtime function. +func (task *Task) TaskFunc(mode runtime.Mode) phase.TaskFunc { return task.runtime } -func (task *Task) runtime(args *phase.RuntimeArgs) error { +func (task *Task) runtime(r runtime.Runtime) error { var multiErr *multierror.Error if err := sysctl.WriteSystemProperty(&sysctl.SystemProperty{Key: "net.ipv4.ip_forward", Value: "1"}); err != nil { diff --git a/internal/app/machined/internal/phase/upgrade/leave_etcd.go b/internal/app/machined/internal/phase/upgrade/leave_etcd.go index 48a4bb8db..9e815d340 100644 --- a/internal/app/machined/internal/phase/upgrade/leave_etcd.go +++ b/internal/app/machined/internal/phase/upgrade/leave_etcd.go @@ -29,13 +29,13 @@ func NewLeaveEtcdTask() phase.Task { return &LeaveEtcd{} } -// RuntimeFunc returns the runtime function. -func (task *LeaveEtcd) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { +// TaskFunc returns the runtime function. +func (task *LeaveEtcd) TaskFunc(mode runtime.Mode) phase.TaskFunc { return task.standard } -func (task *LeaveEtcd) standard(args *phase.RuntimeArgs) (err error) { - if args.Config().Machine().Type() == machine.Worker { +func (task *LeaveEtcd) standard(r runtime.Runtime) (err error) { + if r.Config().Machine().Type() == machine.Worker { return nil } diff --git a/internal/app/machined/internal/phase/upgrade/upgrade.go b/internal/app/machined/internal/phase/upgrade/upgrade.go index 9c8803924..1d5215cf9 100644 --- a/internal/app/machined/internal/phase/upgrade/upgrade.go +++ b/internal/app/machined/internal/phase/upgrade/upgrade.go @@ -32,12 +32,12 @@ func NewUpgradeTask(devname string, req *machineapi.UpgradeRequest) phase.Task { } } -// RuntimeFunc returns the runtime function. -func (task *Upgrade) RuntimeFunc(mode runtime.Mode) phase.RuntimeFunc { +// TaskFunc returns the runtime function. +func (task *Upgrade) TaskFunc(mode runtime.Mode) phase.TaskFunc { 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 // platform name, this should be determined in the installer container. var config *string @@ -45,7 +45,7 @@ func (task *Upgrade) standard(args *phase.RuntimeArgs) (err error) { 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 } diff --git a/internal/pkg/runtime/initializer/cloud/cloud.go b/internal/pkg/runtime/initializer/cloud/cloud.go index 8584327cc..e879f4b6f 100644 --- a/internal/pkg/runtime/initializer/cloud/cloud.go +++ b/internal/pkg/runtime/initializer/cloud/cloud.go @@ -8,7 +8,7 @@ import ( "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/platform" + "github.com/talos-systems/talos/internal/pkg/runtime" "github.com/talos-systems/talos/pkg/config/machine" ) @@ -16,7 +16,7 @@ import ( type Cloud struct{} // 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 mountpoints, err = owned.MountPointsFromLabels() diff --git a/internal/pkg/runtime/initializer/container/container.go b/internal/pkg/runtime/initializer/container/container.go index 345724442..982072422 100644 --- a/internal/pkg/runtime/initializer/container/container.go +++ b/internal/pkg/runtime/initializer/container/container.go @@ -5,7 +5,7 @@ package container 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" ) @@ -13,6 +13,6 @@ import ( type Container struct{} // 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 } diff --git a/internal/pkg/runtime/initializer/initializer.go b/internal/pkg/runtime/initializer/initializer.go index ce74ffb19..7db97ce55 100644 --- a/internal/pkg/runtime/initializer/initializer.go +++ b/internal/pkg/runtime/initializer/initializer.go @@ -5,7 +5,6 @@ package initializer 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/initializer/cloud" "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 // environment it is in. 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. diff --git a/internal/pkg/runtime/initializer/interactive/interactive.go b/internal/pkg/runtime/initializer/interactive/interactive.go index 860deaff7..89fc71fb0 100644 --- a/internal/pkg/runtime/initializer/interactive/interactive.go +++ b/internal/pkg/runtime/initializer/interactive/interactive.go @@ -17,7 +17,7 @@ import ( "github.com/talos-systems/talos/internal/pkg/installer" "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/config/machine" "github.com/talos-systems/talos/pkg/constants" @@ -28,7 +28,7 @@ import ( type Interactive struct{} // 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 dev, err = probe.GetDevWithFileSystemLabel(constants.ISOFilesystemLabel) diff --git a/internal/pkg/runtime/initializer/metal/metal.go b/internal/pkg/runtime/initializer/metal/metal.go index 94b282aa1..e24bf97e0 100644 --- a/internal/pkg/runtime/initializer/metal/metal.go +++ b/internal/pkg/runtime/initializer/metal/metal.go @@ -13,7 +13,7 @@ import ( "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/platform" + "github.com/talos-systems/talos/internal/pkg/runtime" "github.com/talos-systems/talos/pkg/config/machine" ) @@ -22,7 +22,7 @@ import ( type Metal struct{} // 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 // An err case should only happen if no partitions // with matching labels were found diff --git a/internal/pkg/runtime/platform.go b/internal/pkg/runtime/platform.go new file mode 100644 index 000000000..3a816782e --- /dev/null +++ b/internal/pkg/runtime/platform.go @@ -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) +} diff --git a/internal/pkg/platform/aws/aws.go b/internal/pkg/runtime/platform/aws/aws.go similarity index 100% rename from internal/pkg/platform/aws/aws.go rename to internal/pkg/runtime/platform/aws/aws.go diff --git a/internal/pkg/platform/aws/aws_test.go b/internal/pkg/runtime/platform/aws/aws_test.go similarity index 100% rename from internal/pkg/platform/aws/aws_test.go rename to internal/pkg/runtime/platform/aws/aws_test.go diff --git a/internal/pkg/platform/azure/azure.go b/internal/pkg/runtime/platform/azure/azure.go similarity index 100% rename from internal/pkg/platform/azure/azure.go rename to internal/pkg/runtime/platform/azure/azure.go index 99ec5e8e3..be3336128 100644 --- a/internal/pkg/platform/azure/azure.go +++ b/internal/pkg/runtime/platform/azure/azure.go @@ -46,11 +46,6 @@ func (a *Azure) Configuration() ([]byte, error) { 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. func (a *Azure) Hostname() (hostname []byte, err error) { var ( @@ -82,6 +77,11 @@ func (a *Azure) Hostname() (hostname []byte, err error) { 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 func (a *Azure) ExternalIPs() (addrs []net.IP, err error) { var ( diff --git a/internal/pkg/platform/azure/azure_test.go b/internal/pkg/runtime/platform/azure/azure_test.go similarity index 100% rename from internal/pkg/platform/azure/azure_test.go rename to internal/pkg/runtime/platform/azure/azure_test.go diff --git a/internal/pkg/platform/azure/register.go b/internal/pkg/runtime/platform/azure/register.go similarity index 100% rename from internal/pkg/platform/azure/register.go rename to internal/pkg/runtime/platform/azure/register.go diff --git a/internal/pkg/platform/container/container.go b/internal/pkg/runtime/platform/container/container.go similarity index 100% rename from internal/pkg/platform/container/container.go rename to internal/pkg/runtime/platform/container/container.go index cace606ee..e754f0838 100644 --- a/internal/pkg/platform/container/container.go +++ b/internal/pkg/runtime/platform/container/container.go @@ -36,16 +36,16 @@ func (c *Container) Configuration() ([]byte, error) { return decoded, nil } -// Mode implements the platform.Platform interface. -func (c *Container) Mode() runtime.Mode { - return runtime.Container -} - // Hostname implements the platform.Platform interface. func (c *Container) Hostname() (hostname []byte, err error) { 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 func (c *Container) ExternalIPs() (addrs []net.IP, err error) { return addrs, err diff --git a/internal/pkg/platform/gcp/gcp.go b/internal/pkg/runtime/platform/gcp/gcp.go similarity index 100% rename from internal/pkg/platform/gcp/gcp.go rename to internal/pkg/runtime/platform/gcp/gcp.go index 904888df4..48741441d 100644 --- a/internal/pkg/platform/gcp/gcp.go +++ b/internal/pkg/runtime/platform/gcp/gcp.go @@ -37,16 +37,16 @@ func (g *GCP) Configuration() ([]byte, error) { 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. func (g *GCP) Hostname() (hostname []byte, err error) { 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 func (g *GCP) ExternalIPs() (addrs []net.IP, err error) { var ( diff --git a/internal/pkg/platform/gcp/gcp_test.go b/internal/pkg/runtime/platform/gcp/gcp_test.go similarity index 100% rename from internal/pkg/platform/gcp/gcp_test.go rename to internal/pkg/runtime/platform/gcp/gcp_test.go diff --git a/internal/pkg/platform/iso/iso.go b/internal/pkg/runtime/platform/iso/iso.go similarity index 100% rename from internal/pkg/platform/iso/iso.go rename to internal/pkg/runtime/platform/iso/iso.go index 1fdbb924a..0a5c8ec21 100644 --- a/internal/pkg/platform/iso/iso.go +++ b/internal/pkg/runtime/platform/iso/iso.go @@ -41,16 +41,16 @@ func (i *ISO) Configuration() ([]byte, error) { return b, nil } -// Mode implements the platform.Platform interface. -func (i *ISO) Mode() runtime.Mode { - return runtime.Interactive -} - // Hostname implements the platform.Platform interface. func (i *ISO) Hostname() (hostname []byte, err error) { 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 func (i *ISO) ExternalIPs() (addrs []net.IP, err error) { return addrs, err diff --git a/internal/pkg/platform/metal/metal.go b/internal/pkg/runtime/platform/metal/metal.go similarity index 99% rename from internal/pkg/platform/metal/metal.go rename to internal/pkg/runtime/platform/metal/metal.go index 69a15cd4b..0c415c776 100644 --- a/internal/pkg/platform/metal/metal.go +++ b/internal/pkg/runtime/platform/metal/metal.go @@ -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. func (b *Metal) Hostname() (hostname []byte, err error) { 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 func (b *Metal) ExternalIPs() (addrs []net.IP, err error) { return addrs, err diff --git a/internal/pkg/platform/metal/metal_test.go b/internal/pkg/runtime/platform/metal/metal_test.go similarity index 100% rename from internal/pkg/platform/metal/metal_test.go rename to internal/pkg/runtime/platform/metal/metal_test.go diff --git a/internal/pkg/platform/packet/packet.go b/internal/pkg/runtime/platform/packet/packet.go similarity index 98% rename from internal/pkg/platform/packet/packet.go rename to internal/pkg/runtime/platform/packet/packet.go index 07f8bdd02..6c5ea489d 100644 --- a/internal/pkg/platform/packet/packet.go +++ b/internal/pkg/runtime/platform/packet/packet.go @@ -31,7 +31,7 @@ func (p *Packet) Configuration() ([]byte, error) { // Mode implements the platform.Platform interface. func (p *Packet) Mode() runtime.Mode { - return runtime.Metal + return runtime.Cloud } // Hostname implements the platform.Platform interface. diff --git a/internal/pkg/platform/packet/packet_test.go b/internal/pkg/runtime/platform/packet/packet_test.go similarity index 100% rename from internal/pkg/platform/packet/packet_test.go rename to internal/pkg/runtime/platform/packet/packet_test.go diff --git a/internal/pkg/platform/platform.go b/internal/pkg/runtime/platform/platform.go similarity index 61% rename from internal/pkg/platform/platform.go rename to internal/pkg/runtime/platform/platform.go index 8b3a49374..68874a933 100644 --- a/internal/pkg/platform/platform.go +++ b/internal/pkg/runtime/platform/platform.go @@ -5,38 +5,27 @@ package platform import ( - "net" "os" "github.com/pkg/errors" "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/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" ) -// 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. // // nolint: gocyclo -func NewPlatform() (p Platform, err error) { +func NewPlatform() (p runtime.Platform, err error) { var platform string if p := kernel.ProcCmdline().Get(constants.KernelParamPlatform).First(); p != nil { platform = *p diff --git a/internal/pkg/platform/vmware/vmware.go b/internal/pkg/runtime/platform/vmware/vmware.go similarity index 100% rename from internal/pkg/platform/vmware/vmware.go rename to internal/pkg/runtime/platform/vmware/vmware.go index 983fade24..86cd81fa9 100644 --- a/internal/pkg/platform/vmware/vmware.go +++ b/internal/pkg/runtime/platform/vmware/vmware.go @@ -65,16 +65,16 @@ func (v *VMware) Configuration() ([]byte, error) { return nil, nil } -// Mode implements the platform.Platform interface. -func (v *VMware) Mode() runtime.Mode { - return runtime.Cloud -} - // Hostname implements the platform.Platform interface. func (v *VMware) Hostname() (hostname []byte, err error) { 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 func (v *VMware) ExternalIPs() (addrs []net.IP, err error) { return addrs, err diff --git a/internal/pkg/platform/vmware/vmware_test.go b/internal/pkg/runtime/platform/vmware/vmware_test.go similarity index 100% rename from internal/pkg/platform/vmware/vmware_test.go rename to internal/pkg/runtime/platform/vmware/vmware_test.go diff --git a/internal/pkg/runtime/runtime.go b/internal/pkg/runtime/runtime.go index 355748e0c..bc963d987 100644 --- a/internal/pkg/runtime/runtime.go +++ b/internal/pkg/runtime/runtime.go @@ -4,6 +4,10 @@ package runtime +import ( + "github.com/talos-systems/talos/pkg/config" +) + // Mode is a runtime mode. type Mode int @@ -22,3 +26,33 @@ const ( func (m Mode) String() string { 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 +}