Skip to content

Commit

Permalink
Use sudo when downloading k0s to /usr/local/bin (#702)
Browse files Browse the repository at this point in the history
Signed-off-by: Kimmo Lehto <[email protected]>
  • Loading branch information
kke authored May 8, 2024
1 parent bb5034f commit d8af765
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions configurer/linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ func (l *Linux) DownloadURL(h os.Host, url, destination string, opts ...exec.Opt
}

// DownloadK0s performs k0s binary download from github on the host
func (l *Linux) DownloadK0s(h os.Host, path string, version *version.Version, arch string) error {
func (l *Linux) DownloadK0s(h os.Host, path string, version *version.Version, arch string, opts ...exec.Option) error {
v := strings.ReplaceAll(strings.TrimPrefix(version.String(), "v"), "+", "%2B")
url := fmt.Sprintf("https://github.com/k0sproject/k0s/releases/download/v%[1]s/k0s-v%[1]s-%[2]s", v, arch)
if err := l.DownloadURL(h, url, path); err != nil {
if err := l.DownloadURL(h, url, path, opts...); err != nil {
return fmt.Errorf("failed to download k0s - check connectivity and k0s version validity: %w", err)
}

Expand Down
4 changes: 2 additions & 2 deletions phase/download_k0s.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ func (p *DownloadK0s) downloadK0s(h *cluster.Host) error {
if h.K0sDownloadURL != "" {
expandedURL := h.ExpandTokens(h.K0sDownloadURL, p.Config.Spec.K0s.Version)
log.Infof("%s: downloading k0s binary from %s", h, expandedURL)
if err := h.Configurer.DownloadURL(h, expandedURL, tmp); err != nil {
if err := h.Configurer.DownloadURL(h, expandedURL, tmp, exec.Sudo(h)); err != nil {
return fmt.Errorf("failed to download k0s binary: %w", err)
}
} else if err := h.Configurer.DownloadK0s(h, tmp, p.Config.Spec.K0s.Version, h.Metadata.Arch); err != nil {
} else if err := h.Configurer.DownloadK0s(h, tmp, p.Config.Spec.K0s.Version, h.Metadata.Arch, exec.Sudo(h)); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ type configurer interface {
ReadFile(os.Host, string) (string, error)
FileExist(os.Host, string) bool
Chmod(os.Host, string, string, ...exec.Option) error
DownloadK0s(os.Host, string, *version.Version, string) error
DownloadK0s(os.Host, string, *version.Version, string, ...exec.Option) error
DownloadURL(os.Host, string, string, ...exec.Option) error
InstallPackage(os.Host, ...string) error
FileContains(os.Host, string, string) bool
Expand Down

0 comments on commit d8af765

Please sign in to comment.