aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pkg/autoupdate/autoupdate.go41
1 files changed, 20 insertions, 21 deletions
diff --git a/pkg/autoupdate/autoupdate.go b/pkg/autoupdate/autoupdate.go
index 6748ca351..794f31d1f 100644
--- a/pkg/autoupdate/autoupdate.go
+++ b/pkg/autoupdate/autoupdate.go
@@ -53,7 +53,6 @@ var supportedPolicies = map[string]Policy{
// updater includes shared state for auto-updating one or more containers.
type updater struct {
conn *dbus.Conn
- idToImage map[string]*libimage.Image
options *entities.AutoUpdateOptions
unitToTasks map[string][]*task
updatedRawImages map[string]bool
@@ -126,24 +125,6 @@ func ValidateImageReference(imageName string) error {
return nil
}
-func (u *updater) assembleImageMap(ctx context.Context) error {
- // Create a map from `image ID -> *libimage.Image` for image lookups.
- listOptions := &libimage.ListImagesOptions{
- Filters: []string{"readonly=false"},
- }
- imagesSlice, err := u.runtime.LibimageRuntime().ListImages(ctx, nil, listOptions)
- if err != nil {
- return err
- }
- imageMap := make(map[string]*libimage.Image)
- for i := range imagesSlice {
- imageMap[imagesSlice[i].ID()] = imagesSlice[i]
- }
-
- u.idToImage = imageMap
- return nil
-}
-
// AutoUpdate looks up containers with a specified auto-update policy and acts
// accordingly.
//
@@ -383,7 +364,8 @@ func (u *updater) restartSystemdUnit(ctx context.Context, ctr *libpod.Container,
func (u *updater) assembleTasks(ctx context.Context) []error {
// Assemble a map `image ID -> *libimage.Image` that we can consult
// later on for lookups.
- if err := u.assembleImageMap(ctx); err != nil {
+ imageMap, err := u.assembleImageMap(ctx)
+ if err != nil {
return []error{err}
}
@@ -432,7 +414,7 @@ func (u *updater) assembleTasks(ctx context.Context) []error {
}
id, _ := ctr.Image()
- image, exists := u.idToImage[id]
+ image, exists := imageMap[id]
if !exists {
err := fmt.Errorf("internal error: no image found for ID %s", id)
errors = append(errors, err)
@@ -455,6 +437,23 @@ func (u *updater) assembleTasks(ctx context.Context) []error {
return errors
}
+// assembleImageMap creates a map from `image ID -> *libimage.Image` for image lookups.
+func (u *updater) assembleImageMap(ctx context.Context) (map[string]*libimage.Image, error) {
+ listOptions := &libimage.ListImagesOptions{
+ Filters: []string{"readonly=false"},
+ }
+ imagesSlice, err := u.runtime.LibimageRuntime().ListImages(ctx, nil, listOptions)
+ if err != nil {
+ return nil, err
+ }
+ imageMap := make(map[string]*libimage.Image)
+ for i := range imagesSlice {
+ imageMap[imagesSlice[i].ID()] = imagesSlice[i]
+ }
+
+ return imageMap, nil
+}
+
// newerRemoteImageAvailable returns true if there corresponding image on the remote
// registry is newer.
func newerRemoteImageAvailable(ctx context.Context, img *libimage.Image, origName string, authfile string) (bool, error) {