Skip to content

Commit b0c05db

Browse files
committed
Add --pull-progress-timeout / pull_progress_timeout option
Add the option to be able to fine-tune the pull progress timeout or even disable it. Fixes #8764 and #8760 Follow-up on: #7887 Signed-off-by: Sascha Grunert <[email protected]>
1 parent e833123 commit b0c05db

File tree

16 files changed

+113
-28
lines changed

16 files changed

+113
-28
lines changed

completions/bash/crio

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ h
102102
--profile-cpu
103103
--profile-mem
104104
--profile-port
105+
--pull-progress-timeout
105106
--rdt-config-file
106107
--read-only
107108
--registries-conf

completions/fish/crio.fish

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ complete -c crio -n '__fish_crio_no_subcommand' -f -l profile -d 'Enable pprof r
138138
complete -c crio -n '__fish_crio_no_subcommand' -f -l profile-cpu -r -d 'Write a pprof CPU profile to the provided path.'
139139
complete -c crio -n '__fish_crio_no_subcommand' -f -l profile-mem -r -d 'Write a pprof memory profile to the provided path.'
140140
complete -c crio -n '__fish_crio_no_subcommand' -f -l profile-port -r -d 'Port for the pprof profiler.'
141+
complete -c crio -n '__fish_crio_no_subcommand' -f -l pull-progress-timeout -r -d 'The timeout for an image pull to make progress until the pull operation gets canceled. This value will be also used for calculating the pull progress interval to --pull-progress-timeout / 10. Can be set to 0 to disable the timeout as well as the progress output.'
141142
complete -c crio -n '__fish_crio_no_subcommand' -f -l rdt-config-file -r -d 'Path to the RDT configuration file for configuring the resctrl pseudo-filesystem.'
142143
complete -c crio -n '__fish_crio_no_subcommand' -f -l read-only -d 'Setup all unprivileged containers to run as read-only. Automatically mounts the containers\' tmpfs on \'/run\', \'/tmp\' and \'/var/tmp\'.'
143144
complete -c crio -n '__fish_crio_no_subcommand' -f -l registry -r -d 'Registry to be prepended when pulling unqualified images. Can be specified multiple times.'

completions/zsh/_crio

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ it later with **--config**. Global options will modify the output.'
109109
'--profile-cpu'
110110
'--profile-mem'
111111
'--profile-port'
112+
'--pull-progress-timeout'
112113
'--rdt-config-file'
113114
'--read-only'
114115
'--registries-conf'

docs/crio.8.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ crio
100100
[--profile-mem]=[value]
101101
[--profile-port]=[value]
102102
[--profile]
103+
[--pull-progress-timeout]=[value]
103104
[--rdt-config-file]=[value]
104105
[--read-only]
105106
[--registry]=[value]
@@ -374,6 +375,8 @@ crio [GLOBAL OPTIONS] command [COMMAND OPTIONS] [ARGUMENTS...]
374375

375376
**--profile-port**="": Port for the pprof profiler. (default: 6060)
376377

378+
**--pull-progress-timeout**="": The timeout for an image pull to make progress until the pull operation gets canceled. This value will be also used for calculating the pull progress interval to --pull-progress-timeout / 10. Can be set to 0 to disable the timeout as well as the progress output. (default: 10s)
379+
377380
**--rdt-config-file**="": Path to the RDT configuration file for configuring the resctrl pseudo-filesystem.
378381

379382
**--read-only**: Setup all unprivileged containers to run as read-only. Automatically mounts the containers' tmpfs on '/run', '/tmp' and '/var/tmp'.

docs/crio.conf.5.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,9 @@ CRI-O reads its configured registries defaults from the system wide containers-r
466466
**separate_pull_cgroup**=""
467467
[EXPERIMENTAL] If its value is set, then images are pulled into the specified cgroup. If its value is set to "pod", then the pod's cgroup is used. It is currently supported only with the systemd cgroup manager.
468468

469+
**pull_progress_timeout**="10s"
470+
The timeout for an image pull to make progress until the pull operation gets canceled. This value will be also used for calculating the pull progress interval to pull_progress_timeout / 10. Can be set to 0 to disable the timeout as well as the progress output.
471+
469472
## CRIO.NETWORK TABLE
470473
The `crio.network` table containers settings pertaining to the management of CNI plugins.
471474

internal/criocli/criocli.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,9 @@ func mergeConfig(config *libconfig.Config, ctx *cli.Context) error {
402402
if ctx.IsSet("big-files-temporary-dir") {
403403
config.BigFilesTemporaryDir = ctx.String("big-files-temporary-dir")
404404
}
405+
if ctx.IsSet("pull-progress-timeout") {
406+
config.PullProgressTimeout = ctx.Duration("pull-progress-timeout")
407+
}
405408
if ctx.IsSet("separate-pull-cgroup") {
406409
config.SeparatePullCgroup = ctx.String("separate-pull-cgroup")
407410
}
@@ -926,6 +929,12 @@ func getCrioFlags(defConf *libconfig.Config) []cli.Flag {
926929
EnvVars: []string{"CONTAINER_BIG_FILES_TEMPORARY_DIR"},
927930
Value: defConf.BigFilesTemporaryDir,
928931
},
932+
&cli.DurationFlag{
933+
Name: "pull-progress-timeout",
934+
Usage: "The timeout for an image pull to make progress until the pull operation gets canceled. This value will be also used for calculating the pull progress interval to --pull-progress-timeout / 10. Can be set to 0 to disable the timeout as well as the progress output.",
935+
EnvVars: []string{"CONTAINER_PULL_PROGRESS_TIMEOUT"},
936+
Value: defConf.PullProgressTimeout,
937+
},
929938
&cli.BoolFlag{
930939
Name: "read-only",
931940
Usage: "Setup all unprivileged containers to run as read-only. Automatically mounts the containers' tmpfs on '/run', '/tmp' and '/var/tmp'.",

internal/storage/image.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ type ImageServer interface {
131131
// for further analysis. Call Close() on the resulting image.
132132
PrepareImage(systemContext *types.SystemContext, imageName RegistryImageReference) (types.ImageCloser, error)
133133
// PullImage imports an image from the specified location.
134-
PullImage(imageName RegistryImageReference, options *ImageCopyOptions) (types.ImageReference, error)
134+
PullImage(ctx context.Context, imageName RegistryImageReference, options *ImageCopyOptions) (types.ImageReference, error)
135135

136136
// DeleteImage deletes a storage image (impacting all its tags)
137137
DeleteImage(systemContext *types.SystemContext, id StorageImageID) error
@@ -554,11 +554,11 @@ func formatPullImageOutputItemGoroutine(dest io.Writer, items <-chan pullImageOu
554554
}
555555
}
556556

557-
func (svc *imageService) pullImageParent(imageName RegistryImageReference, parentCgroup string, options *ImageCopyOptions) (types.ImageReference, error) {
557+
func (svc *imageService) pullImageParent(ctx context.Context, imageName RegistryImageReference, parentCgroup string, options *ImageCopyOptions) (types.ImageReference, error) {
558558
progress := options.Progress
559559
// the first argument imageName is not used by the re-execed command but it is useful for debugging as it
560560
// shows in the ps output.
561-
cmd := reexec.CommandContext(svc.ctx, "crio-pull-image", imageName.StringForOutOfProcessConsumptionOnly())
561+
cmd := reexec.CommandContext(ctx, "crio-pull-image", imageName.StringForOutOfProcessConsumptionOnly())
562562
stdout, err := cmd.StdoutPipe()
563563
if err != nil {
564564
return nil, fmt.Errorf("error getting stdout pipe for image copy process: %w", err)
@@ -650,11 +650,11 @@ func (svc *imageService) pullImageParent(imageName RegistryImageReference, paren
650650
return destRef, nil
651651
}
652652

653-
func (svc *imageService) PullImage(imageName RegistryImageReference, options *ImageCopyOptions) (types.ImageReference, error) {
653+
func (svc *imageService) PullImage(ctx context.Context, imageName RegistryImageReference, options *ImageCopyOptions) (types.ImageReference, error) {
654654
if options.CgroupPull.UseNewCgroup {
655-
return svc.pullImageParent(imageName, options.CgroupPull.ParentCgroup, options)
655+
return svc.pullImageParent(ctx, imageName, options.CgroupPull.ParentCgroup, options)
656656
} else {
657-
return pullImageImplementation(svc.ctx, svc.lookup, svc.store, imageName, options)
657+
return pullImageImplementation(ctx, svc.lookup, svc.store, imageName, options)
658658
}
659659
}
660660

internal/storage/image_test.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ var _ = t.Describe("Image", func() {
574574
Expect(err).To(BeNil())
575575

576576
// When
577-
res, err := sut.PullImage(imageRef, &storage.ImageCopyOptions{
577+
res, err := sut.PullImage(context.Background(), imageRef, &storage.ImageCopyOptions{
578578
SourceCtx: &types.SystemContext{SignaturePolicyPath: "/not-existing"},
579579
})
580580

@@ -589,7 +589,7 @@ var _ = t.Describe("Image", func() {
589589
Expect(err).To(BeNil())
590590

591591
// When
592-
res, err := sut.PullImage(imageRef, &storage.ImageCopyOptions{
592+
res, err := sut.PullImage(context.Background(), imageRef, &storage.ImageCopyOptions{
593593
SourceCtx: &types.SystemContext{SignaturePolicyPath: "../../test/policy.json"},
594594
})
595595

@@ -604,14 +604,32 @@ var _ = t.Describe("Image", func() {
604604
Expect(err).To(BeNil())
605605

606606
// When
607-
res, err := sut.PullImage(imageRef, &storage.ImageCopyOptions{
607+
res, err := sut.PullImage(context.Background(), imageRef, &storage.ImageCopyOptions{
608608
SourceCtx: &types.SystemContext{SignaturePolicyPath: "../../test/policy.json"},
609609
})
610610

611611
// Then
612612
Expect(err).NotTo(BeNil())
613613
Expect(res).To(BeNil())
614614
})
615+
616+
It("should fail on cancelled context", func() {
617+
// Given
618+
imageRef, err := references.ParseRegistryImageReferenceFromOutOfProcessData("localhost/busybox:latest")
619+
Expect(err).ToNot(HaveOccurred())
620+
621+
// When
622+
ctx, cancel := context.WithCancel(context.Background())
623+
cancel()
624+
res, err := sut.PullImage(ctx, imageRef, &storage.ImageCopyOptions{
625+
SourceCtx: &types.SystemContext{SignaturePolicyPath: "../../test/policy.json"},
626+
})
627+
628+
// Then
629+
Expect(err).To(HaveOccurred())
630+
Expect(err.Error()).To(ContainSubstring("context canceled"))
631+
Expect(res).To(BeNil())
632+
})
615633
})
616634

617635
t.Describe("CompileRegexpsForPinnedImages", func() {

internal/storage/runtime.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ func (r *runtimeService) CreatePodSandbox(systemContext *types.SystemContext, po
315315
if imageAuthFile != "" {
316316
sourceCtx.AuthFilePath = imageAuthFile
317317
}
318-
ref, err = r.storageImageServer.PullImage(pauseImage, &ImageCopyOptions{
318+
ref, err = r.storageImageServer.PullImage(context.Background(), pauseImage, &ImageCopyOptions{
319319
SourceCtx: &sourceCtx,
320320
DestinationCtx: systemContext,
321321
})

internal/storage/runtime_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ var _ = t.Describe("Runtime", func() {
765765
imageServerMock.EXPECT().GetStore().Return(storeMock),
766766
mockResolveReference(storeMock, storageTransportMock,
767767
"docker.io/library/pauseimagename:latest", "", ""),
768-
imageServerMock.EXPECT().PullImage(pauseImageRef, expectedCopyOptions).Return(pulledRef, nil),
768+
imageServerMock.EXPECT().PullImage(gomock.Any(), pauseImageRef, expectedCopyOptions).Return(pulledRef, nil),
769769
mockResolveReference(storeMock, storageTransportMock,
770770
"docker.io/library/pauseimagename:latest", "", imageID.IDStringForOutOfProcessConsumptionOnly()),
771771
imageServerMock.EXPECT().GetStore().Return(storeMock),

0 commit comments

Comments
 (0)