Skip to content

client/config: Wrap results and options#51078

Merged
austinvazquez merged 3 commits intomoby:masterfrom
vvoland:client-config-opts
Oct 20, 2025
Merged

client/config: Wrap results and options#51078
austinvazquez merged 3 commits intomoby:masterfrom
vvoland:client-config-opts

Conversation

@vvoland
Copy link
Contributor

@vvoland vvoland commented Oct 1, 2025

`client.ConfigCreate`, `client.ConfigList`, `client.ConfigInspectWithRaw`, `client.ConfigUpdate`, and `client.ConfigRemove` methods now accept option structs instead of positional arguments, and return dedicated result structs.

@vvoland vvoland added this to the 29.0.0 milestone Oct 1, 2025
@vvoland vvoland self-assigned this Oct 1, 2025
@vvoland vvoland added kind/refactor PR's that refactor, or clean-up code area/go-sdk labels Oct 1, 2025

// ConfigCreateResult holds the result from the ConfigCreate method.
type ConfigCreateResult struct {
Response swarm.ConfigCreateResponse
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use your thoughts on this; given that the API can be updated independent from the client module, we could have a situation where the API gained a new field, but the client may not handle it; in this case, likely not a huge issue as it directly unmarshals whatever it receives, but in other cases it could mean that the response is not handled, but the client returning a struct with fields not set and/or not handled correctly.

One option we have for that is to make the client define the counterpart to the response as well for the API version it was created for, e.g. similar to https://github.com/moby/moby/pull/50991/files

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm tricky. I think this is only an issue if the user depends on a newer version of the api package than the vendored client package right?

Wondering how wide that use case would be, and is it important enough for us to mirror many API types in the client package.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, definitely a tricky one; it's definitely possible it could happen if dependabot comes along and updates the API, although in many cases we may have a corresponding client release as well.

For some types we may want to do a conversion (at least the one I linked to exposes a reduced set of the fields on the client (TBD)).

One thing I did already account for is to make sure the client doesn't auto-magically "upgrade" by pinning the API version in the client module;

moby/client/client.go

Lines 93 to 100 in 5c877f4

// MaxAPIVersion is the highest REST API version supported by the client.
// If API-version negotiation is enabled (see [WithAPIVersionNegotiation],
// [Client.NegotiateAPIVersion]), the client may downgrade its API version.
// Similarly, the [WithVersion] and [WithVersionFromEnv] allow overriding
// the version.
//
// This version may be lower than the version of the api library module used.
const MaxAPIVersion = "1.52"

One option (to keep our options open) could be to define a local type that's a copy, not an alias, i.e.;

type ConfigCreateResponse swarm.ConfigCreateResponse

But I agree it's a thin line between handling this correctly and doing "too much" 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably could force the client package to depend on a specific api module version via replace rule 😅

Not sure if we should though...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace breaks go modules, or at least will cause go get to not work etc, so not a great option.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! And more importantly, "replace" is not seen by users of the module, so other than the above, they are ignored

@vvoland vvoland force-pushed the client-config-opts branch from fff361c to 4ec17cd Compare October 1, 2025 13:26
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall LGTM, but left a comment


// ConfigUpdate attempts to update a config
func (cli *Client) ConfigUpdate(ctx context.Context, id string, version swarm.Version, config swarm.ConfigSpec) error {
func (cli *Client) ConfigUpdate(ctx context.Context, id string, options ConfigUpdateOptions) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for this one, I wonder if version should stay a positional arg, because it's really required.

Interested to hear what others think though /cc @corhere

@austinvazquez
Copy link
Contributor

I rebased this one for the filters changes. I don't have opinions on the version argument though. :/

@vvoland vvoland force-pushed the client-config-opts branch 3 times, most recently from db0e8ea to 3dabd35 Compare October 17, 2025 09:42
@vvoland vvoland added impact/changelog impact/go-sdk Noteworthy (compatibility changes) in the Go SDK labels Oct 17, 2025
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments / thoughts ❤️ 🙈

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

cc @austinvazquez

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
@vvoland vvoland force-pushed the client-config-opts branch from d875a89 to abf5679 Compare October 20, 2025 20:29
@austinvazquez austinvazquez merged commit 0ad58d3 into moby:master Oct 20, 2025
184 of 185 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/dependencies area/go-sdk impact/changelog impact/go-sdk Noteworthy (compatibility changes) in the Go SDK kind/refactor PR's that refactor, or clean-up code module/client release-blocker PRs we want to block a release on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants