mirror of
https://github.com/containers/podman.git
synced 2025-10-19 20:23:08 +08:00
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 <vrothberg@redhat.com>
This commit is contained in:
@ -182,6 +182,10 @@ func AutoUpdate(ctx context.Context, runtime *libpod.Runtime, options entities.A
|
|||||||
|
|
||||||
for _, task := range tasks {
|
for _, task := range tasks {
|
||||||
err := func() error {
|
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)
|
updateAvailable, err := task.updateAvailable(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
task.status = statusFailed
|
task.status = statusFailed
|
||||||
@ -298,8 +302,11 @@ func (t *task) registryUpdate(ctx context.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := pullImage(ctx, t.auto.runtime, t.rawImageName, t.authfile); err != nil {
|
pullOptions := &libimage.PullOptions{}
|
||||||
return fmt.Errorf("registry auto-updating container %q: image update for %q failed: %w", t.container.ID(), t.rawImageName, err)
|
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
|
t.auto.updatedRawImages[t.rawImageName] = true
|
||||||
@ -448,13 +455,3 @@ func (u *updater) assembleImageMap(ctx context.Context) (map[string]*libimage.Im
|
|||||||
|
|
||||||
return imageMap, nil
|
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
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user