Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tee error when uploading k0s binaries #366

Merged
merged 2 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's even the possibility in getting the file size and modification date from an URL. A HEAD request and an inspection of the Content-Length and Last-Modified headers.

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) {
kke marked this conversation as resolved.
Show resolved Hide resolved
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