Skip to content

Conversation

@thaJeztah
Copy link
Member

relates to #42623

The errdefs package is used both to generate errors, but also has utilities
to convert errors originating from subsystems into a suitable HTTP error.

The API should always return a suitable HTTP error, and Conversion of errors
originating from subsystems will (generally) only be needed in the API server
(not the client).

This patch prevents the client from depending on grpc, containerd and distribution,
by moving the code to convert those errors to a separate "adapters" package.

The api/server/httputils.GetHTTPErrorStatusCode was un-deprecated, and modified
to include the default set of adapters.

- Description for the changelog

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

@thaJeztah thaJeztah added area/api API status/2-code-review kind/refactor PR's that refactor, or clean-up code labels Jul 12, 2021

containerderrors "github.com/containerd/containerd/errdefs"
"github.com/docker/distribution/registry/api/errcode"
"github.com/sirupsen/logrus"
Copy link
Member Author

Choose a reason for hiding this comment

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

We should get rid of logrus here

@thaJeztah
Copy link
Member Author

@dims @cpuguy83 not sure if this is the most suitable approach; let me know what you think

@dims
Copy link
Contributor

dims commented Jul 12, 2021

@thaJeztah as long as errdefs are not transitively needed from moby/moby/client, we are ok for now. this looks like too much of a change for sure. Let's hold this until we really need this, i'll POC a cadvisor change once #42623 lands and will let you know.

@dims
Copy link
Contributor

dims commented Jul 12, 2021

@thaJeztah bad news ...

go: finding module for package github.com/containerd/containerd/errdefs
github.com/google/cadvisor/container/docker imports
	github.com/docker/docker/client imports
	github.com/docker/docker/errdefs imports
	github.com/containerd/containerd/errdefs

@dims
Copy link
Contributor

dims commented Jul 12, 2021

@thaJeztah one more problem after applying the commit in this PR

github.com/google/cadvisor/container/docker imports
	github.com/docker/docker/client tested by
	github.com/docker/docker/client.test imports
	github.com/docker/docker/api/server/httputils imports
	github.com/docker/docker/errdefs/adapter imports
	github.com/containerd/containerd/errdefs

@thaJeztah thaJeztah force-pushed the errdefs_reduce_client_deps branch from ac75bbd to 464f248 Compare July 12, 2021 15:16
@dims
Copy link
Contributor

dims commented Jul 12, 2021

@thaJeztah the new commit works well! ( 464f248 ) thanks. i don't see this problem any more

Copy link
Member

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

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

Having anything other than the base definitions in errdefs seems wrong.

I don't remember the change that moved stuff around, but none of this seems correct and a generic Adapter seems like too much abstraction.

In client/ we should only be outputting for the most part, errors that implement something in errdefs and we should generally only be consuming errors that come across the API.

In api/ we should only be receiving errors that implement something from errdefs and outputing the relavent status code + messages.

@thaJeztah
Copy link
Member Author

I don't remember the change that moved stuff around, but none of this seems correct and a generic Adapter seems like too much abstraction.

I think that may have been my doing. We had code to convert from/to errdefs and to/from HTTP status code in various locations, and (from that perspective) it seemed to make sense to have the errdefs package be the canonical place to provide conversions in both directions.

In client/ we should only be outputting for the most part, errors that implement something in errdefs and we should generally only be consuming errors that come across the API.

So currently the client uses errdefs to convert HTTP status codes returned by the API back to errdefs errors (added in #38689). I think that makes sense (I recall string matching in various code using the client because it returned no information whatsoever).

In api/ we should only be receiving errors that implement something from errdefs and outputing the relavent status code + messages.

So conversion from other subsystems was added over time;

For those above, perhaps they should live in a client specific to each (e.g. libcontainerd/client for containerd ?) and convert to our errdef errors?

conn, _, errHijack := hijacker.Hijack()
if errHijack == nil {
statusCode := errdefs.GetHTTPErrorStatusCode(err)
statusCode := errdefs.GetHTTPErrorStatusCode(err, adapter.All()...)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any reason why the adapters are not hidden inside GetHTTPErrorStatusCode? other than that LGTM

@dims
Copy link
Contributor

dims commented Oct 23, 2021

@thaJeztah let's please reach consensus on this one (with a hopefully quick tag/release!). this is holding up a long-dependency-update-chain in kubernetes.

  • allows cadvisor to reduce footprint of docker/docker in its deps.
  • which then allows us to update containerd + containerd-api (from 1.6 branch) + moby/moby + cadvisor into kubernetes/kubernetes.

@thaJeztah thaJeztah force-pushed the errdefs_reduce_client_deps branch from 464f248 to 1efa7ca Compare March 6, 2022 09:50
@thaJeztah thaJeztah added this to the 21.xx milestone Mar 6, 2022
@thaJeztah thaJeztah force-pushed the errdefs_reduce_client_deps branch from 1efa7ca to 5cdb258 Compare March 6, 2022 17:06
The errdefs package is used both to generate errors, but also has utilities
to convert errors originating from subsystems into a suitable HTTP error.

The API should always return a suitable HTTP error, and Conversion of errors
originating from subsystems will (generally) only be needed in the API server
(not the client).

This patch prevents the client from depending on grpc, containerd and distribution,
by moving the code to convert those errors to a separate "adapters" package.

The api/server/httputils.GetHTTPErrorStatusCode was un-deprecated, and modified
to include the default set of adapters.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Unfortunately, the previous change didn't produce the desired result,
because the client uses httputils in a test:

    github.com/google/cadvisor/container/docker imports
	github.com/docker/docker/client tested by
	github.com/docker/docker/client.test imports
	github.com/docker/docker/api/server/httputils imports
	github.com/docker/docker/errdefs/adapter imports
	github.com/containerd/containerd/errdefs

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

I had a draft alternative to this one, which does not include the Adapter interface, and just moves everything together into a package that's only used by the API server; I just pushed it as an alternative PR; #43399 - hopefully that's able to unblock this.

@thaJeztah
Copy link
Member Author

Replaced by #43399, which was just merged 👍

@thaJeztah thaJeztah deleted the errdefs_reduce_client_deps branch March 22, 2022 10:06
@dims
Copy link
Contributor

dims commented Mar 22, 2022

thanks a ton @thaJeztah

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

Labels

area/api API kind/refactor PR's that refactor, or clean-up code status/2-code-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants