Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: clean up an orphaned etchosts directory for the container that failed to create #3819

Conversation

haytok
Copy link
Contributor

@haytok haytok commented Jan 15, 2025

When specifying 22200-22299:22200-22299 for -p optinn in running nerdctl
run, the following errors occur.

$ nerdctl run --rm -p 22200-22299:22200-22299 alpine sh
FATA[0000] create container failed validation: containers.Labels: label key and value length (7714 bytes) greater than maximum size (4096 bytes), key: nerdctl/ports: invalid argument

This error is expected behavior in nerdctl.

However, the etchosts directory for this container has not been cleaned
up, even though the container has not been created.

Specifically, the following directory for the container remains without
being cleaned up.

$ ls ~/.local/share/nerdctl/1935db59/etchosts/default/
ea9c09bfdbc525db0b2cfdf3632ddf7c0e58918044acc626019f2fc4e1167573

Therefore, this PR creates the following three commits to clean up an
orphaned directory when the nerdctl run command fails to create a
container with an invalid value for the -p option.

  1. Refactor TestRunWithInvalidPortThenCleanUp in
    cmd/nerdctl/container/container_run_network_linux_test.go based on the
    Principles in the following document
  1. Add the logic to clean up an orphaned etchosts directory for the
    container that failed to create

  2. Add an test for added logic to TestRunWithInvalidPortThenCleanUp

This commit refactors TestRunWithInvalidPortThenCleanUp in
cmd/nerdctl/container/container_run_network_linux_test.go based on the
principles in the following document.

- https://github.com/containerd/nerdctl/tree/main/docs/testing#principles

Signed-off-by: Hayato Kiwata <haytok@amazon.co.jp>
This commit adds the logic to clean up an orphaned etchosts directory for
the container that failed to create.

Signed-off-by: Hayato Kiwata <haytok@amazon.co.jp>
This commit adds an test for added logic to clean up an orphaned etchosts
directory for the container that failed to create to
TestRunWithInvalidPortThenCleanUp.

Signed-off-by: Hayato Kiwata <haytok@amazon.co.jp>
@AkihiroSuda AkihiroSuda added this to the v2.0.3 milestone Jan 17, 2025
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

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

Thanks

@AkihiroSuda AkihiroSuda merged commit f15d0ad into containerd:main Jan 17, 2025
30 checks passed
@haytok haytok deleted the fix-to-clean-up-an-orphaned-etchosts-directory branch January 17, 2025 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants