mirror of
https://github.com/siderolabs/talos.git
synced 2025-08-24 16:11:11 +02:00
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:
parent
e6f980463f
commit
8153c2e2a9
@ -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"
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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, ""))
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
@ -42,7 +42,7 @@ type Phase struct {
|
||||
// Runner represents a management layer for phases.
|
||||
type Runner struct {
|
||||
phases []*Phase
|
||||
args *RuntimeArgs
|
||||
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.
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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())
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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 {
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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())
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 {
|
||||
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)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to label node as master")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
time.Sleep(3 * time.Second)
|
||||
}
|
||||
|
||||
return errors.New("failed to label node as master")
|
||||
}
|
||||
|
@ -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{},
|
||||
)
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
18
internal/pkg/runtime/platform.go
Normal file
18
internal/pkg/runtime/platform.go
Normal 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)
|
||||
}
|
@ -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 (
|
@ -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
|
@ -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 (
|
@ -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
|
@ -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
|
@ -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.
|
@ -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
|
@ -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
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user