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

Disable grab download resume #5019

Closed
Closed
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
9 changes: 8 additions & 1 deletion pkg/autopilot/controller/signal/common/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ type DownloadManifest struct {
apdl.Config

SuccessState string
// A hook that will be called after the download itself is done succesfully
AfterTransferSuccess func() error
}

type DownloadManifestBuilder interface {
Expand Down Expand Up @@ -90,7 +92,12 @@ func (r *downloadController) Reconcile(ctx context.Context, req cr.Request) (cr.

} else {
logger.Infof("Download of '%s' successful", manifest.URL)

// When download is successful, run the post-download hook
if manifest.AfterTransferSuccess != nil {
if err := manifest.AfterTransferSuccess(); err != nil {
return cr.Result{}, fmt.Errorf("failed to run post-download hook: %w", err)
}
}
// When the download is complete move the status to the success state
signalData.Status = apsigv2.NewStatus(manifest.SuccessState)
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/autopilot/controller/signal/k0s/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ package k0s

import (
"crypto/sha256"
"os"
"path/filepath"

apcomm "github.com/k0sproject/k0s/pkg/autopilot/common"
apdel "github.com/k0sproject/k0s/pkg/autopilot/controller/delegate"
Expand Down Expand Up @@ -88,6 +90,13 @@ func (b downloadManifestBuilderK0s) Build(signalNode crcli.Object, signalData ap
ExpectedHash: signalData.Command.K0sUpdate.Sha256,
Hasher: sha256.New(),
DownloadDir: b.k0sBinaryDir,
Filename: filepath.Join(b.k0sBinaryDir, "k0s.tmp"),
},
// After the download is done, we need to rename the file to the correct name
AfterTransferSuccess: func() error {
src := filepath.Join(b.k0sBinaryDir, "k0s.tmp")
dst := filepath.Join(b.k0sBinaryDir, "k0s")
return os.Rename(src, dst)
},
SuccessState: Cordoning,
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/autopilot/download/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type Config struct {
ExpectedHash string
Hasher hash.Hash
DownloadDir string
Filename string
}

type downloader struct {
Expand Down Expand Up @@ -72,6 +73,15 @@ func (d *downloader) Download(ctx context.Context) error {
dlreq.SetChecksum(d.config.Hasher, expectedHash, true)
}

// We're never really resuming downloads, so disable this feature.
// This also allows to re-download the file if it's already present.
dlreq.NoResume = true

if d.config.Filename != "" {
d.logger.Infof("Setting filename to %s", d.config.Filename)
dlreq.Filename = d.config.Filename
}

client := grab.NewClient()
// Set user agent to mitigate 403 errors from GitHub
// See https://github.com/cavaliergopher/grab/issues/104
Expand Down
Loading