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 image save flagging process #1924

Merged
merged 1 commit into from
Feb 5, 2023

Conversation

suyanhanx
Copy link
Contributor

@suyanhanx suyanhanx commented Jan 25, 2023

part of #1680

Checklist:

  • 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

Signed-off-by: suyanhanx suyanhanx@gmail.com

@suyanhanx suyanhanx marked this pull request as ready for review January 25, 2023 12:37
pkg/cmd/image/save.go Show resolved Hide resolved
pkg/cmd/image/save.go Outdated Show resolved Hide resolved
pkg/cmd/image/save.go Outdated Show resolved Hide resolved
pkg/cmd/image/save.go Outdated Show resolved Hide resolved
pkg/cmd/image/save.go Outdated Show resolved Hide resolved
Comment on lines +36 to +46
if options.Output != "" {
f, err := os.OpenFile(options.Output, os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
return err
}
defer f.Close()
options.Stdout = f
} else {
if isatty.IsTerminal(os.Stdout.Fd()) {
return fmt.Errorf("cowardly refusing to save to a terminal. Use the -o flag or redirect")
}
}
Copy link
Member

Choose a reason for hiding this comment

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

(below is more for discussion and see other reviewers' thought).

I think we should remove Output string from ImageSaveOptions. Functionally, it represents the same thing as Stdout io.Writer and having both might cause inconsistency and confusing, for example:

  • Even Output != "", we init Stdout = cmd.OutOrStdout() when creating ImageSaveOptions, and then change it after the file writer created (i.e., here).
  • Should a caller specify Output, or Stdout io.Writer?

If we remove Output and keep Stdout only:

  1. pkg/cmd side logic doesn't need to know where the writer comes from. It just writes content to it.
  2. On cmd side, we init opt.Stdout = cmd.OutOrStdout() if output == "" or create a file writer and use it as opt.Stdout (i.e., this pard of code).

Copy link
Contributor Author

@suyanhanx suyanhanx Jan 26, 2023

Choose a reason for hiding this comment

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

I think your thought is a pretty good idea. I will keep the code quo for now.

Copy link
Contributor Author

@suyanhanx suyanhanx Jan 26, 2023

Choose a reason for hiding this comment

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

PTAL. Thanks. @AkihiroSuda @Zheaoli

Copy link
Member

@Zheaoli Zheaoli Jan 28, 2023

Choose a reason for hiding this comment

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

I think it's better to make another PR to simplify the logic. I prefer to keep the same code here (one PR for one thing). BTW I have made a new issue to discuss this

Signed-off-by: suyanhanx <suyanhanx@gmail.com>
Copy link
Member

@Zheaoli Zheaoli left a comment

Choose a reason for hiding this comment

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

LGTM, Thanks

@Zheaoli Zheaoli added this to the v1.3.0 (tentative) milestone Feb 5, 2023
@Zheaoli Zheaoli merged commit 875560e into containerd:main Feb 5, 2023
@suyanhanx suyanhanx deleted the refactor-image-save-flag branch February 5, 2023 13:34
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.

None yet

3 participants