Skip to content

Commit

Permalink
Fix tee error when uploading k0s binaries (#366)
Browse files Browse the repository at this point in the history
* Fix tee error when uploading k0s binaries

* Update rig
  • Loading branch information
kke committed Apr 5, 2022
1 parent 14e44b4 commit 39a3f13
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/gofrs/uuid v4.2.0+incompatible // indirect
github.com/hashicorp/go-version v1.4.0 // indirect
github.com/k0sproject/dig v0.2.0
github.com/k0sproject/rig v0.6.0
github.com/k0sproject/rig v0.6.1
github.com/logrusorgru/aurora v2.0.3+incompatible
github.com/masterzen/simplexml v0.0.0-20190410153822-31eea3082786 // indirect
github.com/masterzen/winrm v0.0.0-20211231115050-232efb40349e // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/k0sproject/dig v0.2.0 h1:cNxEIl96g9kqSMfPSZLhpnZ0P8bWXKv08nxvsMHop5w=
github.com/k0sproject/dig v0.2.0/go.mod h1:rBcqaQlJpcKdt2x/OE/lPvhGU50u/e95CSm5g/r4s78=
github.com/k0sproject/rig v0.6.0 h1:KpnEeFYguLft95pvF+Z6OsfkthAsFK/Hz30eJWx9chs=
github.com/k0sproject/rig v0.6.0/go.mod h1:myOVP6gFhWATqL2iOuwKL/2hg90ZkyMqqTssx2fjWjM=
github.com/k0sproject/rig v0.6.1 h1:qPImH2ka4jalu/E0KcIx5SyOH/LBgMAECp4JHSpByWc=
github.com/k0sproject/rig v0.6.1/go.mod h1:myOVP6gFhWATqL2iOuwKL/2hg90ZkyMqqTssx2fjWjM=
github.com/k0sproject/version v0.3.0 h1:6HAn8C29+WVksGCzbQvQ9feEJpUZ0iHD8GebIQMiftQ=
github.com/k0sproject/version v0.3.0/go.mod h1:oEjuz2ItQQtAnGyRgwEV9m5R6/9rjoFC6EiEEzbkFdI=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
Expand Down
26 changes: 21 additions & 5 deletions phase/gather_k0s_facts.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package phase
import (
"encoding/json"
"fmt"
"path"
"strings"

"github.com/k0sproject/dig"
Expand Down Expand Up @@ -169,13 +170,28 @@ func (p *GatherK0sFacts) needsUpgrade(h *cluster.Host) bool {
// If supplimental files or a k0s binary have been specified explicitly,
// always upgrade. This covers the scenario where a user moves from a
// default-install cluster to one fed by OCI image bundles (ie. airgap)
if len(h.Files) > 0 {
log.Debugf("%s: marked for upgrade because there are %d file uploads for the host", h, len(h.Files))
return true
for _, f := range h.Files {
if f.IsURL() {
log.Debugf("%s: marked for upgrade because there are URL source file uploads for the host", h)
return true
}

for _, s := range f.Sources {
dest := f.DestinationFile
if dest == "" {
dest = path.Join(f.DestinationDir, s.Path)
}
src := path.Join(f.Base, s.Path)

if h.FileChanged(src, dest) {
log.Debugf("%s: marked for upgrade because file was changed for upload %s", h, src)
return true
}
}
}

if h.K0sBinaryPath != "" {
log.Debugf("%s: marked for upgrade because a static k0s binary path %s", h, h.K0sBinaryPath)
if h.K0sBinaryPath != "" && h.FileChanged(h.K0sBinaryPath, h.Configurer.K0sBinaryPath()) {
log.Debugf("%s: marked for upgrade because of a static k0s binary path %s", h, h.K0sBinaryPath)
return true
}

Expand Down
17 changes: 16 additions & 1 deletion phase/upload_binaries.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,22 @@ func (p *UploadBinaries) Title() string {
func (p *UploadBinaries) Prepare(config *v1beta1.Cluster) error {
p.Config = config
p.hosts = p.Config.Spec.Hosts.Filter(func(h *cluster.Host) bool {
return h.UploadBinaryPath != "" && h.Metadata.K0sBinaryVersion != p.Config.Spec.K0s.Version && !h.Metadata.NeedsUpgrade
// Nothing to upload
if h.UploadBinaryPath == "" {
return false
}

// Upgrade is handled separately (k0s stopped, binary uploaded, k0s restarted)
if h.Metadata.NeedsUpgrade {
return false
}

// The version is already correct
if h.Metadata.K0sBinaryVersion == p.Config.Spec.K0s.Version {
return false
}

return true
})
return nil
}
Expand Down

0 comments on commit 39a3f13

Please sign in to comment.