Skip to content

Commit

Permalink
Fix always performing an upgrade when UploadBinary: true (#214)
Browse files Browse the repository at this point in the history
  • Loading branch information
kke committed Sep 13, 2021
1 parent 32a334e commit 23c86e0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
9 changes: 5 additions & 4 deletions config/cluster/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion phase/download_binaries.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
9 changes: 8 additions & 1 deletion phase/gather_k0s_facts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
6 changes: 3 additions & 3 deletions phase/upload_binaries.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}

Expand Down

0 comments on commit 23c86e0

Please sign in to comment.