Skip to content

Commit

Permalink
Set ETCD_UNSUPPORTED_ARCH on ARM controller nodes (#184)
Browse files Browse the repository at this point in the history
* set ETCD_UNSUPPORTED_ARCH on arm nodes

Signed-off-by: erdii <[email protected]>

* use h.Configurer.WriteFile to upload arm override file

Signed-off-by: erdii <[email protected]>

* Finetuning

* Use rig 0.3.24 for service env management

* Whoops, left out the arm

* Missing return

* Update go.mod

* Try trickery

* Ok the file cant be called _arm

* ineffassign

* Clean up service environment during reset even if k0s not running

* More cleaning up

* Ok, after hooks were interntionally even if it errored

Co-authored-by: Kimmo Lehto <[email protected]>
  • Loading branch information
erdii and kke committed Aug 23, 2021
1 parent 428bedd commit d97cc1f
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ var applyCommand = &cli.Command{
&phase.UploadBinaries{},
&phase.DownloadK0s{},
&phase.RunHooks{Stage: "before", Action: "apply"},
&phase.PrepareArm{},
&phase.ConfigureK0s{},
&phase.Restore{
RestoreFrom: ctx.String("restore-from"),
Expand Down
2 changes: 2 additions & 0 deletions config/cluster/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ type configurer interface {
PrivateInterface(os.Host) (string, error)
PrivateAddress(os.Host, string, string) (string, error)
TempDir(os.Host) (string, error)
UpdateServiceEnvironment(os.Host, string, map[string]string) error
CleanupServiceEnvironment(os.Host, string) error
}

// HostMetadata resolved metadata for host
Expand Down
59 changes: 59 additions & 0 deletions phase/arm_prepare.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package phase

import (
"strings"

log "github.com/sirupsen/logrus"

"github.com/k0sproject/k0sctl/config"
"github.com/k0sproject/k0sctl/config/cluster"
)

// PrepareArm implements a phase which fixes arm quirks
type PrepareArm struct {
GenericPhase

hosts cluster.Hosts
}

// Title for the phase
func (p *PrepareArm) Title() string {
return "Prepare ARM nodes"
}

// Prepare the phase
func (p *PrepareArm) Prepare(config *config.Cluster) error {
p.Config = config

p.hosts = p.Config.Spec.Hosts.Filter(func(h *cluster.Host) bool {
arch := h.Metadata.Arch
return h.Role != "worker" && (strings.HasPrefix(arch, "arm") || strings.HasPrefix(arch, "aarch"))
})

return nil
}

// ShouldRun is true when there are arm controllers
func (p *PrepareArm) ShouldRun() bool {
return len(p.hosts) > 0
}

// Run the phase
func (p *PrepareArm) Run() error {
return p.hosts.ParallelEach(p.etcdUnsupportedArch)
}

func (p *PrepareArm) etcdUnsupportedArch(h *cluster.Host) error {
var arch string
switch h.Metadata.Arch {
case "aarch32", "arm32", "armv7l", "armhfp", "arm-32":
arch = "arm32"
default:
arch = "arm64"
}

log.Warnf("%s: enabling ETCD_UNSUPPORTED_ARCH=%s override - you may encounter problems with etcd", h, arch)
h.Environment["ETCD_UNSUPPORTED_ARCH"] = arch

return nil
}
17 changes: 17 additions & 0 deletions phase/initialize_k0s.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ func (p *InitializeK0s) ShouldRun() bool {
return p.leader != nil
}

// CleanUp cleans up the environment override file
func (p *InitializeK0s) CleanUp() {
h := p.leader
if len(h.Environment) > 0 {
if err := h.Configurer.CleanupServiceEnvironment(h, h.K0sServiceName()); err != nil {
log.Warnf("%s: failed to clean up service environment: %s", h, err.Error())
}
}
}

// Run the phase
func (p *InitializeK0s) Run() error {
h := p.leader
Expand All @@ -42,6 +52,13 @@ func (p *InitializeK0s) Run() error {
return err
}

if len(h.Environment) > 0 {
log.Infof("%s: updating service environment", h)
if err := h.Configurer.UpdateServiceEnvironment(h, h.K0sServiceName(), h.Environment); err != nil {
return err
}
}

if err := h.Configurer.StartService(h, h.K0sServiceName()); err != nil {
return err
}
Expand Down
18 changes: 18 additions & 0 deletions phase/install_controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ func (p *InstallControllers) ShouldRun() bool {
return len(p.hosts) > 0
}

// CleanUp cleans up the environment override files on hosts
func (p *InstallControllers) CleanUp() {
for _, h := range p.hosts {
if len(h.Environment) > 0 {
if err := h.Configurer.CleanupServiceEnvironment(h, h.K0sServiceName()); err != nil {
log.Warnf("%s: failed to clean up service environment: %s", h, err.Error())
}
}
}
}

// Run the phase
func (p *InstallControllers) Run() error {
for _, h := range p.hosts {
Expand All @@ -60,6 +71,13 @@ func (p *InstallControllers) Run() error {
return err
}

if len(h.Environment) > 0 {
log.Infof("%s: updating service environment", h)
if err := h.Configurer.UpdateServiceEnvironment(h, h.K0sServiceName(), h.Environment); err != nil {
return err
}
}

log.Infof("%s: starting service", h)
if err := h.Configurer.StartService(h, h.K0sServiceName()); err != nil {
return err
Expand Down
18 changes: 18 additions & 0 deletions phase/install_workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ func (p *InstallWorkers) ShouldRun() bool {
return len(p.hosts) > 0
}

// CleanUp cleans up the environment override files on hosts
func (p *InstallWorkers) CleanUp() {
for _, h := range p.hosts {
if len(h.Environment) > 0 {
if err := h.Configurer.CleanupServiceEnvironment(h, h.K0sServiceName()); err != nil {
log.Warnf("%s: failed to clean up service environment: %s", h, err.Error())
}
}
}
}

// Run the phase
func (p *InstallWorkers) Run() error {
log.Infof("%s: generating token", p.leader)
Expand Down Expand Up @@ -75,6 +86,13 @@ func (p *InstallWorkers) Run() error {
return err
}

if len(h.Environment) > 0 {
log.Infof("%s: updating service environment", h)
if err := h.Configurer.UpdateServiceEnvironment(h, h.K0sServiceName(), h.Environment); err != nil {
return err
}
}

log.Infof("%s: starting service", h)
if err := h.Configurer.StartService(h, h.K0sServiceName()); err != nil {
return err
Expand Down
21 changes: 20 additions & 1 deletion phase/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ type propsetter interface {
SetProp(string, interface{})
}

type withcleanup interface {
CleanUp()
}

// Manager executes phases to construct the cluster
type Manager struct {
phases []phase
Expand All @@ -50,6 +54,20 @@ func (m *Manager) AddPhase(p ...phase) {

// Run executes all the added Phases in order
func (m *Manager) Run() error {
var ran []phase
var result error

defer func() {
if result != nil {
for _, p := range ran {
if c, ok := p.(withcleanup); ok {
log.Infof(Colorize.Red("* Running clean-up for phase: %s").String(), p.Title())
c.CleanUp()
}
}
}
}()

for _, p := range m.phases {
title := p.Title()

Expand Down Expand Up @@ -81,7 +99,8 @@ func (m *Manager) Run() error {

text := Colorize.Green("==> Running phase: %s").String()
log.Infof(text, title)
result := p.Run()
result = p.Run()
ran = append(ran, p)

if p, ok := p.(afterhook); ok {
if err := p.After(result); err != nil {
Expand Down
5 changes: 5 additions & 0 deletions phase/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ func (p *Reset) Prepare(config *config.Cluster) error {
// Run the phase
func (p *Reset) Run() error {
return p.hosts.ParallelEach(func(h *cluster.Host) error {
log.Infof("%s: cleaning up service environment", h)
if err := h.Configurer.CleanupServiceEnvironment(h, h.K0sServiceName()); err != nil {
return err
}

if h.Configurer.ServiceIsRunning(h, h.K0sServiceName()) {
log.Infof("%s: stopping k0s", h)
if err := h.Configurer.StopService(h, h.K0sServiceName()); err != nil {
Expand Down
19 changes: 19 additions & 0 deletions phase/upgrade_controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ func (p *UpgradeControllers) ShouldRun() bool {
return len(p.hosts) > 0
}

// CleanUp cleans up the environment override files on hosts
func (p *UpgradeControllers) CleanUp() {
for _, h := range p.hosts {
if len(h.Environment) > 0 {
if err := h.Configurer.CleanupServiceEnvironment(h, h.K0sServiceName()); err != nil {
log.Warnf("%s: failed to clean up service environment: %s", h, err.Error())
}
}
}
}

// Run the phase
func (p *UpgradeControllers) Run() error {
for _, h := range p.hosts {
Expand All @@ -59,6 +70,14 @@ func (p *UpgradeControllers) Run() error {
if err := h.UpdateK0sBinary(p.Config.Spec.K0s.Version); err != nil {
return err
}

if len(h.Environment) > 0 {
log.Infof("%s: updating service environment", h)
if err := h.Configurer.UpdateServiceEnvironment(h, h.K0sServiceName(), h.Environment); err != nil {
return err
}
}

if err := h.Configurer.StartService(h, h.K0sServiceName()); err != nil {
return err
}
Expand Down
19 changes: 19 additions & 0 deletions phase/upgrade_workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ func (p *UpgradeWorkers) ShouldRun() bool {
return len(p.hosts) > 0
}

// CleanUp cleans up the environment override files on hosts
func (p *UpgradeWorkers) CleanUp() {
for _, h := range p.hosts {
if len(h.Environment) > 0 {
if err := h.Configurer.CleanupServiceEnvironment(h, h.K0sServiceName()); err != nil {
log.Warnf("%s: failed to clean up service environment: %s", h, err.Error())
}
}
}
}

// Run the phase
func (p *UpgradeWorkers) Run() error {
// Upgrade worker hosts parallelly in 10% chunks
Expand Down Expand Up @@ -93,6 +104,14 @@ func (p *UpgradeWorkers) upgradeWorker(h *cluster.Host) error {
if err := h.UpdateK0sBinary(p.Config.Spec.K0s.Version); err != nil {
return err
}

if len(h.Environment) > 0 {
log.Infof("%s: updating service environment", h)
if err := h.Configurer.UpdateServiceEnvironment(h, h.K0sServiceName(), h.Environment); err != nil {
return err
}
}

if err := h.Configurer.StartService(h, h.K0sServiceName()); err != nil {
return err
}
Expand Down

0 comments on commit d97cc1f

Please sign in to comment.