Skip to content

Move *.go files for subcommand out main package #1631

Closed

Description

@sctb512

What is the problem you're trying to solve

I wish to import the nerdctl subcommand package to add some new features.

Describe the solution you'd like

Move *.go files for subcommand out of the main package so we can import it.

Additional context

In addition, are there any other ways to implement this?

Activity

  1. self-assigned this
    on Dec 11, 2022
  2. AkihiroSuda commented on Dec 16, 2022

    @AkihiroSuda
    Member

    @sctb512

    What function actually do you want to be exposed?

  3. AkihiroSuda commented on Dec 16, 2022

    @AkihiroSuda
    Member

    Cross-posting #1639 (comment)

    Sorry, I have to admit that I'm unable to review/carry this amount of PR 🙇‍♂️

    Possible plan B might be incrementally separating out cobra-independent functions into pkg directory but I'm not sure we need to do so because codes under cmd/nerdctl are tightly coupled.

    Yes, this should be done in a series of small PRs if we want to continue this. e.g.,

    • PR 1: move cobra-independent functions into pkg/...
    • PR 2: split other common functions into somewhere like cmd/nerdctl/cmdpkg/...
    • PR 3: split the client cmdpkg
    • PR 4: split nerdctl namespace
    • PR 5: split nerdctl apparmor
    • PR 6: split nerdctl builder
    • PR 7: ...

    The git diff has to be kept minimal for ease of reviewing and potential rebasing. It mustn't contain unnecessary changes such as exposing private functions. Some private functions could be exposed, but it has to be done in a separate PR.

    Also, there shouldn't be the common package that is likely to result in being the home of random mutually irrelevant functions; the common package has to be split to multiple small cmdpkgs with clear purposes.

    We also have to revisit whether we really have to split cmd/nerdctl in the first place ( #1631 (comment) ), as the functions in cmd/nerdctl aren't really designed to be imported from other projects. There might be some functions that can be safely imported from third parties, but they should be rather decoupled from the CLI and should be moved to pkg/... .

    Then there might be no good reason to split cmd/nerdctl ? I expected that splitting cmd/nerdctl will increase the code readability as a side effect, but improper splitting will rather decrease the readability, so it has to be done seriously carefully.

    @Zheaoli Thanks anyway for your hard work, and hope you will get well soon! 👍

  4. sctb512 commented on Dec 21, 2022

    @sctb512
    MemberAuthor

    @sctb512

    What function actually do you want to be exposed?

    Thanks for your reply. I want to add features for nerdctl run subcommand. If we can split subcommand into a package, It will benefit developers.

    There are two reasons:

    1. The files in cmd/nerdctl are too many.

    2. We cannot import them as packages because they all belong to the main.

  5. sctb512 commented on Dec 21, 2022

    @sctb512
    MemberAuthor

    Moreover, I want to add a feature for nerdctl run to record accessed files when a container is running. If it is acceptable, We could consider adding it to the nerdctl source code and contributing it to the community.

  6. sctb512 commented on Dec 21, 2022

    @sctb512
    MemberAuthor

    There is some information about it. containerd/nydus-snapshotter#228

  7. AkihiroSuda commented on Dec 21, 2022

    @AkihiroSuda
    Member
  8. sctb512 commented on Dec 21, 2022

    @sctb512
    MemberAuthor

    Also, there shouldn't be the common package that is likely to result in being the home of random mutually irrelevant functions; the common package has to be split to multiple small cmdpkgs with clear purposes.
    We also have to revisit whether we really have to split cmd/nerdctl in the first place ( #1631 (comment) ), as the functions in cmd/nerdctl aren't really designed to be imported from other projects. There might be some functions that can be safely imported from third parties, but they should be rather decoupled from the CLI and should be moved to pkg/... .
    Then there might be no good reason to split cmd/nerdctl ? I expected that splitting cmd/nerdctl will increase the code readability as a side effect, but improper splitting will rather decrease the readability, so it has to be done seriously carefully.

    Yes, I couldn't agree more that we should consider it carefully. One reason for this is to add private features for nerdctl.

  9. sctb512 commented on Feb 9, 2023

    @sctb512
    MemberAuthor

    May we close this issue?

  10. djdongjin commented on Feb 9, 2023

    @djdongjin
    Member

    Hi @sctb512, we're refactoring nerdctl as you may see above (#1680). If you feel the refactor (or the direction the refactor towards) is sufficient for your use case or you find workaround bypassing the necessary refactor, please feel free to close.

  11. sctb512 commented on Feb 9, 2023

    @sctb512
    MemberAuthor

    We are considering implementing containerd/nydus-snapshotter#228 with OCI hooks, so we can currently bypass this refactor. However, the feature mentioned in this PR is also useful for developers. Let's close this issue after #1680 is finished.

  12. apostasie commented on Nov 30, 2024

    @apostasie
    Contributor

    @AkihiroSuda I assume this is what we did with #3379 and #3383 ?

    Shall this be closed?

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions