Skip to content

Commit

Permalink
Run reset after k0s install has been run but host doesn't come up
Browse files Browse the repository at this point in the history
If "k0s install" has been run but the host fails to become ready, run
"k0s reset" in the phase's cleanup.

Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
  • Loading branch information
kke committed Oct 18, 2023
1 parent 7e7a67e commit 3817ae5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
16 changes: 16 additions & 0 deletions action/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,22 @@ func (a Apply) Run() error {

if result = a.Manager.Run(); result != nil {
analytics.Client.Publish("apply-failure", map[string]interface{}{"clusterID": a.Manager.Config.Spec.K0s.Metadata.ClusterID})
log.Info(phase.Colorize.Red("==> Apply failed").String())

var installedHosts []string
for _, h := range a.Manager.Config.Spec.Hosts {
if h.Metadata.K0sInstalled {
installedHosts = append(installedHosts, h.String())
}
}
if len(installedHosts) > 0 {
log.Warn("Cluster setup failed, but 'k0s install' has been run on the following hosts:")
for _, h := range installedHosts {
log.Warnf(" - %s", h)
}
log.Warn("You may need to reset them before retrying 'k0sctl apply'. See 'k0sctl reset --help' for more information.")
}

return result
}

Expand Down
2 changes: 2 additions & 0 deletions phase/initialize_k0s.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ func (p *InitializeK0s) Run() error {
return err
}

h.Metadata.K0sInstalled = true

if len(h.Environment) > 0 {
log.Infof("%s: updating service environment", h)
if err := h.Configurer.UpdateServiceEnvironment(h, h.K0sServiceName(), h.Environment); err != nil {
Expand Down
1 change: 1 addition & 0 deletions phase/install_controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func (p *InstallControllers) Run() error {
if err = h.Exec(cmd); err != nil {
return err
}
h.Metadata.K0sInstalled = true

if len(h.Environment) > 0 {
log.Infof("%s: updating service environment", h)
Expand Down
2 changes: 2 additions & 0 deletions phase/install_workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ func (p *InstallWorkers) Run() error {
return err
}

h.Metadata.K0sInstalled = true

if len(h.Environment) > 0 {
log.Infof("%s: updating service environment", h)
if err := h.Configurer.UpdateServiceEnvironment(h, h.K0sServiceName(), h.Environment); err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ type HostMetadata struct {
K0sBinaryVersion *version.Version
K0sBinaryTempFile string
K0sRunningVersion *version.Version
K0sInstalled bool
Arch string
IsK0sLeader bool
Hostname string
Expand Down

0 comments on commit 3817ae5

Please sign in to comment.