Skip to content

Commit d8af765

Browse files
authored
Use sudo when downloading k0s to /usr/local/bin (#702)
Signed-off-by: Kimmo Lehto <[email protected]>
1 parent bb5034f commit d8af765

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

configurer/linux.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,10 @@ func (l *Linux) DownloadURL(h os.Host, url, destination string, opts ...exec.Opt
168168
}
169169

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

phase/download_k0s.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ func (p *DownloadK0s) downloadK0s(h *cluster.Host) error {
6666
if h.K0sDownloadURL != "" {
6767
expandedURL := h.ExpandTokens(h.K0sDownloadURL, p.Config.Spec.K0s.Version)
6868
log.Infof("%s: downloading k0s binary from %s", h, expandedURL)
69-
if err := h.Configurer.DownloadURL(h, expandedURL, tmp); err != nil {
69+
if err := h.Configurer.DownloadURL(h, expandedURL, tmp, exec.Sudo(h)); err != nil {
7070
return fmt.Errorf("failed to download k0s binary: %w", err)
7171
}
72-
} else if err := h.Configurer.DownloadK0s(h, tmp, p.Config.Spec.K0s.Version, h.Metadata.Arch); err != nil {
72+
} else if err := h.Configurer.DownloadK0s(h, tmp, p.Config.Spec.K0s.Version, h.Metadata.Arch, exec.Sudo(h)); err != nil {
7373
return err
7474
}
7575

pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/host.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ type configurer interface {
144144
ReadFile(os.Host, string) (string, error)
145145
FileExist(os.Host, string) bool
146146
Chmod(os.Host, string, string, ...exec.Option) error
147-
DownloadK0s(os.Host, string, *version.Version, string) error
147+
DownloadK0s(os.Host, string, *version.Version, string, ...exec.Option) error
148148
DownloadURL(os.Host, string, string, ...exec.Option) error
149149
InstallPackage(os.Host, ...string) error
150150
FileContains(os.Host, string, string) bool

0 commit comments

Comments
 (0)