-
Notifications
You must be signed in to change notification settings - Fork 133
json-proxy: Add GetEngineConfig to advertise retry policy #951
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cgwalters
wants to merge
1
commit into
podman-container-tools:main
Choose a base branch
from
cgwalters:proxy-engine-config
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,10 +10,12 @@ import ( | |
| "os" | ||
| "sync" | ||
| "syscall" | ||
| "time" | ||
|
|
||
| "github.com/opencontainers/go-digest" | ||
| imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1" | ||
| "github.com/sirupsen/logrus" | ||
| "go.podman.io/common/pkg/config" | ||
| "go.podman.io/image/v5/image" | ||
| "go.podman.io/image/v5/manifest" | ||
| "go.podman.io/image/v5/pkg/blobinfocache" | ||
|
|
@@ -106,6 +108,54 @@ func (h *handler) Initialize(ctx context.Context, args []any) (replyBuf, error) | |
| return r, nil | ||
| } | ||
|
|
||
| // GetEngineConfig returns a curated subset of the host containers.conf | ||
| // [engine] settings (new in 0.2.9). Today this is the retry policy; clients | ||
| // use it to drive retries with the same defaults as `podman pull` without | ||
| // having to read containers.conf themselves. | ||
| // | ||
| // Note the proxy only advertises the configuration; it does not perform | ||
| // retries itself, since a partially streamed blob cannot be transparently | ||
| // resumed. | ||
| func (h *handler) GetEngineConfig(_ context.Context, args []any) (replyBuf, error) { | ||
| h.lock.Lock() | ||
| defer h.lock.Unlock() | ||
|
|
||
| var ret replyBuf | ||
|
|
||
| if h.sysctx == nil { | ||
| return ret, errors.New("client error: must invoke Initialize") | ||
| } | ||
| if len(args) != 0 { | ||
| return ret, errors.New("invalid request, expecting zero arguments") | ||
| } | ||
|
|
||
| // config.Default() memoizes internally, so this is cheap to call here. | ||
| cfg, err := config.Default() | ||
| if err != nil { | ||
| return ret, fmt.Errorf("loading containers.conf: %w", err) | ||
| } | ||
|
|
||
| ec := engineConfig{ | ||
| Retry: cfg.Engine.Retry, | ||
| } | ||
| // An empty retry_delay means "use exponential backoff"; only advertise a | ||
| // concrete value when one is configured. We normalize to milliseconds so | ||
| // clients don't have to parse Go's duration syntax. | ||
| if cfg.Engine.RetryDelay != "" { | ||
| d, err := time.ParseDuration(cfg.Engine.RetryDelay) | ||
| if err != nil { | ||
| return ret, fmt.Errorf("parsing containers.conf retry_delay %q: %w", cfg.Engine.RetryDelay, err) | ||
| } | ||
| // A negative delay is meaningless; treat it as unset (exponential | ||
| // backoff) rather than advertising a nonsensical value to clients. | ||
|
Comment on lines
+149
to
+150
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| if ms := d.Milliseconds(); ms > 0 { | ||
| ec.RetryDelayMS = &ms | ||
| } | ||
| } | ||
|
|
||
| return replyBuf{value: ec}, nil | ||
| } | ||
|
|
||
| // OpenImage accepts a string image reference i.e. TRANSPORT:REF - like `skopeo copy`. | ||
| // The return value is an opaque integer handle. | ||
| func (h *handler) OpenImage(ctx context.Context, args []any) (replyBuf, error) { | ||
|
|
@@ -706,6 +756,8 @@ func (h *handler) processRequest(ctx context.Context, readBytes []byte) (rb repl | |
| switch req.Method { | ||
| case "Initialize": | ||
| rb, err = h.Initialize(ctx, req.Args) | ||
| case "GetEngineConfig": | ||
| rb, err = h.GetEngineConfig(ctx, req.Args) | ||
| case "OpenImage": | ||
| rb, err = h.OpenImage(ctx, req.Args) | ||
| case "OpenImageOptional": | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know where little about that proxy but since it is used by skopeo never depended on containers.conf in any way.
This adds a large dependency chain thus to skopeo and makes it care about something it never did before, I do not maintain skopeo so I do not have a strong opinion but it is a design choice that likely should be looked at carefully.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, yes. That’s pretty likely to be a big issue.