Skip to content

Commit 39a3f13

Browse files
authored
Fix tee error when uploading k0s binaries (#366)
* Fix tee error when uploading k0s binaries * Update rig
1 parent 14e44b4 commit 39a3f13

File tree

4 files changed

+40
-9
lines changed

4 files changed

+40
-9
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require (
1818
github.com/gofrs/uuid v4.2.0+incompatible // indirect
1919
github.com/hashicorp/go-version v1.4.0 // indirect
2020
github.com/k0sproject/dig v0.2.0
21-
github.com/k0sproject/rig v0.6.0
21+
github.com/k0sproject/rig v0.6.1
2222
github.com/logrusorgru/aurora v2.0.3+incompatible
2323
github.com/masterzen/simplexml v0.0.0-20190410153822-31eea3082786 // indirect
2424
github.com/masterzen/winrm v0.0.0-20211231115050-232efb40349e // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1
228228
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
229229
github.com/k0sproject/dig v0.2.0 h1:cNxEIl96g9kqSMfPSZLhpnZ0P8bWXKv08nxvsMHop5w=
230230
github.com/k0sproject/dig v0.2.0/go.mod h1:rBcqaQlJpcKdt2x/OE/lPvhGU50u/e95CSm5g/r4s78=
231-
github.com/k0sproject/rig v0.6.0 h1:KpnEeFYguLft95pvF+Z6OsfkthAsFK/Hz30eJWx9chs=
232-
github.com/k0sproject/rig v0.6.0/go.mod h1:myOVP6gFhWATqL2iOuwKL/2hg90ZkyMqqTssx2fjWjM=
231+
github.com/k0sproject/rig v0.6.1 h1:qPImH2ka4jalu/E0KcIx5SyOH/LBgMAECp4JHSpByWc=
232+
github.com/k0sproject/rig v0.6.1/go.mod h1:myOVP6gFhWATqL2iOuwKL/2hg90ZkyMqqTssx2fjWjM=
233233
github.com/k0sproject/version v0.3.0 h1:6HAn8C29+WVksGCzbQvQ9feEJpUZ0iHD8GebIQMiftQ=
234234
github.com/k0sproject/version v0.3.0/go.mod h1:oEjuz2ItQQtAnGyRgwEV9m5R6/9rjoFC6EiEEzbkFdI=
235235
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=

phase/gather_k0s_facts.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package phase
33
import (
44
"encoding/json"
55
"fmt"
6+
"path"
67
"strings"
78

89
"github.com/k0sproject/dig"
@@ -169,13 +170,28 @@ func (p *GatherK0sFacts) needsUpgrade(h *cluster.Host) bool {
169170
// If supplimental files or a k0s binary have been specified explicitly,
170171
// always upgrade. This covers the scenario where a user moves from a
171172
// default-install cluster to one fed by OCI image bundles (ie. airgap)
172-
if len(h.Files) > 0 {
173-
log.Debugf("%s: marked for upgrade because there are %d file uploads for the host", h, len(h.Files))
174-
return true
173+
for _, f := range h.Files {
174+
if f.IsURL() {
175+
log.Debugf("%s: marked for upgrade because there are URL source file uploads for the host", h)
176+
return true
177+
}
178+
179+
for _, s := range f.Sources {
180+
dest := f.DestinationFile
181+
if dest == "" {
182+
dest = path.Join(f.DestinationDir, s.Path)
183+
}
184+
src := path.Join(f.Base, s.Path)
185+
186+
if h.FileChanged(src, dest) {
187+
log.Debugf("%s: marked for upgrade because file was changed for upload %s", h, src)
188+
return true
189+
}
190+
}
175191
}
176192

177-
if h.K0sBinaryPath != "" {
178-
log.Debugf("%s: marked for upgrade because a static k0s binary path %s", h, h.K0sBinaryPath)
193+
if h.K0sBinaryPath != "" && h.FileChanged(h.K0sBinaryPath, h.Configurer.K0sBinaryPath()) {
194+
log.Debugf("%s: marked for upgrade because of a static k0s binary path %s", h, h.K0sBinaryPath)
179195
return true
180196
}
181197

phase/upload_binaries.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,22 @@ func (p *UploadBinaries) Title() string {
2626
func (p *UploadBinaries) Prepare(config *v1beta1.Cluster) error {
2727
p.Config = config
2828
p.hosts = p.Config.Spec.Hosts.Filter(func(h *cluster.Host) bool {
29-
return h.UploadBinaryPath != "" && h.Metadata.K0sBinaryVersion != p.Config.Spec.K0s.Version && !h.Metadata.NeedsUpgrade
29+
// Nothing to upload
30+
if h.UploadBinaryPath == "" {
31+
return false
32+
}
33+
34+
// Upgrade is handled separately (k0s stopped, binary uploaded, k0s restarted)
35+
if h.Metadata.NeedsUpgrade {
36+
return false
37+
}
38+
39+
// The version is already correct
40+
if h.Metadata.K0sBinaryVersion == p.Config.Spec.K0s.Version {
41+
return false
42+
}
43+
44+
return true
3045
})
3146
return nil
3247
}

0 commit comments

Comments
 (0)