Skip to content

api/types/container: remove StateStatus, NewStateStatus#50493

Draft
thaJeztah wants to merge 3 commits intomoby:masterfrom
thaJeztah:move_back_StateStatus
Draft

api/types/container: remove StateStatus, NewStateStatus#50493
thaJeztah wants to merge 3 commits intomoby:masterfrom
thaJeztah:move_back_StateStatus

Conversation

@thaJeztah
Copy link
Copy Markdown
Member

These types used to be internal to the container package, but were moved to the API in 1001021.

However, the StateStatus type is only used internally; it's used as an intermediate type because container.State contains a sync.Mutex field which would make copying it unsafe (see moby@2998945).

But, StateStatus is not the type returned by the API, which is container.WaitResponse, so now we ended up changing the type yet again in containerRouter.postContainersWait to convert it to the API response type and marshal it as JSON. The whole process of converting meant that we were also changing error-message strings to errors, and back again.

This patch rewrites the backend to use the container.WaitResponse type directly. While the type isn't "pretty" (the nested WaitExitError should probably be swapped for our common types.ErrorResponse), at least it removes a confusing type in the API (that's only used internally), and the aforementioned conversions.

- Human readable description for the release notes

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

}

// StateStatus is used to return container wait results.
// Implements exec.ExitCode interface.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Still double-checking, but the only interface I found was ExitCoder in swarmkit;

// ExitCoder is implemented by errors that have an exit code.
type ExitCoder interface {
// ExitCode returns the exit code.
ExitCode() int
}

Which is matched here;
https://github.com/moby/moby/blob/master/vendor/github.com/moby/swarmkit/v2/agent/exec/controller.go#L195-L198

Which doesn't consume the response directly, but uses a exitError to satisfy the interface;

waitC, err := r.adapter.wait(ctx)
if err != nil {
return err
}
if status := <-waitC; status.ExitCode() != 0 {
exitErr := &exitError{
code: status.ExitCode(),
}

@thaJeztah thaJeztah force-pushed the move_back_StateStatus branch from 39cd61f to ae17cf3 Compare July 23, 2025 18:56
@thaJeztah
Copy link
Copy Markdown
Member Author

OK; this needs some work. I may go back to my original plan, which was to move the type back to daemon/container

These types used to be internal to the container package, but were
moved to the API in 1001021.

However, the `StateStatus` type is only used internally; it's used
as an intermediate type because [`container.State`] contains a sync.Mutex
field which would make copying it unsafe (see [moby/moby@2998945]).

But, `StateStatus` is not the type returned by the API, which is
[`container.WaitResponse`], so now we ended up changing the type
yet again in [`containerRouter.postContainersWait`] to convert
it to the API response type and marshal it as JSON. The whole process
of converting meant that we were also changing error-message strings
to errors, and back again.

This patch rewrites the backend to use the `container.WaitResponse`
type directly. While the type isn't "pretty" (the nested `WaitExitError`
should probably be swapped for our common [`types.ErrorResponse`]), at
least it removes a confusing type in the API (that's only used internally),
and the aforementioned conversions.

[`container.State`]: https://github.com/moby/moby/blob/19e79906cb347ab12deaade16bf9d82c41d777c4/container/state.go#L15-L23
[moby/moby@2998945]: moby@2998945
[`container.WaitResponse`]: https://github.com/moby/moby/blob/496c555d7528755a97455f58f99e73ebaf433c2c/api/types/container/wait_response.go#L6-L18
[`containerRouter.postContainersWait`]: https://github.com/moby/moby/blob/496c555d7528755a97455f58f99e73ebaf433c2c/daemon/server/router/container/container_routes.go#L381-L399
[`types.ErrorResponse`]: https://github.com/moby/moby/blob/496c555d7528755a97455f58f99e73ebaf433c2c/api/types/error_response.go#L6-L13

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah thaJeztah force-pushed the move_back_StateStatus branch from ae17cf3 to f4c43eb Compare July 27, 2025 11:40
@thaJeztah
Copy link
Copy Markdown
Member Author

Yeah, this needs more work

=== CONT  TestBuildWithRemoveAndForceRemove/successful_build_with_remove_and_force_remove
    build_test.go:117: assertion failed: error is not nil: unexpected EOF
=== CONT  TestBuildWithRemoveAndForceRemove/failed_build_with_remove
=== CONT  TestBuildWithRemoveAndForceRemove/successful_build_with_remove
    build_test.go:117: assertion failed: error is not nil: unexpected EOF
    build_test.go:117: assertion failed: error is not nil: unexpected EOF
--- FAIL: TestBuildWithRemoveAndForceRemove (0.03s)
    --- FAIL: TestBuildWithRemoveAndForceRemove/failed_build_with_no_removal (0.51s)
    --- PASS: TestBuildWithRemoveAndForceRemove/successful_build_with_remove_and_force_remove (0.56s)
    --- FAIL: TestBuildWithRemoveAndForceRemove/failed_build_with_remove_and_force_remove (0.60s)
    --- PASS: TestBuildWithRemoveAndForceRemove/successful_build_with_no_removal (0.70s)
    --- FAIL: TestBuildWithRemoveAndForceRemove/failed_build_with_remove (0.49s)
    --- PASS: TestBuildWithRemoveAndForceRemove/successful_build_with_remove (0.52s)

=== Failed
=== FAIL: amd64.integration.network TestServiceWithDefaultAddressPoolInit (16.46s)
    service_test.go:441: timeout hit after 15s: running task count at 0 waiting for 1 (total tasks: 4)

--- FAIL: TestEndpointWithCustomIfname (21.56s)
=== RUN   TestHostPortMappings
    overlay_test.go:90: timeout hit after 15s: running task count at 0 waiting for 1 (total tasks: 4)
--- FAIL: TestHostPortMappings (16.47s)
FAIL
coverage: [no statements]

=== Failed
=== FAIL: amd64.integration.network.overlay TestEndpointWithCustomIfname (21.56s)
    overlay_test.go:44: assertion failed: error is not nil: Error response from daemon: failed to set up container networking: attaching to network failed, make sure your network options are correct and check manager logs: context deadline exceeded

=== FAIL: amd64.integration.network.overlay TestHostPortMappings (16.47s)
    overlay_test.go:90: timeout hit after 15s: running task count at 0 waiting for 1 (total tasks: 4)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants