Skip to content

Commit 6ae628d

Browse files
committed
Default Pull/Push to use containers.conf Retry, RetryDelay
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
1 parent 6ee157e commit 6ae628d

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

libimage/pull.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,23 @@ func (r *Runtime) Pull(ctx context.Context, name string, pullPolicy config.PullP
6060
options = &PullOptions{}
6161
}
6262

63+
defaultConfig, err := config.Default()
64+
if err != nil {
65+
return nil, err
66+
}
67+
if options.MaxRetries == nil {
68+
options.MaxRetries = &defaultConfig.Engine.Retry
69+
}
70+
if options.RetryDelay == nil {
71+
if defaultConfig.Engine.RetryDelay != "" {
72+
duration, err := time.ParseDuration(defaultConfig.Engine.RetryDelay)
73+
if err != nil {
74+
return nil, fmt.Errorf("failed to parse containers.conf retry_delay: %w", err)
75+
}
76+
options.RetryDelay = &duration
77+
}
78+
}
79+
6380
var possiblyUnqualifiedName string // used for short-name resolution
6481
ref, err := alltransports.ParseImageName(name)
6582
if err != nil {

libimage/push.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ package libimage
44

55
import (
66
"context"
7+
"fmt"
78
"time"
89

10+
"github.com/containers/common/pkg/config"
911
dockerArchiveTransport "github.com/containers/image/v5/docker/archive"
1012
"github.com/containers/image/v5/docker/reference"
1113
"github.com/containers/image/v5/transports/alltransports"
@@ -31,6 +33,23 @@ func (r *Runtime) Push(ctx context.Context, source, destination string, options
3133
options = &PushOptions{}
3234
}
3335

36+
defaultConfig, err := config.Default()
37+
if err != nil {
38+
return nil, err
39+
}
40+
if options.MaxRetries == nil {
41+
options.MaxRetries = &defaultConfig.Engine.Retry
42+
}
43+
if options.RetryDelay == nil {
44+
if defaultConfig.Engine.RetryDelay != "" {
45+
duration, err := time.ParseDuration(defaultConfig.Engine.RetryDelay)
46+
if err != nil {
47+
return nil, fmt.Errorf("failed to parse containers.conf retry_delay: %w", err)
48+
}
49+
options.RetryDelay = &duration
50+
}
51+
}
52+
3453
// Look up the local image. Note that we need to ignore the platform
3554
// and push what the user specified (containers/podman/issues/10344).
3655
image, resolvedSource, err := r.LookupImage(source, nil)

0 commit comments

Comments
 (0)