From 43cca5d97a2c971f3386099d6b66250a1ebad96f Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Wed, 3 Aug 2022 16:12:48 +0200 Subject: pkg/autoupdate: decompose the update logic Decompose the update logic into smaller steps (update check, update, rollback, etc.) and move the implementation into the `task` API. This allows to transition a task from state to state, independent of its underlying auto-update policy. Supporting more than one container per unit is now really close. [NO NEW TESTS NEEDED] - should not change behavior. Signed-off-by: Valentin Rothberg --- pkg/autoupdate/autoupdate.go | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/pkg/autoupdate/autoupdate.go b/pkg/autoupdate/autoupdate.go index f450a4233..b3f0c53eb 100644 --- a/pkg/autoupdate/autoupdate.go +++ b/pkg/autoupdate/autoupdate.go @@ -182,6 +182,10 @@ func AutoUpdate(ctx context.Context, runtime *libpod.Runtime, options entities.A for _, task := range tasks { err := func() error { + // Transition from state to state. Will be + // split into multiple loops in the future to + // support more than one container/task per + // unit. updateAvailable, err := task.updateAvailable(ctx) if err != nil { task.status = statusFailed @@ -298,8 +302,11 @@ func (t *task) registryUpdate(ctx context.Context) error { return nil } - if err := pullImage(ctx, t.auto.runtime, t.rawImageName, t.authfile); err != nil { - return fmt.Errorf("registry auto-updating container %q: image update for %q failed: %w", t.container.ID(), t.rawImageName, err) + pullOptions := &libimage.PullOptions{} + pullOptions.AuthFilePath = t.authfile + pullOptions.Writer = os.Stderr + if _, err := t.auto.runtime.LibimageRuntime().Pull(ctx, t.rawImageName, config.PullPolicyAlways, pullOptions); err != nil { + return err } t.auto.updatedRawImages[t.rawImageName] = true @@ -448,13 +455,3 @@ func (u *updater) assembleImageMap(ctx context.Context) (map[string]*libimage.Im return imageMap, nil } - -// pullImage pulls the specified image. -func pullImage(ctx context.Context, runtime *libpod.Runtime, name, authfile string) error { - pullOptions := &libimage.PullOptions{} - pullOptions.AuthFilePath = authfile - pullOptions.Writer = os.Stderr - - _, err := runtime.LibimageRuntime().Pull(ctx, name, config.PullPolicyAlways, pullOptions) - return err -} -- cgit v1.2.3-54-g00ecf