Allow podman pull to specify --retry and --retry-delay

Fixes: https://github.com/containers/podman/issues/19770

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
Daniel J Walsh
2024-02-14 14:25:10 -05:00
parent 3b3423230c
commit 7ba23cd6fc
13 changed files with 184 additions and 5 deletions

View File

@ -257,9 +257,11 @@ func CreateImageFromImage(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
query := struct {
FromImage string `schema:"fromImage"`
Tag string `schema:"tag"`
Platform string `schema:"platform"`
FromImage string `schema:"fromImage"`
Tag string `schema:"tag"`
Platform string `schema:"platform"`
Retry uint `schema:"retry"`
RetryDelay string `schema:"retryDelay"`
}{
// This is where you can override the golang default value for one of fields
}
@ -290,6 +292,19 @@ func CreateImageFromImage(w http.ResponseWriter, r *http.Request) {
}
pullOptions.Writer = os.Stderr // allows for debugging on the server
if _, found := r.URL.Query()["retry"]; found {
pullOptions.MaxRetries = &query.Retry
}
if _, found := r.URL.Query()["retryDelay"]; found {
duration, err := time.ParseDuration(query.RetryDelay)
if err != nil {
utils.Error(w, http.StatusBadRequest, err)
return
}
pullOptions.RetryDelay = &duration
}
// Handle the platform.
platformSpecs := strings.Split(query.Platform, "/")
pullOptions.OS = platformSpecs[0] // may be empty

View File

@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"net/http"
"time"
"github.com/containers/common/libimage"
"github.com/containers/common/pkg/config"
@ -33,6 +34,8 @@ func ImagesPull(w http.ResponseWriter, r *http.Request) {
PullPolicy string `schema:"policy"`
Quiet bool `schema:"quiet"`
Reference string `schema:"reference"`
Retry uint `schema:"retry"`
RetryDelay string `schema:"retrydelay"`
TLSVerify bool `schema:"tlsVerify"`
// Platform fields below:
Arch string `schema:"Arch"`
@ -95,6 +98,19 @@ func ImagesPull(w http.ResponseWriter, r *http.Request) {
return
}
if _, found := r.URL.Query()["retry"]; found {
pullOptions.MaxRetries = &query.Retry
}
if _, found := r.URL.Query()["retrydelay"]; found {
duration, err := time.ParseDuration(query.RetryDelay)
if err != nil {
utils.Error(w, http.StatusBadRequest, err)
return
}
pullOptions.RetryDelay = &duration
}
// Let's keep thing simple when running in quiet mode and pull directly.
if query.Quiet {
images, err := runtime.LibimageRuntime().Pull(r.Context(), query.Reference, pullPolicy, pullOptions)