Skip to content

Deprecate api/types/strslice.StrSlice and remove its use#50292

Merged
thaJeztah merged 1 commit intomoby:masterfrom
thaJeztah:deprecate_strslice
Aug 8, 2025
Merged

Deprecate api/types/strslice.StrSlice and remove its use#50292
thaJeztah merged 1 commit intomoby:masterfrom
thaJeztah:deprecate_strslice

Conversation

@thaJeztah
Copy link
Member

relates to;

The strslice.StrSlice type is a string-slice with a custom JSON Unmarshal function to provide backward-compatibility with older API requests from before docker 1.7 (see moby@17d6f00 and moby@ea4a067), which used a string instead of an array of strings for some fields (Cmd, Entrypoint).

We no longer support those API versions, and we no longer support pulling v1 images that may contain such a config, so we can deprecate the type and remove its use.

- What I did

- How I did it

- How to verify it

- Human readable description for the release notes

api/types/strslice: deprecate StrSlice in favor of using a regular `[]string`.

- A picture of a cute animal (not mandatory but encouraged)

@thaJeztah thaJeztah added this to the 29.0.0 milestone Jul 1, 2025
}
//
// Deprecated: this type was used for compatibility with deprecated API versions. Use []string instead.
type StrSlice = []string
Copy link
Member Author

Choose a reason for hiding this comment

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

Changed this to an alias for []string so that any uses of it would just become a no-op.

@thaJeztah
Copy link
Member Author

And some tests that use invalid requests (current API versions only document / support string-slice)

=== FAIL: amd64.integration-cli TestDockerAPISuite/TestContainerAPIPostCreateNull (0.01s)
    docker_api_containers_test.go:778: assertion failed: 400 (res.StatusCode int) != 201 (http.StatusCreated int)
    --- FAIL: TestDockerAPISuite/TestContainerAPIPostCreateNull (0.01s)

=== FAIL: amd64.integration-cli TestDockerAPISuite/TestCreateWithTooLowMemoryLimit (0.00s)
    docker_api_containers_test.go:815: assertion failed: string "{\"message\":\"invalid JSON: json: cannot unmarshal string into Go struct field CreateRequest.Config.Cmd of type []string\"}\n" does not contain "Minimum memory limit allowed is 6MB"
    --- FAIL: TestDockerAPISuite/TestCreateWithTooLowMemoryLimit (0.00s)

=== FAIL: amd64.integration-cli TestDockerAPISuite/TestPostContainerAPICreateWithStringOrSliceEntrypoint (0.28s)
    docker_api_containers_test.go:1106: assertion failed: 
        Command:  /usr/local/cli-integration/docker start -a echotest2
        ExitCode: 1
        Error:    exit status 1
        Stdout:   
        Stderr:   Error: No such container: echotest2
        
        
        Failures:
        ExitCode was 1 expected 0
        Expected no error
    --- FAIL: TestDockerAPISuite/TestPostContainerAPICreateWithStringOrSliceEntrypoint (0.28s)

=== FAIL: amd64.integration-cli TestDockerAPISuite/TestPostContainersCreateWithStringOrSliceCmd (0.26s)
    docker_api_containers_test.go:1133: assertion failed: 
        Command:  /usr/local/cli-integration/docker start -a echotest2
        ExitCode: 1
        Error:    exit status 1
        Stdout:   
        Stderr:   Error: No such container: echotest2
        
        
        Failures:
        ExitCode was 1 expected 0
        Expected no error
    --- FAIL: TestDockerAPISuite/TestPostContainersCreateWithStringOrSliceCmd (0.26s)

Comment on lines -439 to +438
CapAdd strslice.StrSlice // List of kernel capabilities to add to the container
CapDrop strslice.StrSlice // List of kernel capabilities to remove from the container
CapAdd []string // List of kernel capabilities to add to the container
CapDrop []string // List of kernel capabilities to remove from the container
Copy link
Member Author

Choose a reason for hiding this comment

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

Even if we do want to continue supporting the old format; these two definitely look wrong, as these fields never supported a string (instead of a slice) AFAIK.

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like I was wrong there; Hmm, so CapAdd/CapDrop;

@thaJeztah thaJeztah marked this pull request as draft July 1, 2025 14:54
@thaJeztah thaJeztah force-pushed the deprecate_strslice branch from 96a5500 to 8f58969 Compare July 3, 2025 13:06
@thaJeztah thaJeztah force-pushed the deprecate_strslice branch 4 times, most recently from f521274 to 3cc0361 Compare July 10, 2025 15:04
@thompson-shaun thompson-shaun moved this from New to Complete in 🔦 Maintainer spotlight Jul 10, 2025
@thaJeztah thaJeztah marked this pull request as ready for review July 10, 2025 18:30
@thaJeztah thaJeztah requested a review from tonistiigi as a code owner July 10, 2025 18:30
@thaJeztah thaJeztah force-pushed the deprecate_strslice branch 4 times, most recently from b65ffc0 to f04c4cc Compare July 23, 2025 13:36
@thaJeztah thaJeztah force-pushed the deprecate_strslice branch from f04c4cc to d4fb340 Compare July 25, 2025 11:53
@thaJeztah thaJeztah force-pushed the deprecate_strslice branch 2 times, most recently from 0eb1cf2 to 0f813a4 Compare July 28, 2025 20:29
@thaJeztah thaJeztah force-pushed the deprecate_strslice branch from 0f813a4 to 377f7b2 Compare August 6, 2025 10:59
@thompson-shaun thompson-shaun added the release-blocker PRs we want to block a release on label Aug 6, 2025
@austinvazquez
Copy link
Contributor

Rebased to bring in some of the changes that have been merged to master.

@thaJeztah
Copy link
Member Author

Definitely some weird things happening; checksum failiures in various places. Not sure if these are issues with the fixture. Also worth noting (just in case) that docker/dockerfile:v1.7.1 was put to "latest" earlier Today; which COULD be relevant if there's something with building the dev-container?

=== FAIL: amd64.docker.docker.integration.container TestInspectImageManifestPlatform/amd64_image_on_non-amd64_host (0.06s)
    inspect_test.go:123: assertion failed: error is not nil: Error response from daemon: apply layer error for "": wrong diff id calculated on extraction "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
=== FAIL: amd64.docker.docker.integration.daemon TestLiveRestore/volume_references/image_mount (0.08s)
    daemon_test.go:679: assertion failed: error is not nil: Error response from daemon: apply layer error for "": wrong diff id calculated on extraction "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
        --- FAIL: TestLiveRestore/volume_references/image_mount (0.08s)
=== FAIL: amd64.docker.docker.integration.volume TestRunMountImageMultipleTimes (0.14s)
    mount_test.go:370: assertion failed: error is not nil: Error response from daemon: apply layer error for "": wrong diff id calculated on extraction "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"

@thaJeztah
Copy link
Member Author

Error looks to come from containerd vendor; not sure why the i.Name() is empty, but maybe that's expected

for _, layer := range layers {
unpacked, err = rootfs.ApplyLayerWithOpts(ctx, layer, chain, sn, a, config.SnapshotOpts, config.ApplyOpts)
if err != nil {
return fmt.Errorf("apply layer error for %q: %w", i.Name(), err)

The strslice.StrSlice type is a string-slice with a custom JSON Unmarshal
function to provide backward-compatibility with older API requests from
before docker 1.7 (see [moby/moby@17d6f00] and [moby/moby@ea4a067]), which used a
string instead of an array of strings for some fields (Cmd, Entrypoint).

We no longer support those API versions, and we no longer support pulling
v1 images that may contain such a config, so we can deprecate the type
and remove its use.

[moby/moby@17d6f00]: moby@17d6f00
[moby/moby@ea4a067]: moby@ea4a067

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah
Copy link
Member Author

I think this should be ready to go, but doing a quick check with the BuildKit folks. The "short" story is that;

  • Our API has not supported "string" for these fields since... forever, so it's good to remove that type from our API
  • Likewise, the API server SHOULD not have to be able to handle those (as the API spec doesn't define it to be valid)
  • ☝️ if REALLY needed, we can add handling for those in the API server, i.e., add an ad-hoc struct to unmarshal or otherwise.
  • ❓ the only concern (hence "ask BuildKit folks") is container / image configs. Would there be images that somehow contain a (otherwise "invalid") config having a string for these fields?
  • ❓ does BuildKit still contain its own special handling for those, and if it encounters, does it preserve the invalid fields, or does it convert the invalid to become valid ([]string)?

This type is one of those poorly documented cases where we deprecated something, but (without proper versioning the API handling) just left the old in as well. Which makes sense for "post v1.0" releases, but in this case it was to bridge compatibility between early v0.x versions.

@thaJeztah
Copy link
Member Author

Chatted with @crazy-max - and looks like BuildKit has no special handling for this; it uses the OCI types for these fields, which don't support the string format, so (famous last words) I think we should be fine.

As mentioned; all handling was on unmarshalling (daemon side), so it's good to not have that implementation detail leak into the API module.

I'm bringing this one in.

We can probably remove the "deprecated" alias (as it's a new module), but I'm sure we have more cleanup rounds to make in the client and api modules.

@thaJeztah thaJeztah merged commit 846cf4b into moby:master Aug 8, 2025
175 checks passed
@thaJeztah thaJeztah deleted the deprecate_strslice branch August 8, 2025 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/api API area/go-sdk impact/deprecation impact/go-sdk Noteworthy (compatibility changes) in the Go SDK release-blocker PRs we want to block a release on status/2-code-review

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants