-
Notifications
You must be signed in to change notification settings - Fork 18.7k
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
Add load/save image event support #22137
Conversation
IMO, I don't think we should move |
Hi @coolljt0725
I'd like to hear specific suggestions. Thanks |
@HackToday I think just add a +++ b/daemon/daemon.go
@@ -973,7 +973,7 @@ func isBrokenPipe(e error) bool {
// the same tag are exported. names is the set of tags to export, and
// outStream is the writer which the images are written to.
func (daemon *Daemon) ExportImage(names []string, outStream io.Writer) error {
- imageExporter := tarexport.NewTarExporter(daemon.imageStore, daemon.layerStore, daemon.referenceStore)
+ imageExporter := tarexport.NewTarExporter(daemon.imageStore, daemon.layerStore, daemon.referenceStore, daemon)
return imageExporter.Save(names, outStream)
}
@@ -1052,7 +1052,7 @@ func (daemon *Daemon) LookupImage(name string) (*types.ImageInspect, error) {
// complement of ImageExport. The input stream is an uncompressed tar
// ball containing images and metadata.
func (daemon *Daemon) LoadImage(inTar io.ReadCloser, outStream io.Writer, quiet bool) error {
- imageExporter := tarexport.NewTarExporter(daemon.imageStore, daemon.layerStore, daemon.referenceStore)
+ imageExporter := tarexport.NewTarExporter(daemon.imageStore, daemon.layerStore, daemon.referenceStore, daemon)
return imageExporter.Load(inTar, outStream, quiet)
}
diff --git a/image/tarexport/load.go b/image/tarexport/load.go
index 42eaa40..69c518e 100644
--- a/image/tarexport/load.go
+++ b/image/tarexport/load.go
@@ -122,6 +122,7 @@ func (l *tarexporter) Load(inTar io.ReadCloser, outStream io.Writer, quiet bool)
}
parentLinks = append(parentLinks, parentLink{imgID, m.Parent})
+ l.e.LogImageEvent(imgID.String(), imgID.String(), "load")
}
for _, p := range validatedParentLinks(parentLinks) {
diff --git a/image/tarexport/tarexport.go b/image/tarexport/tarexport.go
index 5e20877..45f7aae 100644
--- a/image/tarexport/tarexport.go
+++ b/image/tarexport/tarexport.go
@@ -21,17 +21,23 @@ type manifestItem struct {
Parent image.ID `json:",omitempty"`
}
+type LogImageEvent interface {
+ LogImageEvent(imageID, refName, action string)
+}
+
type tarexporter struct {
is image.Store
ls layer.Store
rs reference.Store
+ e LogImageEvent
}
// NewTarExporter returns new ImageExporter for tar packages
-func NewTarExporter(is image.Store, ls layer.Store, rs reference.Store) image.Exporter {
+func NewTarExporter(is image.Store, ls layer.Store, rs reference.Store, e LogImageEvent) image.Exporter {
return &tarexporter{
is: is,
ls: ls,
rs: rs,
+ e: e,
}
} |
Thanks @coolljt0725 I would to hear more |
c.Assert(longImageID, checker.Not(check.Equals), "", check.Commentf("Id should not be empty")) | ||
|
||
dockerCmd(c, "save", "-o", "saveimg.tar", "busybox") | ||
dockerCmd(c, "rmi", "busybox") |
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 removes busybox. Meaning it will be repulled from instead of using the frozen image. Image pulled from hub doesn't have a parent chain.
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.
Thanks @tonistiigi for your input!
I would use another way to test the load/save case
I agree with @coolljt0725. |
@calavera OK add another interface could have less code, and I would follow that. but I did not find any good reason put such daemon operation in separate package make sense. Could you help explain why ? |
The jenkins failed seems unrelated with my change |
@HackToday I think they're related;
|
7590c56
to
8595df5
Compare
please test it |
LGTM |
We should add those events to the documentation |
For every docker load and save operations, it would log related image events. Signed-off-by: Kai Qiang Wu(Kennan) <[email protected]>
@calavera docs updated ping @thaJeztah PTAL if docs OK. Thanks |
LGTM |
LGTM 🐯 |
- What I did
make docker load/save emit events
- How I did it
move related logic to daemon directory(it follows other docker operation style)
- How to verify it
Have integration test for that
- A picture of a cute animal (not mandatory but encouraged)
This change moves related load/save logic to daemon dir,
which keep same as other docker operations(import, export etc.)
For every docker load and save operations, it would log related
image events.
Closes: #21973
Signed-off-by: Kai Qiang Wu(Kennan) [email protected]