Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload new k0s binary directly to final directory #685

Merged
merged 2 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions phase/download_k0s.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package phase

import (
"fmt"
"strconv"
"time"

"github.com/k0sproject/k0sctl/pkg/apis/k0sctl.k0sproject.io/v1beta1"
"github.com/k0sproject/k0sctl/pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster"
"github.com/k0sproject/rig/exec"
"github.com/sirupsen/logrus"
log "github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -59,17 +59,14 @@ func (p *DownloadK0s) Run() error {
}

func (p *DownloadK0s) downloadK0s(h *cluster.Host) error {
tmp, err := h.Configurer.TempFile(h)
if err != nil {
return fmt.Errorf("failed to create tempfile %w", err)
}
tmp := h.Configurer.K0sBinaryPath() + ".tmp." + strconv.Itoa(int(time.Now().UnixNano()))

log.Infof("%s: downloading k0s %s", h, p.Config.Spec.K0s.Version)
if err := h.Configurer.DownloadK0s(h, tmp, p.Config.Spec.K0s.Version, h.Metadata.Arch); err != nil {
return err
}
if err := h.Execf(`chmod +x "%s"`, tmp, exec.Sudo(h)); err != nil {
logrus.Warnf("%s: failed to chmod k0s temp binary: %v", h, err.Error())
log.Warnf("%s: failed to chmod k0s temp binary: %v", h, err.Error())
}

h.Metadata.K0sBinaryTempFile = tmp
Expand Down
12 changes: 5 additions & 7 deletions phase/upload_k0s.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package phase
import (
"fmt"
"os"
"strconv"
"time"

"github.com/k0sproject/k0sctl/pkg/apis/k0sctl.k0sproject.io/v1beta1"
"github.com/k0sproject/k0sctl/pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster"
"github.com/k0sproject/rig/exec"
"github.com/sirupsen/logrus"
log "github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -58,17 +59,14 @@ func (p *UploadK0s) Run() error {
}

func (p *UploadK0s) uploadBinary(h *cluster.Host) error {
tmp, err := h.Configurer.TempFile(h)
if err != nil {
return fmt.Errorf("failed to create tempfile %w", err)
}
tmp := h.Configurer.K0sBinaryPath() + ".tmp." + strconv.Itoa(int(time.Now().UnixNano()))

stat, err := os.Stat(h.UploadBinaryPath)
if err != nil {
return fmt.Errorf("stat %s: %w", h.UploadBinaryPath, err)
}

log.Infof("%s: uploading k0s binary from %s", h, h.UploadBinaryPath)
log.Infof("%s: uploading k0s binary from %s to %s", h, h.UploadBinaryPath, tmp)
if err := h.Upload(h.UploadBinaryPath, tmp); err != nil {
return fmt.Errorf("upload k0s binary: %w", err)
}
Expand All @@ -77,7 +75,7 @@ func (p *UploadK0s) uploadBinary(h *cluster.Host) error {
return fmt.Errorf("failed to touch %s: %w", tmp, err)
}
if err := h.Execf(`chmod +x "%s"`, tmp, exec.Sudo(h)); err != nil {
logrus.Warnf("%s: failed to chmod k0s temp binary: %v", h, err.Error())
log.Warnf("%s: failed to chmod k0s temp binary: %v", h, err.Error())
}

h.Metadata.K0sBinaryTempFile = tmp
Expand Down
Loading