Skip to content

Commit

Permalink
Fix always overwriting k0s version with latest version (#340)
Browse files Browse the repository at this point in the history
* Fix k0s version defaulting to latest to not override existing value

* Show download url in debug

* Why is this necessary?
  • Loading branch information
kke committed Mar 4, 2022
1 parent 1767917 commit e6e8d94
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions phase/download_binaries.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"net/http"
"os"
"strings"

"github.com/k0sproject/k0sctl/cache"
"github.com/k0sproject/k0sctl/pkg/apis/k0sctl.k0sproject.io/v1beta1"
Expand Down Expand Up @@ -107,11 +108,11 @@ func (b binary) ext() string {
}

func (b binary) url() string {
return fmt.Sprintf("https://github.com/k0sproject/k0s/releases/download/v%s/k0s-v%s-%s%s", b.version, b.version, b.arch, b.ext())
return fmt.Sprintf("https://github.com/k0sproject/k0s/releases/download/v%s/k0s-v%s-%s%s", strings.TrimPrefix(b.version, "v"), strings.TrimPrefix(b.version, "v"), b.arch, b.ext())
}

func (b binary) downloadTo(path string) error {
log.Infof("downloading k0s version %s binary for %s-%s", b.version, b.os, b.arch)
log.Infof("downloading k0s version %s binary for %s-%s from %s", b.version, b.os, b.arch, b.url())

var err error

Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/k0s.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ func (k *K0s) validateMinDynamic() func(interface{}) error {

// SetDefaults (implements defaults Setter interface) defaults the version to latest k0s version
func (k *K0s) SetDefaults() {
if k.Version != "" {
return
}

latest, err := version.LatestReleaseByPrerelease(k0sctl.IsPre() || k0sctl.Version == "0.0.0")
if err == nil {
k.Version = latest.String()
Expand Down

0 comments on commit e6e8d94

Please sign in to comment.