From 23c86e07bef940cdef26ebd9973fb3d01dc40ba7 Mon Sep 17 00:00:00 2001 From: Kimmo Lehto Date: Mon, 13 Sep 2021 15:56:26 +0300 Subject: [PATCH] Fix always performing an upgrade when UploadBinary: true (#214) --- config/cluster/host.go | 9 +++++---- phase/download_binaries.go | 4 +++- phase/gather_k0s_facts.go | 9 ++++++++- phase/upload_binaries.go | 6 +++--- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/config/cluster/host.go b/config/cluster/host.go index 7faacf08..1578b074 100644 --- a/config/cluster/host.go +++ b/config/cluster/host.go @@ -32,8 +32,9 @@ type Host struct { OSIDOverride string `yaml:"os,omitempty"` Hooks Hooks `yaml:"hooks,omitempty"` - Metadata HostMetadata `yaml:"-"` - Configurer configurer `yaml:"-"` + UploadBinaryPath string `yaml:"-"` + Metadata HostMetadata `yaml:"-"` + Configurer configurer `yaml:"-"` } type configurer interface { @@ -240,8 +241,8 @@ func (h *Host) K0sServiceName() string { // UpdateK0sBinary updates the binary on the host either by downloading or uploading, based on the config func (h *Host) UpdateK0sBinary(version string) error { - if h.K0sBinaryPath != "" { - if err := h.Upload(h.K0sBinaryPath, h.Configurer.K0sBinaryPath(), exec.Sudo(h)); err != nil { + if h.UploadBinaryPath != "" { + if err := h.Upload(h.UploadBinaryPath, h.Configurer.K0sBinaryPath(), exec.Sudo(h)); err != nil { return err } if err := h.Configurer.Chmod(h, h.Configurer.K0sBinaryPath(), "0700"); err != nil { diff --git a/phase/download_binaries.go b/phase/download_binaries.go index 0f62a60c..18f16e7f 100644 --- a/phase/download_binaries.go +++ b/phase/download_binaries.go @@ -70,8 +70,10 @@ func (p *DownloadBinaries) Run() error { for _, h := range p.hosts { if h.K0sBinaryPath == "" { if bin := bins.find(h.Configurer.Kind(), h.Metadata.Arch); bin != nil { - h.K0sBinaryPath = bin.path + h.UploadBinaryPath = bin.path } + } else { + h.UploadBinaryPath = h.K0sBinaryPath } } diff --git a/phase/gather_k0s_facts.go b/phase/gather_k0s_facts.go index 04298fc5..65f26302 100644 --- a/phase/gather_k0s_facts.go +++ b/phase/gather_k0s_facts.go @@ -133,10 +133,17 @@ 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 || h.K0sBinaryPath != "" { + 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 } + if h.K0sBinaryPath != "" { + log.Debugf("%s: marked for upgrade because a static k0s binary path %s", h, h.K0sBinaryPath) + return true + } + + log.Debugf("%s: checking if %s is an upgrade from %s", h, p.Config.Spec.K0s.Version, h.Metadata.K0sRunningVersion) target, err := semver.NewVersion(p.Config.Spec.K0s.Version) if err != nil { log.Warnf("%s: failed to parse target version: %s", h, err.Error()) diff --git a/phase/upload_binaries.go b/phase/upload_binaries.go index c8c0cef0..7757e9b4 100644 --- a/phase/upload_binaries.go +++ b/phase/upload_binaries.go @@ -22,7 +22,7 @@ func (p *UploadBinaries) Title() string { func (p *UploadBinaries) Prepare(config *config.Cluster) error { p.Config = config p.hosts = p.Config.Spec.Hosts.Filter(func(h *cluster.Host) bool { - return h.K0sBinaryPath != "" && h.Metadata.K0sBinaryVersion != p.Config.Spec.K0s.Version && !h.Metadata.NeedsUpgrade + return h.UploadBinaryPath != "" && h.Metadata.K0sBinaryVersion != p.Config.Spec.K0s.Version && !h.Metadata.NeedsUpgrade }) return nil } @@ -38,8 +38,8 @@ func (p *UploadBinaries) Run() error { } func (p *UploadBinaries) uploadBinary(h *cluster.Host) error { - log.Infof("%s: uploading k0s binary from %s", h, h.K0sBinaryPath) - if err := h.Upload(h.K0sBinaryPath, h.Configurer.K0sBinaryPath(), exec.Sudo(h)); err != nil { + log.Infof("%s: uploading k0s binary from %s", h, h.UploadBinaryPath) + if err := h.Upload(h.UploadBinaryPath, h.Configurer.K0sBinaryPath(), exec.Sudo(h)); err != nil { return err }