-
Notifications
You must be signed in to change notification settings - Fork 174
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: status, metadata and content handlers for manifest index
commands
#1509
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Xiaoxuan Wang <xiaoxuanwang@microsoft.com>
Signed-off-by: Xiaoxuan Wang <xiaoxuanwang@microsoft.com>
Signed-off-by: Xiaoxuan Wang <xiaoxuanwang@microsoft.com>
Signed-off-by: Xiaoxuan Wang <xiaoxuanwang@microsoft.com>
manifest index
commands
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1509 +/- ##
==========================================
- Coverage 86.10% 85.28% -0.83%
==========================================
Files 118 119 +1
Lines 4224 4355 +131
==========================================
+ Hits 3637 3714 +77
- Misses 350 382 +32
- Partials 237 259 +22 ☔ View full report in Codecov by Sentry. |
Signed-off-by: Xiaoxuan Wang <xiaoxuanwang@microsoft.com>
Signed-off-by: Xiaoxuan Wang <xiaoxuanwang@microsoft.com>
Signed-off-by: Xiaoxuan Wang <xiaoxuanwang@microsoft.com>
Signed-off-by: Xiaoxuan Wang <xiaoxuanwang@microsoft.com>
@@ -91,6 +89,10 @@ Example - Create an index and output the index to stdout, auto push will be disa | |||
opts.RawReference = refs[0] | |||
opts.extraRefs = refs[1:] | |||
opts.sources = args[1:] | |||
// ignore --pretty when output to a file | |||
if opts.outputPath != "" && opts.outputPath != "-" { | |||
opts.Pretty.Pretty = false |
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 move this pretty reset within OnContentCreated
, so you don't need to duplicate this snippet in index update
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.
In the option handling in command maybe?
|
||
// NewManifestIndexCreateHandler creates a new handler. | ||
func NewManifestIndexCreateHandler(out io.Writer, pretty bool, outputPath string) ManifestIndexCreateHandler { | ||
return &manifestIndexCreate{ |
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.
reset pretty here if output path is -
@@ -37,3 +38,8 @@ func NewManifestIndexCreateHandler(printer *output.Printer) metadata.ManifestInd | |||
func (h *ManifestIndexCreateHandler) OnTagged(_ ocispec.Descriptor, tag string) error { | |||
return h.printer.Println("Tagged", tag) | |||
} | |||
|
|||
// OnCompleted implements ManifestIndexCreateHandler. | |||
func (h *ManifestIndexCreateHandler) OnCompleted(digest digest.Digest) 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.
Considering we are most likely to have format. Here should pass in a descriptor and output the digest of the descriptor
@@ -28,3 +31,13 @@ func NewDiscardHandler() discard { | |||
func (discard) OnFetched(string, ocispec.Descriptor, []byte) error { | |||
return nil | |||
} | |||
|
|||
// OnTagged implements ManifestIndexCreateHandler. | |||
func (discard) OnTagged(desc ocispec.Descriptor, tag 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.
NIT
func (discard) OnTagged(desc ocispec.Descriptor, tag string) error { | |
func (discard) OnTagged(ocispec.Descriptor, string) error { |
} | ||
|
||
// OnCompleted implements ManifestIndexCreateHandler. | ||
func (discard) OnCompleted(digest digest.Digest) 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.
func (discard) OnCompleted(digest digest.Digest) error { | |
func (discard) OnCompleted(ocispec.Descriptor) error { |
@@ -81,8 +82,12 @@ type ManifestPushHandler interface { | |||
// ManifestIndexCreateHandler handles metadata output for index create events. | |||
type ManifestIndexCreateHandler interface { | |||
TaggedHandler | |||
OnCompleted(digest digest.Digest) 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.
OnCompleted(digest digest.Digest) error | |
OnCompleted(ocispec.Descriptor) error |
type ManifestIndexCreateHandler interface { | ||
OnSourceManifestFetching(source string) error | ||
OnSourceManifestFetched(source string) error | ||
OnIndexPacked(shortDigest 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.
Packed index should be moved to metadata output.
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.
Packed, Updated, Pushed, Added, Removed, Merged should all be moved to metadata output.
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.
Use one interface for packed and updated.
OnSourceManifestFetching(source string) error | ||
OnSourceManifestFetched(source 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.
Can we remove Source
from the naming? Will non-source manifest be fetched?
OnManifestRemoved(digest digest.Digest) error | ||
OnManifestAdded(manifestRef string, digest digest.Digest) error | ||
OnIndexMerged(indexRef string, digest digest.Digest) 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.
Should be moved to metadata handler
} | ||
|
||
// ManifestIndexUpdateHandler handles status output for manifest index update command. | ||
type ManifestIndexUpdateHandler interface { |
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.
Contains duplicated methods ManifestIndexCreateHandler
as below
OnIndexFetching(indexRef string) error
OnIndexFetched(indexRef string, digest digest.Digest) error
You can create a new interface and use it in both interfaces.
var statusHandler status.ManifestIndexCreateHandler | ||
var metadataHandler metadata.ManifestIndexCreateHandler | ||
var contentHandler content.ManifestIndexCreateHandler | ||
switch outputPath { | ||
case "": | ||
statusHandler = status.NewTextManifestIndexCreateHandler(printer) | ||
metadataHandler = text.NewManifestIndexCreateHandler(printer) | ||
contentHandler = content.NewDiscardHandler() | ||
case "-": | ||
statusHandler = status.NewDiscardHandler() | ||
metadataHandler = metadata.NewDiscardHandler() | ||
contentHandler = content.NewManifestIndexCreateHandler(printer, pretty, outputPath) | ||
default: | ||
statusHandler = status.NewTextManifestIndexCreateHandler(printer) | ||
metadataHandler = text.NewManifestIndexCreateHandler(printer) | ||
contentHandler = content.NewManifestIndexCreateHandler(printer, pretty, outputPath) | ||
} |
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.
var statusHandler status.ManifestIndexCreateHandler | |
var metadataHandler metadata.ManifestIndexCreateHandler | |
var contentHandler content.ManifestIndexCreateHandler | |
switch outputPath { | |
case "": | |
statusHandler = status.NewTextManifestIndexCreateHandler(printer) | |
metadataHandler = text.NewManifestIndexCreateHandler(printer) | |
contentHandler = content.NewDiscardHandler() | |
case "-": | |
statusHandler = status.NewDiscardHandler() | |
metadataHandler = metadata.NewDiscardHandler() | |
contentHandler = content.NewManifestIndexCreateHandler(printer, pretty, outputPath) | |
default: | |
statusHandler = status.NewTextManifestIndexCreateHandler(printer) | |
metadataHandler = text.NewManifestIndexCreateHandler(printer) | |
contentHandler = content.NewManifestIndexCreateHandler(printer, pretty, outputPath) | |
} | |
statusHandler := status.NewTextManifestIndexCreateHandler(printer) | |
metadataHandler := text.NewManifestIndexCreateHandler(printer) | |
contentHandler := content.NewManifestIndexCreateHandler(printer, pretty, outputPath) | |
switch outputPath { | |
case "": | |
contentHandler = content.NewDiscardHandler() | |
case "-": | |
statusHandler = status.NewDiscardHandler() | |
metadataHandler = metadata.NewDiscardHandler() | |
} |
// ignore --pretty when output to a file | ||
if opts.outputPath != "" && opts.outputPath != "-" { | ||
opts.Pretty.Pretty = false | ||
} |
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.
Can be merged into the handler construction.
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 this is a general option thing, maybe a method in otpions?
// OnContentCreated is called after index content is created. | ||
func (h *manifestIndexCreate) OnContentCreated(manifest []byte) error { | ||
out := h.stdout | ||
if h.outputPath != "-" && h.outputPath != "" { |
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 you changed outputPath to "" for "-" this logic would look less odd.
} | ||
|
||
// NewManifestIndexUpdateHandler returns status, metadata and content handlers for index update command. | ||
func NewManifestIndexUpdateHandler(outputPath string, printer *output.Printer, pretty bool) ( |
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 there just be a NewManivestIndexHandler
method for both for now and someone can add the other in the future if needed?
tmich := TextManifestIndexCreateHandler{ | ||
printer: printer, | ||
} | ||
return &tmich |
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.
tmich := TextManifestIndexCreateHandler{ | |
printer: printer, | |
} | |
return &tmich | |
manifestHandler := TextManifestIndexCreateHandler{ | |
printer: printer, | |
} | |
return &manifestHandler |
miuh := TextManifestIndexUpdateHandler{ | ||
printer: printer, | ||
} | ||
return &miuh |
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.
miuh := TextManifestIndexUpdateHandler{ | |
printer: printer, | |
} | |
return &miuh | |
manifestHandler := TextManifestIndexUpdateHandler{ | |
printer: printer, | |
} | |
return &manifestHandler |
@@ -91,6 +89,10 @@ Example - Create an index and output the index to stdout, auto push will be disa | |||
opts.RawReference = refs[0] | |||
opts.extraRefs = refs[1:] | |||
opts.sources = args[1:] | |||
// ignore --pretty when output to a file | |||
if opts.outputPath != "" && opts.outputPath != "-" { | |||
opts.Pretty.Pretty = false |
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.
In the option handling in command maybe?
@@ -188,7 +197,8 @@ func getPlatform(ctx context.Context, target oras.ReadOnlyTarget, manifestBytes | |||
return &platform, nil | |||
} | |||
|
|||
func pushIndex(ctx context.Context, target oras.Target, desc ocispec.Descriptor, content []byte, ref string, extraRefs []string, path string, printer *output.Printer) error { | |||
func pushIndex(ctx context.Context, onIndexPushed func(path string) error, onTagged func(desc ocispec.Descriptor, tag 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.
This is a private method here, seems like it would make more sense for it to take handlers than function pointers.
Another thing, it seems like an extremely long list of params like something is not right here.
// ignore --pretty when output to a file | ||
if opts.outputPath != "" && opts.outputPath != "-" { | ||
opts.Pretty.Pretty = false | ||
} |
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 this is a general option thing, maybe a method in otpions?
What this PR does / why we need it:
Implements output handlers for
manifest index
commands.Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Fixes #1503
Please check the following list: