pkg/autoupdate: move authfile into `tasks`

Will simplify the code and speed up things as we do not consult a
container's labels multiple times.

[NO NEW TESTS NEEDED] - should not change behavior.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
This commit is contained in:
Valentin Rothberg 2022-08-03 13:37:06 +02:00
parent 3f1928d767
commit 42c4c17c01
1 changed files with 4 additions and 14 deletions

View File

@ -62,6 +62,7 @@ type updater struct {
// task includes data and state for updating a container // task includes data and state for updating a container
type task struct { type task struct {
authfile string // Container-specific authfile
auto *updater // Reverse pointer to the updater auto *updater // Reverse pointer to the updater
container *libpod.Container // Container to update container *libpod.Container // Container to update
policy Policy // Update policy policy Policy // Update policy
@ -244,8 +245,7 @@ func (t *task) updateRegistry(ctx context.Context) (*entities.AutoUpdateReport,
return report, nil return report, nil
} }
authfile := getAuthfilePath(t.container, t.auto.options) needsUpdate, err := newerRemoteImageAvailable(ctx, t.image, rawImageName, t.authfile)
needsUpdate, err := newerRemoteImageAvailable(ctx, t.image, rawImageName, authfile)
if err != nil { if err != nil {
return report, fmt.Errorf("registry auto-updating container %q: image check for %q failed: %w", cid, rawImageName, err) return report, fmt.Errorf("registry auto-updating container %q: image check for %q failed: %w", cid, rawImageName, err)
} }
@ -260,7 +260,7 @@ func (t *task) updateRegistry(ctx context.Context) (*entities.AutoUpdateReport,
return report, nil return report, nil
} }
if _, err := pullImage(ctx, t.auto.runtime, rawImageName, authfile); err != nil { if _, err := pullImage(ctx, t.auto.runtime, rawImageName, t.authfile); err != nil {
return report, fmt.Errorf("registry auto-updating container %q: image update for %q failed: %w", cid, rawImageName, err) return report, fmt.Errorf("registry auto-updating container %q: image update for %q failed: %w", cid, rawImageName, err)
} }
t.auto.updatedRawImages[rawImageName] = true t.auto.updatedRawImages[rawImageName] = true
@ -432,6 +432,7 @@ func (u *updater) assembleTasks(ctx context.Context) []error {
} }
t := task{ t := task{
authfile: labels[AuthfileLabel],
auto: u, auto: u,
container: ctr, container: ctr,
policy: policy, policy: policy,
@ -446,17 +447,6 @@ func (u *updater) assembleTasks(ctx context.Context) []error {
return errors return errors
} }
// getAuthfilePath returns an authfile path, if set. The authfile label in the
// container, if set, as precedence over the one set in the options.
func getAuthfilePath(ctr *libpod.Container, options *entities.AutoUpdateOptions) string {
labels := ctr.Labels()
authFilePath, exists := labels[AuthfileLabel]
if exists {
return authFilePath
}
return options.Authfile
}
// newerRemoteImageAvailable returns true if there corresponding image on the remote // newerRemoteImageAvailable returns true if there corresponding image on the remote
// registry is newer. // registry is newer.
func newerRemoteImageAvailable(ctx context.Context, img *libimage.Image, origName string, authfile string) (bool, error) { func newerRemoteImageAvailable(ctx context.Context, img *libimage.Image, origName string, authfile string) (bool, error) {