-
Notifications
You must be signed in to change notification settings - Fork 589
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
Refactor the package structure in cmd/nerdctl #1639
Conversation
95f23b0
to
b05df8f
Compare
154b510
to
4d114ab
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: integration
might be a better name than e2e
nice catch( |
4d114ab
to
50cc8b3
Compare
50cc8b3
to
3d2fcd9
Compare
cmd/nerdctl/event/events.go
Outdated
@@ -26,6 +26,8 @@ import ( | |||
|
|||
"github.com/containerd/containerd/events" | |||
"github.com/containerd/containerd/log" | |||
client2 "github.com/containerd/nerdctl/cmd/nerdctl/client" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer the package name to be like ncclient
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I will clean dirty name when I pass all CI(lol
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another suggestion is ndclient
😃 since nd
reads more similar to nerd
ctl
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd argue that the contaiNERD client library is also "nerd" 🤓
cmd/nerdctl/event/events.go
Outdated
@@ -26,6 +26,8 @@ import ( | |||
|
|||
"github.com/containerd/containerd/events" | |||
"github.com/containerd/containerd/log" | |||
client2 "github.com/containerd/nerdctl/cmd/nerdctl/client" | |||
fmt2 "github.com/containerd/nerdctl/cmd/nerdctl/utils" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer the package name to be something like utils/fmtutil
.
cmd/nerdctl/create/create.go
Outdated
@@ -14,16 +14,20 @@ | |||
limitations under the License. | |||
*/ | |||
|
|||
package main | |||
package create |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be in the nerdctl/container
package, or maybe better in the nerdctl/container/create
pkg?
Because the "canonical" form of nerdctl create
is nerdctl container create
.
Same applies to the run
, exec
, cp
commands, etc.
Also, nerdctl info
should be in nerdctl/system
or nerdctl/system/info
.
cmd/nerdctl/image/image_convert.go
Outdated
@@ -30,6 +30,8 @@ import ( | |||
"github.com/containerd/containerd/images" | |||
"github.com/containerd/containerd/images/converter" | |||
"github.com/containerd/containerd/images/converter/uncompress" | |||
client2 "github.com/containerd/nerdctl/cmd/nerdctl/client" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can change either the package name (something like cliclient
or nerdclient
) or rename the variable client
to avoid client2
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have already fix(
87fa51d
to
8e52853
Compare
Revert unexpected changes in 5588f70 Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
b46d661
to
dc34976
Compare
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
dc34976
to
206e0c8
Compare
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
48788c3
to
c0566a4
Compare
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
A bunch of functions seems misplaced in wrong files. (See my follow-up commits above) I'm trying to fix them, but if I fail to do that by the end of the day, I'll prioritize merging other PRs. |
And I also don't want to split the integration test package from the command packages |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to fix them, but if I fail to do that by the end of the day, I'll prioritize merging other PRs.
But I fear that basically this PR isn't rebaseable after merging other PRs...
Thank you for the following up. 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. (cc @Zheaoli)
func InspectAction(cmd *cobra.Command, args []string) error { | ||
client, ctx, cancel, err := ncclient.New(cmd) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exported functions should have godoc. In this case, XAction
seems prints formatted strings to stdout so godoc should include the information about the format so that the caller can make sure it prints the expected outputs.
Maybe, exported functions should be independent from cobra and stdio.
"github.com/containerd/containerd/cio" | ||
) | ||
|
||
func PauseContainer(ctx context.Context, client *containerd.Client, id string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that we can put this under pkg
dir because it doesn't have cobra dependency?
// formatSlice is expected to be only used for `nerdctl OBJECT inspect` commands. | ||
func formatSlice(cmd *cobra.Command, x []interface{}) error { | ||
// FormatSlice is expected to be only used for `nerdctl OBJECT inspect` commands. | ||
func FormatSlice(cmd *cobra.Command, x []interface{}) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the purpose of the function is formatting rather than printing, I think it should receive io.Writer rather than *cobra.Command.
Probably we can prioritize bugfix PRs which usually happens in |
Sorry, I have to admit that I'm unable to review/carry this amount of PR 🙇♂️
Yes, this should be done in a series of small PRs if we want to continue this.
The git diff has to be kept minimal for ease of reviewing and potential rebasing. Also, there shouldn't be the We also have to revisit whether we really have to split Then there might be no good reason to split @Zheaoli |
I'm sorry for this huge PR, very sorry. It's my bad, the effort scope is beyond my think when I start this process. I will close this PR first, and I will make a refactor proposal to design the refactor step. Sorry again for this damn huge PR... |
Not "damn", don't blame your self ❤️ |
Fix #1631
First, I'm sorry that I make this PR too large to review. I have to make a one-shot PR if I want to re-structured the directory because the code in the
cmd/nerdctl
has been mixed,In this PR, I have made four things below
cmd/nerdctl
into subdirectory which the subcommand has organizedcmd/nerdctl/utils
cmd/nerdct/completion
Signed-off-by: Zheao.Li me@manjusaka.me