aboutsummaryrefslogtreecommitdiff
path: root/pkg/autoupdate
diff options
context:
space:
mode:
authorValentin Rothberg <vrothberg@redhat.com>2022-08-03 14:56:01 +0200
committerValentin Rothberg <vrothberg@redhat.com>2022-08-04 13:07:58 +0200
commit3fdd3b1ae332a26e6bba696d8bd49d29a0299b3b (patch)
tree81e7cdab1585f8a242d458615578a0b894d74e29 /pkg/autoupdate
parent82d18a86f395657424f24e86140bb1ed15229141 (diff)
downloadpodman-3fdd3b1ae332a26e6bba696d8bd49d29a0299b3b.tar.gz
podman-3fdd3b1ae332a26e6bba696d8bd49d29a0299b3b.tar.bz2
podman-3fdd3b1ae332a26e6bba696d8bd49d29a0299b3b.zip
pkg/autoupdate: remove image map from updater
It is not state needed after assembling the tasks, so remove it to keep the task struct simpler. Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
Diffstat (limited to 'pkg/autoupdate')
-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) {