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

[Refactor] Refactor the (container) create command flagging process #1970

Merged
merged 1 commit into from
May 7, 2023

Conversation

Laitr0n
Copy link
Contributor

@Laitr0n Laitr0n commented Feb 3, 2023

Checklist:

  • Create a file in pkg/api/types/container_types.go, and define the CommandOption for this command

Signed-off-by: Laitron meetlq@outlook.com

@Laitr0n Laitr0n marked this pull request as ready for review February 3, 2023 03:00
@Laitr0n Laitr0n marked this pull request as draft February 3, 2023 10:05
@Laitr0n Laitr0n force-pushed the refactor_container_create branch 11 times, most recently from fa7578e to cde45a3 Compare February 4, 2023 16:39
@Laitr0n Laitr0n force-pushed the refactor_container_create branch 2 times, most recently from 1cdf3bd to a2c6d43 Compare February 6, 2023 03:53
@Laitr0n Laitr0n force-pushed the refactor_container_create branch 8 times, most recently from e14ae66 to dd82e4b Compare February 12, 2023 08:07
@Laitr0n Laitr0n force-pushed the refactor_container_create branch 2 times, most recently from fc68d9d to 73f0bc3 Compare February 14, 2023 16:23
pkg/api/types/container_types.go Outdated Show resolved Hide resolved
cmd/nerdctl/container_create.go Outdated Show resolved Hide resolved
cmd/nerdctl/container_run_linux.go Outdated Show resolved Hide resolved
@Laitr0n Laitr0n changed the title [WIP][Refactor] Refactor the (container) create command flagging process [Refactor] Refactor the (container) create command flagging process Mar 31, 2023
@Laitr0n Laitr0n requested a review from djdongjin March 31, 2023 12:55
@Laitr0n
Copy link
Contributor Author

Laitr0n commented Apr 3, 2023

@djdongjin Sorry for delay.
PTAL. If there are any problems, please let me know. I will make the changes as soon as possible.

cmd/nerdctl/container_create.go Outdated Show resolved Hide resolved
cmd/nerdctl/container_create.go Show resolved Hide resolved
cmd/nerdctl/container_create.go Outdated Show resolved Hide resolved
cmd/nerdctl/container_create.go Outdated Show resolved Hide resolved
cmd/nerdctl/container_create.go Outdated Show resolved Hide resolved
pkg/containerutil/containerutil.go Outdated Show resolved Hide resolved
pkg/cmd/container/run.go Outdated Show resolved Hide resolved
pkg/containerutil/mount_options.go Outdated Show resolved Hide resolved
pkg/containerutil/labels.go Outdated Show resolved Hide resolved
)

// GenerateGcFunc returns a function that can be used to garbage collect a container
func GenerateGcFunc(ctx context.Context, container containerd.Container, ns, id, name, dataStore string, containerErr error, containerNameStore namestore.NameStore, netManager NetworkOptionsManager, internalLabels InternalLabels) func() {
Copy link
Member

Choose a reason for hiding this comment

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

where is this func used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When an error occurs during creation client.NewContainer(ctx, id, cOpts...) or due to a network error netManager.SetupNetworking(ctx, id), GenerateGcFunc uses to generate gc func.

@djdongjin
Copy link
Member

I haven't looked into if the newly created files make sense (i.e. if they're created in the correct pkg/location etc). Will take a look later.

@Laitr0n
Copy link
Contributor Author

Laitr0n commented Apr 3, 2023

I haven't looked into if the newly created files make sense (i.e. if they're created in the correct pkg/location etc). Will take a look later.

Thanks! I got it and I will deal above comments firstly.

Copy link
Member

@djdongjin djdongjin left a comment

Choose a reason for hiding this comment

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

@Laitr0n thanks for the change.

An overall suggestion is to first make the file name changes more consistent with the existing pattern, instead of creating new packages (cgrouputil) or moving to other packages (containerutil) unless the code is reused by other functions/commands other than run.

E.g., move cmd/nerdctl/container_run_xxx_linux.go to pkg/cmd/container/run_xxx_linux.go.

This will be quite helpful to identify where a new file/code come from.

Thanks!

pkg/containerutil/restart_options.go Outdated Show resolved Hide resolved
pkg/containerutil/platform_options_linux.go Outdated Show resolved Hide resolved
pkg/cgrouputil/cgroup_linux.go Outdated Show resolved Hide resolved
@Laitr0n
Copy link
Contributor Author

Laitr0n commented Apr 25, 2023

@Laitr0n thanks for the change.

An overall suggestion is to first make the file name changes more consistent with the existing pattern, instead of creating new packages (cgrouputil) or moving to other packages (containerutil) unless the code is reused by other functions/commands other than run.

E.g., move cmd/nerdctl/container_run_xxx_linux.go to pkg/cmd/container/run_xxx_linux.go.

This will be quite helpful to identify where a new file/code come from.

Thanks!

Got what you mean. I'll make the update for these changes.

@Laitr0n Laitr0n force-pushed the refactor_container_create branch 4 times, most recently from a44450c to 09cc240 Compare April 30, 2023 06:56
@Laitr0n Laitr0n requested a review from djdongjin April 30, 2023 07:29
@AkihiroSuda
Copy link
Member

@Zheaoli @djdongjin LGTY? 🙏

@djdongjin
Copy link
Member

@AkihiroSuda sorry I haven't gotten a chance to take a look at the latest change. Will take a look today.

Copy link
Member

@djdongjin djdongjin left a comment

Choose a reason for hiding this comment

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

Overall LGTM, I left some minor suggestions. Thanks!

Since it's a large PR it might be good to have another review/approval.

pkg/cmd/container/run_runtime.go Outdated Show resolved Hide resolved
memSwap, err := cmd.Flags().GetString("memory-swap")
if err != nil {
return nil, err
func generateCgroupPath(id string, cgroupManager, cgroupParent string) (string, error) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: can we keep the argument order unchanged and remove the redundant string arg type (cgroupManager, cgroupParent, id string). Also if you move this func to after GenerateOptsand beforeParseDevice`, the diff will be much smaller.

@Laitr0n
Copy link
Contributor Author

Laitr0n commented May 4, 2023

Overall LGTM, I left some minor suggestions. Thanks!

Since it's a large PR it might be good to have another review/approval.

LGTM! Thanks for your work! ❤️

@Zheaoli Could you take a look at this?

Signed-off-by: Laitron <meetlq@outlook.com>
@Laitr0n Laitr0n force-pushed the refactor_container_create branch from 09cc240 to e7855d0 Compare May 4, 2023 13:50
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 a28e41d into containerd:main May 7, 2023
@Laitr0n Laitr0n deleted the refactor_container_create branch May 7, 2023 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants