Skip to content

Conversation

@rumpl
Copy link
Owner

@rumpl rumpl commented Aug 8, 2022

This change fixes multiple things:

  • pass ctx instead of nil because we need it while computing the layer
    size
  • don't return an error if the container is not found during the layer
    size calculation, if a container is not found it means that it exited
  • create the container with the image it was created from, the image is
    used when computing the layer size

@rumpl rumpl requested review from ndeloof, thaJeztah and vvoland August 8, 2022 12:16
c, err := i.client.ContainerService().Get(ctx, containerID)
// Get() returns an error if the container is not found, we return 0, 0 in this case and
// not an error because this will happen when the container exited.
if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess we could ignore the error; perhaps for errors that are not "not found", we could log them; not sure if either is best handled in this function or by the caller though (haven't looked closely where it's all used)

Copy link
Owner Author

Choose a reason for hiding this comment

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

Looks like the error is not a errdefs.IsNotFound :/

Output from the cli:

Error response from daemon: failed to retrieve container list: container "d4ee0fe826d4043c1b8eb619d959f43ec6bd01c2440bf6a0b1f8d39d12233f34" in namespace "moby": not found

Daemon logs:

DEBU[2022-08-08T14:33:29.885930020+02:00] FIXME: Got an API for which error does not match any expected type!!!: failed to retrieve container list: container "d4ee0fe826d4043c1b8eb619d959f43ec6bd01c2440bf6a0b1f8d39d12233f34" in namespace "moby": not found  error_type="*errors.errorString" module=api

The documentation of the Get method says:

// Container object is returned on success. If the id is not known to the
// store, an error will be returned.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you use the containerd errdefs? (not by accident the moby errdefs?)

Copy link
Owner Author

Choose a reason for hiding this comment

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

OK nevermind, I imported the wrong package...

Copy link
Owner Author

Choose a reason for hiding this comment

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

Fixed, thanks!

Copy link
Collaborator

Choose a reason for hiding this comment

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

But yeah, if it's the only error it can return, it's probably fine (for now); it's a bit scary though to ignore "any" error (in case things change in containerd)

Copy link
Owner Author

Choose a reason for hiding this comment

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

Did you use the containerd errdefs? (not by accident the moby errdefs?)

This is exactly what happened :D

Copy link
Collaborator

Choose a reason for hiding this comment

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

I got bitten by the errdefs a few times too. Maybe we could we have a soft convention to import the containerd errdefs as containerderrdefs/cerrdefs/c8derrdefs?

c, err := i.client.ContainerService().Get(ctx, containerID)
// Get() returns an error if the container is not found, we return 0, 0 in this case and
// not an error because this will happen when the container exited.
if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I got bitten by the errdefs a few times too. Maybe we could we have a soft convention to import the containerd errdefs as containerderrdefs/cerrdefs/c8derrdefs?

This change fixes multiple things:
* pass ctx instead of nil because we need it while computing the layer
  size
* don't return an error if the container is not found during the layer
  size calculation, if a container is not found it means that it exited
* create the container with the image it was created from, the image is
  used when computing the layer size

Signed-off-by: Djordje Lukic <[email protected]>
"fmt"

"github.com/containerd/containerd"
"github.com/containerd/containerd/errdefs"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps use an alias for this one to prevent that. Looks like we've not been consistent on "what" alias to use in upstream (something we should fix); here's the existing list of aliases "pick one" and we should then update upstream to use the same everywhere :)

Screenshot 2022-08-08 at 15 10 09

And in BuildKit;

Screenshot 2022-08-08 at 15 12 20

Copy link
Owner Author

Choose a reason for hiding this comment

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

What a mess, I'll update to cerrdefs

@rumpl rumpl merged commit e274a6e into c8d Aug 8, 2022
@rumpl rumpl deleted the fix-system-df branch August 8, 2022 14:19
Copy link
Collaborator

@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

(left two comments for consideration)

containertypes "github.com/docker/docker/api/types/container"
"github.com/docker/docker/container"
"github.com/docker/docker/errdefs"
v1 "github.com/opencontainers/image-spec/specs-go/v1"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think in most places, this is currently aliased as "specs"

if daemon.UsesSnapshotter() {
newContainerOpts = append(newContainerOpts, containerd.WithSnapshotter(containerd.DefaultSnapshotter))
newContainerOpts = append(newContainerOpts, containerd.WithSnapshot(container.ID))
c8dImge, err := daemon.imageService.(containerdImage).GetContainerdImage(ctx, container.Config.Image, &v1.Platform{})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Arf, I should've looked at the whole diff instead of leaving one comment at a time 🙈❤️

I'd use either "c8dImage" or "c8dImg" (the "e" at the end now looks a bit odd)

@thaJeztah
Copy link
Collaborator

This one should be upstreamed together with #19

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

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants