mirror of
https://github.com/containers/podman.git
synced 2026-10-25 11:19:12 -04:00
add --retry --retry-delay to podman run/create
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
10 files changed
+53
-8
No files matched your search
@@ -396,6 +396,13 @@ func DefineCreateFlags(cmd *cobra.Command, cf *entities.ContainerCreateOptions,
|
||||
)
|
||||
_ = cmd.RegisterFlagCompletionFunc(requiresFlagName, AutocompleteContainers)
|
||||
|
||||
retryFlagName := "retry"
|
||||
createFlags.Uint(retryFlagName, registry.RetryDefault(), "number of times to retry in case of failure when performing pull")
|
||||
_ = cmd.RegisterFlagCompletionFunc(retryFlagName, completion.AutocompleteNone)
|
||||
retryDelayFlagName := "retry-delay"
|
||||
createFlags.String(retryDelayFlagName, registry.RetryDelayDefault(), "delay between retries in case of pull failures")
|
||||
_ = cmd.RegisterFlagCompletionFunc(retryDelayFlagName, completion.AutocompleteNone)
|
||||
|
||||
createFlags.BoolVar(
|
||||
&cf.Rm,
|
||||
"rm", false,
|
||||
|
||||
@@ -63,7 +63,7 @@ func clone(cmd *cobra.Command, args []string) error {
|
||||
ctrClone.Image = args[2]
|
||||
if !cliVals.RootFS {
|
||||
rawImageName := args[0]
|
||||
name, err := pullImage(ctrClone.Image, &ctrClone.CreateOpts)
|
||||
name, err := pullImage(cmd, ctrClone.Image, &ctrClone.CreateOpts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ func create(cmd *cobra.Command, args []string) error {
|
||||
rawImageName := ""
|
||||
if !cliVals.RootFS {
|
||||
rawImageName = args[0]
|
||||
name, err := pullImage(args[0], &cliVals)
|
||||
name, err := pullImage(cmd, args[0], &cliVals)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -336,7 +336,7 @@ func CreateInit(c *cobra.Command, vals entities.ContainerCreateOptions, isInfra
|
||||
}
|
||||
|
||||
// Pulls image if any also parses and populates OS, Arch and Variant in specified container create options
|
||||
func pullImage(imageName string, cliVals *entities.ContainerCreateOptions) (string, error) {
|
||||
func pullImage(cmd *cobra.Command, imageName string, cliVals *entities.ContainerCreateOptions) (string, error) {
|
||||
pullPolicy, err := config.ParsePullPolicy(cliVals.Pull)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -365,7 +365,7 @@ func pullImage(imageName string, cliVals *entities.ContainerCreateOptions) (stri
|
||||
return "unable to obtain decryption config", err
|
||||
}
|
||||
|
||||
pullReport, pullErr := registry.ImageEngine().Pull(registry.GetContext(), imageName, entities.ImagePullOptions{
|
||||
pullOptions := entities.ImagePullOptions{
|
||||
Authfile: cliVals.Authfile,
|
||||
Quiet: cliVals.Quiet,
|
||||
Arch: cliVals.Arch,
|
||||
@@ -375,7 +375,27 @@ func pullImage(imageName string, cliVals *entities.ContainerCreateOptions) (stri
|
||||
PullPolicy: pullPolicy,
|
||||
SkipTLSVerify: skipTLSVerify,
|
||||
OciDecryptConfig: decConfig,
|
||||
})
|
||||
}
|
||||
|
||||
if cmd.Flags().Changed("retry") {
|
||||
retry, err := cmd.Flags().GetUint("retry")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
pullOptions.Retry = &retry
|
||||
}
|
||||
|
||||
if cmd.Flags().Changed("retry-delay") {
|
||||
val, err := cmd.Flags().GetString("retry-delay")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
pullOptions.RetryDelay = val
|
||||
}
|
||||
|
||||
pullReport, pullErr := registry.ImageEngine().Pull(registry.GetContext(), imageName, pullOptions)
|
||||
if pullErr != nil {
|
||||
return "", pullErr
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ func run(cmd *cobra.Command, args []string) error {
|
||||
rawImageName := ""
|
||||
if !cliVals.RootFS {
|
||||
rawImageName = args[0]
|
||||
name, err := pullImage(args[0], &cliVals)
|
||||
name, err := pullImage(cmd, args[0], &cliVals)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
####> This option file is used in:
|
||||
####> podman build, farm build, pull, push
|
||||
####> podman build, create, farm build, pull, push, run
|
||||
####> If file is edited, make sure the changes
|
||||
####> are applicable to all of those.
|
||||
#### **--retry-delay**=*duration*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
####> This option file is used in:
|
||||
####> podman build, farm build, pull, push
|
||||
####> podman build, create, farm build, pull, push, run
|
||||
####> If file is edited, make sure the changes
|
||||
####> are applicable to all of those.
|
||||
#### **--retry**=*attempts*
|
||||
|
||||
@@ -318,6 +318,10 @@ Suppress output information when pulling images
|
||||
|
||||
@@option restart
|
||||
|
||||
@@option retry
|
||||
|
||||
@@option retry-delay
|
||||
|
||||
#### **--rm**
|
||||
|
||||
Automatically remove the container and any anonymous unnamed volume associated with
|
||||
|
||||
@@ -346,6 +346,10 @@ Suppress output information when pulling images
|
||||
|
||||
@@option restart
|
||||
|
||||
@@option retry
|
||||
|
||||
@@option retry-delay
|
||||
|
||||
#### **--rm**
|
||||
|
||||
Automatically remove the container and any anonymous unnamed volume associated with
|
||||
|
||||
@@ -216,6 +216,8 @@ type ContainerCreateOptions struct {
|
||||
Restart string
|
||||
Replace bool
|
||||
Requires []string
|
||||
Retry *uint `json:"retry,omitempty"`
|
||||
RetryDelay string `json:"retry_delay,omitempty"`
|
||||
Rm bool
|
||||
RootFS bool
|
||||
Secrets []string
|
||||
|
||||
@@ -389,6 +389,14 @@ EOF
|
||||
CONTAINERS_CONF="$containersConf" run_podman push --help
|
||||
assert "$output" =~ "--retry .*performing push \(default 10\)"
|
||||
assert "$output" =~ "--retry-delay .*push failures \(default \"5s\"\)"
|
||||
|
||||
CONTAINERS_CONF="$containersConf" run_podman create --help
|
||||
assert "$output" =~ "--retry .*performing pull \(default 10\)"
|
||||
assert "$output" =~ "--retry-delay .*pull failures \(default \"5s\"\)"
|
||||
|
||||
CONTAINERS_CONF="$containersConf" run_podman run --help
|
||||
assert "$output" =~ "--retry .*performing pull \(default 10\)"
|
||||
assert "$output" =~ "--retry-delay .*pull failures \(default \"5s\"\)"
|
||||
}
|
||||
|
||||
# END cooperation with skopeo
|
||||
|
||||
Reference in new issue
Block a user