Skip to content

Commit 23c86e0

Browse files
authored
Fix always performing an upgrade when UploadBinary: true (#214)
1 parent 32a334e commit 23c86e0

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

config/cluster/host.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ type Host struct {
3232
OSIDOverride string `yaml:"os,omitempty"`
3333
Hooks Hooks `yaml:"hooks,omitempty"`
3434

35-
Metadata HostMetadata `yaml:"-"`
36-
Configurer configurer `yaml:"-"`
35+
UploadBinaryPath string `yaml:"-"`
36+
Metadata HostMetadata `yaml:"-"`
37+
Configurer configurer `yaml:"-"`
3738
}
3839

3940
type configurer interface {
@@ -240,8 +241,8 @@ func (h *Host) K0sServiceName() string {
240241

241242
// UpdateK0sBinary updates the binary on the host either by downloading or uploading, based on the config
242243
func (h *Host) UpdateK0sBinary(version string) error {
243-
if h.K0sBinaryPath != "" {
244-
if err := h.Upload(h.K0sBinaryPath, h.Configurer.K0sBinaryPath(), exec.Sudo(h)); err != nil {
244+
if h.UploadBinaryPath != "" {
245+
if err := h.Upload(h.UploadBinaryPath, h.Configurer.K0sBinaryPath(), exec.Sudo(h)); err != nil {
245246
return err
246247
}
247248
if err := h.Configurer.Chmod(h, h.Configurer.K0sBinaryPath(), "0700"); err != nil {

phase/download_binaries.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@ func (p *DownloadBinaries) Run() error {
7070
for _, h := range p.hosts {
7171
if h.K0sBinaryPath == "" {
7272
if bin := bins.find(h.Configurer.Kind(), h.Metadata.Arch); bin != nil {
73-
h.K0sBinaryPath = bin.path
73+
h.UploadBinaryPath = bin.path
7474
}
75+
} else {
76+
h.UploadBinaryPath = h.K0sBinaryPath
7577
}
7678
}
7779

phase/gather_k0s_facts.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,17 @@ func (p *GatherK0sFacts) needsUpgrade(h *cluster.Host) bool {
133133
// If supplimental files or a k0s binary have been specified explicitly,
134134
// always upgrade. This covers the scenario where a user moves from a
135135
// default-install cluster to one fed by OCI image bundles (ie. airgap)
136-
if len(h.Files) > 0 || h.K0sBinaryPath != "" {
136+
if len(h.Files) > 0 {
137+
log.Debugf("%s: marked for upgrade because there are %d file uploads for the host", h, len(h.Files))
137138
return true
138139
}
139140

141+
if h.K0sBinaryPath != "" {
142+
log.Debugf("%s: marked for upgrade because a static k0s binary path %s", h, h.K0sBinaryPath)
143+
return true
144+
}
145+
146+
log.Debugf("%s: checking if %s is an upgrade from %s", h, p.Config.Spec.K0s.Version, h.Metadata.K0sRunningVersion)
140147
target, err := semver.NewVersion(p.Config.Spec.K0s.Version)
141148
if err != nil {
142149
log.Warnf("%s: failed to parse target version: %s", h, err.Error())

phase/upload_binaries.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func (p *UploadBinaries) Title() string {
2222
func (p *UploadBinaries) Prepare(config *config.Cluster) error {
2323
p.Config = config
2424
p.hosts = p.Config.Spec.Hosts.Filter(func(h *cluster.Host) bool {
25-
return h.K0sBinaryPath != "" && h.Metadata.K0sBinaryVersion != p.Config.Spec.K0s.Version && !h.Metadata.NeedsUpgrade
25+
return h.UploadBinaryPath != "" && h.Metadata.K0sBinaryVersion != p.Config.Spec.K0s.Version && !h.Metadata.NeedsUpgrade
2626
})
2727
return nil
2828
}
@@ -38,8 +38,8 @@ func (p *UploadBinaries) Run() error {
3838
}
3939

4040
func (p *UploadBinaries) uploadBinary(h *cluster.Host) error {
41-
log.Infof("%s: uploading k0s binary from %s", h, h.K0sBinaryPath)
42-
if err := h.Upload(h.K0sBinaryPath, h.Configurer.K0sBinaryPath(), exec.Sudo(h)); err != nil {
41+
log.Infof("%s: uploading k0s binary from %s", h, h.UploadBinaryPath)
42+
if err := h.Upload(h.UploadBinaryPath, h.Configurer.K0sBinaryPath(), exec.Sudo(h)); err != nil {
4343
return err
4444
}
4545

0 commit comments

Comments
 (0)