Skip to content

Commit

Permalink
Ignore missing k0s binary on reset and avoid panic (#465)
Browse files Browse the repository at this point in the history
Signed-off-by: Kimmo Lehto <[email protected]>
  • Loading branch information
kke authored Feb 22, 2023
1 parent 1ebc64b commit d0e13a3
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 24 deletions.
9 changes: 1 addition & 8 deletions phase/reset_controllers.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package phase

import (
"strings"

"github.com/Masterminds/semver"
"github.com/k0sproject/k0sctl/pkg/apis/k0sctl.k0sproject.io/v1beta1"
"github.com/k0sproject/k0sctl/pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster"
"github.com/k0sproject/rig/exec"
Expand Down Expand Up @@ -107,13 +104,9 @@ func (p *ResetControllers) Run() error {

log.Debugf("%s: resetting k0s...", h)
out, err := h.ExecOutput(h.Configurer.K0sCmdf("reset --data-dir=%s", h.DataDir), exec.Sudo(h))
c, _ := semver.NewConstraint("<= 1.22.3+k0s.0")
running, _ := semver.NewVersion(h.Metadata.K0sBinaryVersion)
if err != nil {
log.Debugf("%s: k0s reset failed: %s", h, out)
log.Warnf("%s: k0s reported failure: %v", h, err)
if c.Check(running) && !strings.Contains(out, "k0s cleanup operations done") {
log.Warnf("%s: k0s reset failed, trying k0s cleanup", h)
}
}
log.Debugf("%s: resetting k0s completed", h)

Expand Down
9 changes: 1 addition & 8 deletions phase/reset_leader.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package phase

import (
"strings"

"github.com/Masterminds/semver"
"github.com/k0sproject/k0sctl/pkg/apis/k0sctl.k0sproject.io/v1beta1"
"github.com/k0sproject/k0sctl/pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster"
"github.com/k0sproject/rig/exec"
Expand Down Expand Up @@ -53,13 +50,9 @@ func (p *ResetLeader) Run() error {

log.Debugf("%s: resetting k0s...", p.leader)
out, err := p.leader.ExecOutput(p.leader.Configurer.K0sCmdf("reset --data-dir=%s", p.leader.DataDir), exec.Sudo(p.leader))
c, _ := semver.NewConstraint("<= 1.22.3+k0s.0")
running, _ := semver.NewVersion(p.leader.Metadata.K0sBinaryVersion)
if err != nil {
log.Debugf("%s: k0s reset failed: %s", p.leader, out)
log.Warnf("%s: k0s reported failure: %v", p.leader, err)
if c.Check(running) && !strings.Contains(out, "k0s cleanup operations done") {
log.Warnf("%s: k0s reset failed, trying k0s cleanup", p.leader)
}
}
log.Debugf("%s: resetting k0s completed", p.leader)

Expand Down
9 changes: 1 addition & 8 deletions phase/reset_workers.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package phase

import (
"strings"

"github.com/Masterminds/semver"
"github.com/k0sproject/k0sctl/pkg/apis/k0sctl.k0sproject.io/v1beta1"
"github.com/k0sproject/k0sctl/pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster"
"github.com/k0sproject/rig/exec"
Expand Down Expand Up @@ -98,13 +95,9 @@ func (p *ResetWorkers) Run() error {

log.Debugf("%s: resetting k0s...", h)
out, err := h.ExecOutput(h.Configurer.K0sCmdf("reset --data-dir=%s", h.DataDir), exec.Sudo(h))
c, _ := semver.NewConstraint("<= 1.22.3+k0s.0")
running, _ := semver.NewVersion(h.Metadata.K0sBinaryVersion)
if err != nil {
log.Debugf("%s: k0s reset failed: %s", h, out)
log.Warnf("%s: k0s reported failure: %v", h, err)
if c.Check(running) && !strings.Contains(out, "k0s cleanup operations done") {
log.Warnf("%s: k0s reset failed, trying k0s cleanup", h)
}
}
log.Debugf("%s: resetting k0s completed", h)

Expand Down

0 comments on commit d0e13a3

Please sign in to comment.