Skip to content

refactor: container logs flagging process#1881

Merged
AkihiroSuda merged 1 commit into
containerd:mainfrom
davidhsingyuchen:refactor-logs-flags
Jan 23, 2023
Merged

refactor: container logs flagging process#1881
AkihiroSuda merged 1 commit into
containerd:mainfrom
davidhsingyuchen:refactor-logs-flags

Conversation

@davidhsingyuchen
Copy link
Copy Markdown
Contributor

@davidhsingyuchen davidhsingyuchen commented Jan 19, 2023

Part of #1680

  • Create a file in pkg/api/types/${cmd}_types.go, and define the CommandOption for this command
  • Create some file in pkg/cmd/${cmd}, and move the command entry point in real into this package

Notes:

Signed-off-by: Hsing-Yu (David) Chen davidhsingyuchen@gmail.com

@davidhsingyuchen davidhsingyuchen marked this pull request as ready for review January 19, 2023 06:24
"github.com/spf13/cobra"
)

func newLogsCommand() *cobra.Command {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we can keep the file name unchanged as logs.go (and logs_test.go)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hmm, I was following the pattern in #1869 as container logs is the canonical name of this command. @AkihiroSuda Do you know which pattern we should follow?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ops, didn't notice that. I'm okay with either one.

Currently it seems we only prefix container/image to file names if there're mutiple commands (e.g., container_inspect.go/container_prune.go v.s. image_inspect.go/image_prune.go; run.go instead of container_run.go).

But yeah adding a prefix can make those files closer :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

My thoughts:

  • Prefixing the files according to their canonical names may make them more organized.
  • If we're grouping things according to their canonical names re. things under pkg/cmd, maybe we want to do so consistently in other places.

Just my 2 cents :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, containers_logs.go is preferred as it corresponds to the canonical form nerdctl containers logs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Wondering if I should do a one-shot PR for this. Maybe after #1900 is merged? /cc @Zheaoli

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, @davidhsingyuchen, it's better to be merged after #1900

Comment thread cmd/nerdctl/container_logs.go Outdated
if err != nil {
return err
}
return container.Logs(cmd.Context(), options, cmd.OutOrStdout(), cmd.ErrOrStderr())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can you move the Container out from option and pass it as an argument? Container is not really an option but the target for Logs.

container.Logs(cmd.Context(), args[0], options, ...)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I see. Shall we also move Containers out of ContainerInspectCommandOptions (in another PR)?

Comment thread cmd/nerdctl/container_logs.go Outdated
return logsCommand
}

func processContainerLogsCommandOptions(cmd *cobra.Command) (types.ContainerLogsCommandOptions, error) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We may need to change ContainerLogsCommandOptions to ContainerLogsOptions (e.g. from ${Command}CommandOptions to ${Command}Options) for brevity. And also put stdin/stdout/stderr in ${Command}Options directly (if they're used).

#1889 has more discussion, but the tl;dr is:

  1. Rename ${Command}CommandOptions to ${Command}Options;
  2. Put necessary io used by the command directly in ${Command}Options;
  3. Argument order: func Command(ctx context.Context, param1, param2 type, options ${Command}Options (param1, param2 type means, e.g., container_id, image_ref, id, etc).

Sorry to back and forth on this, but now I think it brings more consistency :) lmk if there is something unclear.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

#1900 has changes following up the issue.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the very clear summary! Updated accordingly.

Re. #1889 (comment):

These are optional, and nil values should imply os.Stdin, os.Stdout, os.Stderr .

I didn't add a check for this as they could be nil even before they are put into the options struct, and we weren't doing the checks. Checked #1900, and it seems that it's also not adding this check. Last, currently every caller in cmd/nerdctl should just explicitly specify them anyway.

@davidhsingyuchen
Copy link
Copy Markdown
Contributor Author

Forced push again to

  1. resolve merge conflicts
  2. move Stdout and Stderr to be consistent with what's in [Refactor] Reorder the method argument ordering in pkg/cmd #1900 (pkg/cmd: inconsistent arguments ordering #1889 (comment))

Copy link
Copy Markdown
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.

LGTM aside from the comment. Maybe we should merge after #1900 to reduce conflict.

Comment thread pkg/cmd/container/logs.go
return err
}
dataStore, err := clientutil.DataStore(globalOptions.DataRoot, globalOptions.Address)
func Logs(ctx context.Context, container string, options types.ContainerLogsOptions) error {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you add a brief comment here?

nit: also maybe change container name to something else (for example, c, arg), since the package name is also container. Not sure if there will any unexpected conflict.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Can you add a brief comment here?

Do you mean adding a function comment for Logs? If yes, maybe we'd want to do it consistently. Currently it seems that no other function has such comment.

also maybe change container name to something else (for example, c, arg)

Maybe ctr? I feel that arg may be too generic, and c is a bit too short for a parameter.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ctr also means ctr cli from containerd, which might be confusing. I'm okay with keeping container if there is no conflict.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Rebased.

I'm okay with keeping container if there is no conflict.

Keeping it as is as there's no conflict.

@davidhsingyuchen
Copy link
Copy Markdown
Contributor Author

Maybe we should merge after #1900 to reduce conflict.

Sure. Will address comments and rebase on main after #1900 is merged.

@AkihiroSuda AkihiroSuda added this to the v1.2.0 milestone Jan 23, 2023
Signed-off-by: Hsing-Yu (David) Chen <davidhsingyuchen@gmail.com>
Copy link
Copy Markdown
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 5b84533 into containerd:main Jan 23, 2023
@davidhsingyuchen davidhsingyuchen deleted the refactor-logs-flags branch January 23, 2023 17:54
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.

4 participants