-
Notifications
You must be signed in to change notification settings - Fork 181
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
feat: enhance manifest fetch #541
Conversation
Signed-off-by: Haoliang Yue <[email protected]>
Codecov Report
@@ Coverage Diff @@
## main #541 +/- ##
==========================================
- Coverage 73.68% 72.44% -1.25%
==========================================
Files 13 13
Lines 532 508 -24
==========================================
- Hits 392 368 -24
Misses 112 112
Partials 28 28
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Signed-off-by: Haoliang Yue <[email protected]>
Signed-off-by: Haoliang Yue <[email protected]>
Signed-off-by: Haoliang Yue <[email protected]>
cmd/oras/manifest/fetch.go
Outdated
if opts.cacheRoot != "" { | ||
ociStore, err := oci.New(opts.cacheRoot) | ||
if err != nil { | ||
return err | ||
} | ||
buf.WriteByte('\n') | ||
content = buf.Bytes() | ||
src = cache.New(src, ociStore) | ||
} |
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 we refactor it into the option
package?
/cc @qweeah
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 we refactor it into the
option
package?/cc @qweeah
Created a option Cache
.
cmd/oras/manifest/fetch.go
Outdated
if opts.OutputDescriptor { | ||
descBytes, err := json.Marshal(desc) | ||
if err != nil { | ||
return err | ||
} | ||
err = opts.Output(os.Stdout, descBytes) | ||
if err != nil { | ||
return err | ||
} | ||
} |
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 code block appears everywhere if --descriptor
and --pretty
and both needed, any idea to refactor it? It doesn't necessarily need to be done in this PR /cc @lizMSFT
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.
We're discussing about this change offline.
Signed-off-by: Haoliang Yue <[email protected]>
Signed-off-by: Haoliang Yue <[email protected]>
Signed-off-by: Haoliang Yue <[email protected]>
Signed-off-by: Haoliang Yue <[email protected]>
if err != nil { | ||
t.Fatal("error calling oci.New(), error =", err) | ||
} | ||
want := cache.New(mockTarget, ociStore) |
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 was trying to write a better test here, but I didn't figure out a good way unless exporting the cache.target
struct.
want := struct {
oras.ReadOnlyTarget
cache content.Storage
}{
mockTarget,
ociStore,
}
Building a struct like above doesn't work as want
and got
are not equal.
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's not doable even if cache.target
struct is exported because target.cache
is not exported. I think we can keep it this way.
|
||
var desc ocispec.Descriptor | ||
var content []byte | ||
if opts.OutputDescriptor && opts.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.
This if block can be merged with the if block at the end:
- If !opts.OutputDescriptor || opt.outputPath != "" => fetch manifest content
- If opts.OutputDescriptor => resolve and output to stdout
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 couldn't really follow your idea here.
In the case of fetching manifest content, there still might be a need to output descriptor, eg. --output manifest.json --descriptor
. Since oras.FetchBytes
returns both the content and the descriptor, so if content has already been fetched, we don't need to call oras.Resolve
again.
Current logic:
if opts.OutputDescriptor && opts.outputPath == "" {
// oras.Resolve fetch manifest descriptor only
} else {
// oras.FetchBytes fetch manifest descriptor content
if opts.outputPath == "" || opts.outputPath == "-" {
// output manifest content
return
}
// save manifest content into the local file
}
if opts.OutputDescriptor {
// output manifest descriptor
}
In the logic below, for --output manifest.json --descriptor
, there's a redundant call of oras.Resolve
.
if !opts.OutputDescriptor || opt.outputPath != "" {
// oras.FetchBytes fetch manifest descriptor content
if opts.outputPath == "" || opts.outputPath == "-" {
// output manifest content
return
}
// save manifest content into the local file
}
if opts.OutputDescriptor {
// oras.Resolve fetch manifest descriptor only
// output manifest descriptor
}
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.
Since oras.FetchBytes returns both the content and the descriptor, so if content has already been fetched, we don't need to call oras.Resolve again
This can be avoided by checking if the desc is an empty struct.
if err != nil { | ||
t.Fatal("error calling oci.New(), error =", err) | ||
} | ||
want := cache.New(mockTarget, ociStore) |
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's not doable even if cache.target
struct is exported because target.cache
is not exported. I think we can keep it this way.
Signed-off-by: Haoliang Yue <[email protected]>
Signed-off-by: Haoliang Yue <[email protected]>
Signed-off-by: Haoliang Yue <[email protected]>
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.
LGTM
Signed-off-by: Haoliang Yue <[email protected]>
Resolve #531
Signed-off-by: Haoliang Yue [email protected]