Skip to content

Commit d97cc1f

Browse files
erdiikke
andauthored
Set ETCD_UNSUPPORTED_ARCH on ARM controller nodes (#184)
* 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]>
1 parent 428bedd commit d97cc1f

File tree

10 files changed

+178
-1
lines changed

10 files changed

+178
-1
lines changed

cmd/apply.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ var applyCommand = &cli.Command{
7676
&phase.UploadBinaries{},
7777
&phase.DownloadK0s{},
7878
&phase.RunHooks{Stage: "before", Action: "apply"},
79+
&phase.PrepareArm{},
7980
&phase.ConfigureK0s{},
8081
&phase.Restore{
8182
RestoreFrom: ctx.String("restore-from"),

config/cluster/host.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ type configurer interface {
7171
PrivateInterface(os.Host) (string, error)
7272
PrivateAddress(os.Host, string, string) (string, error)
7373
TempDir(os.Host) (string, error)
74+
UpdateServiceEnvironment(os.Host, string, map[string]string) error
75+
CleanupServiceEnvironment(os.Host, string) error
7476
}
7577

7678
// HostMetadata resolved metadata for host

phase/arm_prepare.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package phase
2+
3+
import (
4+
"strings"
5+
6+
log "github.com/sirupsen/logrus"
7+
8+
"github.com/k0sproject/k0sctl/config"
9+
"github.com/k0sproject/k0sctl/config/cluster"
10+
)
11+
12+
// PrepareArm implements a phase which fixes arm quirks
13+
type PrepareArm struct {
14+
GenericPhase
15+
16+
hosts cluster.Hosts
17+
}
18+
19+
// Title for the phase
20+
func (p *PrepareArm) Title() string {
21+
return "Prepare ARM nodes"
22+
}
23+
24+
// Prepare the phase
25+
func (p *PrepareArm) Prepare(config *config.Cluster) error {
26+
p.Config = config
27+
28+
p.hosts = p.Config.Spec.Hosts.Filter(func(h *cluster.Host) bool {
29+
arch := h.Metadata.Arch
30+
return h.Role != "worker" && (strings.HasPrefix(arch, "arm") || strings.HasPrefix(arch, "aarch"))
31+
})
32+
33+
return nil
34+
}
35+
36+
// ShouldRun is true when there are arm controllers
37+
func (p *PrepareArm) ShouldRun() bool {
38+
return len(p.hosts) > 0
39+
}
40+
41+
// Run the phase
42+
func (p *PrepareArm) Run() error {
43+
return p.hosts.ParallelEach(p.etcdUnsupportedArch)
44+
}
45+
46+
func (p *PrepareArm) etcdUnsupportedArch(h *cluster.Host) error {
47+
var arch string
48+
switch h.Metadata.Arch {
49+
case "aarch32", "arm32", "armv7l", "armhfp", "arm-32":
50+
arch = "arm32"
51+
default:
52+
arch = "arm64"
53+
}
54+
55+
log.Warnf("%s: enabling ETCD_UNSUPPORTED_ARCH=%s override - you may encounter problems with etcd", h, arch)
56+
h.Environment["ETCD_UNSUPPORTED_ARCH"] = arch
57+
58+
return nil
59+
}

phase/initialize_k0s.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ func (p *InitializeK0s) ShouldRun() bool {
3232
return p.leader != nil
3333
}
3434

35+
// CleanUp cleans up the environment override file
36+
func (p *InitializeK0s) CleanUp() {
37+
h := p.leader
38+
if len(h.Environment) > 0 {
39+
if err := h.Configurer.CleanupServiceEnvironment(h, h.K0sServiceName()); err != nil {
40+
log.Warnf("%s: failed to clean up service environment: %s", h, err.Error())
41+
}
42+
}
43+
}
44+
3545
// Run the phase
3646
func (p *InitializeK0s) Run() error {
3747
h := p.leader
@@ -42,6 +52,13 @@ func (p *InitializeK0s) Run() error {
4252
return err
4353
}
4454

55+
if len(h.Environment) > 0 {
56+
log.Infof("%s: updating service environment", h)
57+
if err := h.Configurer.UpdateServiceEnvironment(h, h.K0sServiceName(), h.Environment); err != nil {
58+
return err
59+
}
60+
}
61+
4562
if err := h.Configurer.StartService(h, h.K0sServiceName()); err != nil {
4663
return err
4764
}

phase/install_controllers.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ func (p *InstallControllers) ShouldRun() bool {
3737
return len(p.hosts) > 0
3838
}
3939

40+
// CleanUp cleans up the environment override files on hosts
41+
func (p *InstallControllers) CleanUp() {
42+
for _, h := range p.hosts {
43+
if len(h.Environment) > 0 {
44+
if err := h.Configurer.CleanupServiceEnvironment(h, h.K0sServiceName()); err != nil {
45+
log.Warnf("%s: failed to clean up service environment: %s", h, err.Error())
46+
}
47+
}
48+
}
49+
}
50+
4051
// Run the phase
4152
func (p *InstallControllers) Run() error {
4253
for _, h := range p.hosts {
@@ -60,6 +71,13 @@ func (p *InstallControllers) Run() error {
6071
return err
6172
}
6273

74+
if len(h.Environment) > 0 {
75+
log.Infof("%s: updating service environment", h)
76+
if err := h.Configurer.UpdateServiceEnvironment(h, h.K0sServiceName(), h.Environment); err != nil {
77+
return err
78+
}
79+
}
80+
6381
log.Infof("%s: starting service", h)
6482
if err := h.Configurer.StartService(h, h.K0sServiceName()); err != nil {
6583
return err

phase/install_workers.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ func (p *InstallWorkers) ShouldRun() bool {
3737
return len(p.hosts) > 0
3838
}
3939

40+
// CleanUp cleans up the environment override files on hosts
41+
func (p *InstallWorkers) CleanUp() {
42+
for _, h := range p.hosts {
43+
if len(h.Environment) > 0 {
44+
if err := h.Configurer.CleanupServiceEnvironment(h, h.K0sServiceName()); err != nil {
45+
log.Warnf("%s: failed to clean up service environment: %s", h, err.Error())
46+
}
47+
}
48+
}
49+
}
50+
4051
// Run the phase
4152
func (p *InstallWorkers) Run() error {
4253
log.Infof("%s: generating token", p.leader)
@@ -75,6 +86,13 @@ func (p *InstallWorkers) Run() error {
7586
return err
7687
}
7788

89+
if len(h.Environment) > 0 {
90+
log.Infof("%s: updating service environment", h)
91+
if err := h.Configurer.UpdateServiceEnvironment(h, h.K0sServiceName(), h.Environment); err != nil {
92+
return err
93+
}
94+
}
95+
7896
log.Infof("%s: starting service", h)
7997
if err := h.Configurer.StartService(h, h.K0sServiceName()); err != nil {
8098
return err

phase/manager.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ type propsetter interface {
3737
SetProp(string, interface{})
3838
}
3939

40+
type withcleanup interface {
41+
CleanUp()
42+
}
43+
4044
// Manager executes phases to construct the cluster
4145
type Manager struct {
4246
phases []phase
@@ -50,6 +54,20 @@ func (m *Manager) AddPhase(p ...phase) {
5054

5155
// Run executes all the added Phases in order
5256
func (m *Manager) Run() error {
57+
var ran []phase
58+
var result error
59+
60+
defer func() {
61+
if result != nil {
62+
for _, p := range ran {
63+
if c, ok := p.(withcleanup); ok {
64+
log.Infof(Colorize.Red("* Running clean-up for phase: %s").String(), p.Title())
65+
c.CleanUp()
66+
}
67+
}
68+
}
69+
}()
70+
5371
for _, p := range m.phases {
5472
title := p.Title()
5573

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

82100
text := Colorize.Green("==> Running phase: %s").String()
83101
log.Infof(text, title)
84-
result := p.Run()
102+
result = p.Run()
103+
ran = append(ran, p)
85104

86105
if p, ok := p.(afterhook); ok {
87106
if err := p.After(result); err != nil {

phase/reset.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ func (p *Reset) Prepare(config *config.Cluster) error {
4848
// Run the phase
4949
func (p *Reset) Run() error {
5050
return p.hosts.ParallelEach(func(h *cluster.Host) error {
51+
log.Infof("%s: cleaning up service environment", h)
52+
if err := h.Configurer.CleanupServiceEnvironment(h, h.K0sServiceName()); err != nil {
53+
return err
54+
}
55+
5156
if h.Configurer.ServiceIsRunning(h, h.K0sServiceName()) {
5257
log.Infof("%s: stopping k0s", h)
5358
if err := h.Configurer.StopService(h, h.K0sServiceName()); err != nil {

phase/upgrade_controllers.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ func (p *UpgradeControllers) ShouldRun() bool {
4040
return len(p.hosts) > 0
4141
}
4242

43+
// CleanUp cleans up the environment override files on hosts
44+
func (p *UpgradeControllers) CleanUp() {
45+
for _, h := range p.hosts {
46+
if len(h.Environment) > 0 {
47+
if err := h.Configurer.CleanupServiceEnvironment(h, h.K0sServiceName()); err != nil {
48+
log.Warnf("%s: failed to clean up service environment: %s", h, err.Error())
49+
}
50+
}
51+
}
52+
}
53+
4354
// Run the phase
4455
func (p *UpgradeControllers) Run() error {
4556
for _, h := range p.hosts {
@@ -59,6 +70,14 @@ func (p *UpgradeControllers) Run() error {
5970
if err := h.UpdateK0sBinary(p.Config.Spec.K0s.Version); err != nil {
6071
return err
6172
}
73+
74+
if len(h.Environment) > 0 {
75+
log.Infof("%s: updating service environment", h)
76+
if err := h.Configurer.UpdateServiceEnvironment(h, h.K0sServiceName(), h.Environment); err != nil {
77+
return err
78+
}
79+
}
80+
6281
if err := h.Configurer.StartService(h, h.K0sServiceName()); err != nil {
6382
return err
6483
}

phase/upgrade_workers.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ func (p *UpgradeWorkers) ShouldRun() bool {
4444
return len(p.hosts) > 0
4545
}
4646

47+
// CleanUp cleans up the environment override files on hosts
48+
func (p *UpgradeWorkers) CleanUp() {
49+
for _, h := range p.hosts {
50+
if len(h.Environment) > 0 {
51+
if err := h.Configurer.CleanupServiceEnvironment(h, h.K0sServiceName()); err != nil {
52+
log.Warnf("%s: failed to clean up service environment: %s", h, err.Error())
53+
}
54+
}
55+
}
56+
}
57+
4758
// Run the phase
4859
func (p *UpgradeWorkers) Run() error {
4960
// Upgrade worker hosts parallelly in 10% chunks
@@ -93,6 +104,14 @@ func (p *UpgradeWorkers) upgradeWorker(h *cluster.Host) error {
93104
if err := h.UpdateK0sBinary(p.Config.Spec.K0s.Version); err != nil {
94105
return err
95106
}
107+
108+
if len(h.Environment) > 0 {
109+
log.Infof("%s: updating service environment", h)
110+
if err := h.Configurer.UpdateServiceEnvironment(h, h.K0sServiceName(), h.Environment); err != nil {
111+
return err
112+
}
113+
}
114+
96115
if err := h.Configurer.StartService(h, h.K0sServiceName()); err != nil {
97116
return err
98117
}

0 commit comments

Comments
 (0)