Skip to content

Commit

Permalink
Merge pull request #1327 from sstosh/fix-load-events
Browse files Browse the repository at this point in the history
libimage: wait to write an event until an image loaded
  • Loading branch information
openshift-merge-robot authored Feb 15, 2023
2 parents 6934442 + 8cf7839 commit 1775cfa
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions libimage/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,13 @@ func (r *Runtime) Load(ctx context.Context, path string, options *LoadOptions) (
} {
loadedImages, transportName, err := f()
if err == nil {
return loadedImages, nil
if r.eventChannel != nil {
err = r.writeLoadEvents(path, loadedImages)
}
return loadedImages, err
}
logrus.Debugf("Error loading %s (%s): %v", path, transportName, err)
loadErrors = append(loadErrors, fmt.Errorf("%s: %v", transportName, err))

if r.eventChannel != nil {
for _, name := range loadedImages {
image, _, err := r.LookupImage(name, nil)
if err != nil {
return nil, fmt.Errorf("locating pulled image %q name in containers storage: %w", name, err)
}
r.writeEvent(&Event{ID: image.ID(), Name: path, Time: time.Now(), Type: EventTypeImageLoad})
}
}
}

// Give a decent error message if nothing above worked.
Expand All @@ -104,6 +97,18 @@ func (r *Runtime) Load(ctx context.Context, path string, options *LoadOptions) (
return nil, loadError
}

// writeLoadEvents writes the events of the loaded image.
func (r *Runtime) writeLoadEvents(path string, loadedImages []string) error {
for _, name := range loadedImages {
image, _, err := r.LookupImage(name, nil)
if err != nil {
return fmt.Errorf("locating pulled image %q name in containers storage: %w", name, err)
}
r.writeEvent(&Event{ID: image.ID(), Name: path, Time: time.Now(), Type: EventTypeImageLoad})
}
return nil
}

// loadMultiImageDockerArchive loads the docker archive specified by ref. In
// case the path@reference notation was used, only the specified image will be
// loaded. Otherwise, all images will be loaded.
Expand Down

0 comments on commit 1775cfa

Please sign in to comment.