From 66d60384f4747116a59a7eaafe98dd21291ad28b Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Thu, 22 Feb 2024 07:44:56 -0500 Subject: [PATCH] add --retry --retry-delay to podman run/create Signed-off-by: Daniel J Walsh --- cmd/podman/common/create.go | 7 ++++++ cmd/podman/containers/clone.go | 2 +- cmd/podman/containers/create.go | 28 ++++++++++++++++++--- cmd/podman/containers/run.go | 2 +- docs/source/markdown/options/retry-delay.md | 2 +- docs/source/markdown/options/retry.md | 2 +- docs/source/markdown/podman-create.1.md.in | 4 +++ docs/source/markdown/podman-run.1.md.in | 4 +++ pkg/domain/entities/pods.go | 2 ++ test/system/150-login.bats | 8 ++++++ 10 files changed, 53 insertions(+), 8 deletions(-) diff --git a/cmd/podman/common/create.go b/cmd/podman/common/create.go index 3a1c7e5a6d..b88714529b 100644 --- a/cmd/podman/common/create.go +++ b/cmd/podman/common/create.go @@ -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, diff --git a/cmd/podman/containers/clone.go b/cmd/podman/containers/clone.go index 5e74634da8..cff3f10c70 100644 --- a/cmd/podman/containers/clone.go +++ b/cmd/podman/containers/clone.go @@ -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 } diff --git a/cmd/podman/containers/create.go b/cmd/podman/containers/create.go index 01692743c1..48eace09e0 100644 --- a/cmd/podman/containers/create.go +++ b/cmd/podman/containers/create.go @@ -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 } diff --git a/cmd/podman/containers/run.go b/cmd/podman/containers/run.go index bf7b53f227..46c4a3a66d 100644 --- a/cmd/podman/containers/run.go +++ b/cmd/podman/containers/run.go @@ -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 } diff --git a/docs/source/markdown/options/retry-delay.md b/docs/source/markdown/options/retry-delay.md index bd1b898e9e..005f471e4a 100644 --- a/docs/source/markdown/options/retry-delay.md +++ b/docs/source/markdown/options/retry-delay.md @@ -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* diff --git a/docs/source/markdown/options/retry.md b/docs/source/markdown/options/retry.md index ae95152231..0abca43aa0 100644 --- a/docs/source/markdown/options/retry.md +++ b/docs/source/markdown/options/retry.md @@ -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* diff --git a/docs/source/markdown/podman-create.1.md.in b/docs/source/markdown/podman-create.1.md.in index 39acaa1cbb..486eca3ddf 100644 --- a/docs/source/markdown/podman-create.1.md.in +++ b/docs/source/markdown/podman-create.1.md.in @@ -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 diff --git a/docs/source/markdown/podman-run.1.md.in b/docs/source/markdown/podman-run.1.md.in index 7756f0c77c..879dcde569 100644 --- a/docs/source/markdown/podman-run.1.md.in +++ b/docs/source/markdown/podman-run.1.md.in @@ -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 diff --git a/pkg/domain/entities/pods.go b/pkg/domain/entities/pods.go index 51167a1183..63b88e3355 100644 --- a/pkg/domain/entities/pods.go +++ b/pkg/domain/entities/pods.go @@ -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 diff --git a/test/system/150-login.bats b/test/system/150-login.bats index 44651ff3ff..3d2f66c9eb 100644 --- a/test/system/150-login.bats +++ b/test/system/150-login.bats @@ -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