mirror of
https://github.com/containers/podman.git
synced 2025-06-23 02:18:13 +08:00
auto update: pass through a context
Pass a single context.Context through the call stack. If auto-updates will ever be made available for REST calls, the context will help supporting disconnected clients. Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
This commit is contained in:
@ -118,7 +118,7 @@ func ValidateImageReference(imageName string) error {
|
|||||||
//
|
//
|
||||||
// It returns a slice of successfully restarted systemd units and a slice of
|
// It returns a slice of successfully restarted systemd units and a slice of
|
||||||
// errors encountered during auto update.
|
// errors encountered during auto update.
|
||||||
func AutoUpdate(runtime *libpod.Runtime, options Options) ([]string, []error) {
|
func AutoUpdate(ctx context.Context, runtime *libpod.Runtime, options Options) ([]string, []error) {
|
||||||
// Create a map from `image ID -> []*Container`.
|
// Create a map from `image ID -> []*Container`.
|
||||||
containerMap, errs := imageContainersMap(runtime)
|
containerMap, errs := imageContainersMap(runtime)
|
||||||
if len(containerMap) == 0 {
|
if len(containerMap) == 0 {
|
||||||
@ -129,7 +129,7 @@ func AutoUpdate(runtime *libpod.Runtime, options Options) ([]string, []error) {
|
|||||||
listOptions := &libimage.ListImagesOptions{
|
listOptions := &libimage.ListImagesOptions{
|
||||||
Filters: []string{"readonly=false"},
|
Filters: []string{"readonly=false"},
|
||||||
}
|
}
|
||||||
imagesSlice, err := runtime.LibimageRuntime().ListImages(context.Background(), nil, listOptions)
|
imagesSlice, err := runtime.LibimageRuntime().ListImages(ctx, nil, listOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, []error{err}
|
return nil, []error{err}
|
||||||
}
|
}
|
||||||
@ -165,7 +165,7 @@ func AutoUpdate(runtime *libpod.Runtime, options Options) ([]string, []error) {
|
|||||||
errs = append(errs, errors.Errorf("error registry auto-updating container %q: raw-image name is empty", cid))
|
errs = append(errs, errors.Errorf("error registry auto-updating container %q: raw-image name is empty", cid))
|
||||||
}
|
}
|
||||||
authfile := getAuthfilePath(registryCtr, options)
|
authfile := getAuthfilePath(registryCtr, options)
|
||||||
needsUpdate, err := newerRemoteImageAvailable(runtime, image, rawImageName, authfile)
|
needsUpdate, err := newerRemoteImageAvailable(ctx, runtime, image, rawImageName, authfile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errs = append(errs, errors.Wrapf(err, "error registry auto-updating container %q: image check for %q failed", cid, rawImageName))
|
errs = append(errs, errors.Wrapf(err, "error registry auto-updating container %q: image check for %q failed", cid, rawImageName))
|
||||||
continue
|
continue
|
||||||
@ -174,7 +174,7 @@ func AutoUpdate(runtime *libpod.Runtime, options Options) ([]string, []error) {
|
|||||||
if needsUpdate {
|
if needsUpdate {
|
||||||
logrus.Infof("Auto-updating container %q using registry image %q", cid, rawImageName)
|
logrus.Infof("Auto-updating container %q using registry image %q", cid, rawImageName)
|
||||||
if _, updated := updatedRawImages[rawImageName]; !updated {
|
if _, updated := updatedRawImages[rawImageName]; !updated {
|
||||||
_, err = updateImage(runtime, rawImageName, options)
|
_, err = updateImage(ctx, runtime, rawImageName, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errs = append(errs, errors.Wrapf(err, "error registry auto-updating container %q: image update for %q failed", cid, rawImageName))
|
errs = append(errs, errors.Wrapf(err, "error registry auto-updating container %q: image update for %q failed", cid, rawImageName))
|
||||||
continue
|
continue
|
||||||
@ -292,13 +292,13 @@ func getAuthfilePath(ctr *libpod.Container, options Options) string {
|
|||||||
|
|
||||||
// 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(runtime *libpod.Runtime, img *libimage.Image, origName string, authfile string) (bool, error) {
|
func newerRemoteImageAvailable(ctx context.Context, runtime *libpod.Runtime, img *libimage.Image, origName string, authfile string) (bool, error) {
|
||||||
remoteRef, err := docker.ParseReference("//" + origName)
|
remoteRef, err := docker.ParseReference("//" + origName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return img.HasDifferentDigest(context.Background(), remoteRef)
|
return img.HasDifferentDigest(ctx, remoteRef)
|
||||||
}
|
}
|
||||||
|
|
||||||
// newerLocalImageAvailable returns true if the container and local image have different digests
|
// newerLocalImageAvailable returns true if the container and local image have different digests
|
||||||
@ -316,12 +316,12 @@ func newerLocalImageAvailable(runtime *libpod.Runtime, img *libimage.Image, rawI
|
|||||||
}
|
}
|
||||||
|
|
||||||
// updateImage pulls the specified image.
|
// updateImage pulls the specified image.
|
||||||
func updateImage(runtime *libpod.Runtime, name string, options Options) (*libimage.Image, error) {
|
func updateImage(ctx context.Context, runtime *libpod.Runtime, name string, options Options) (*libimage.Image, error) {
|
||||||
pullOptions := &libimage.PullOptions{}
|
pullOptions := &libimage.PullOptions{}
|
||||||
pullOptions.AuthFilePath = options.Authfile
|
pullOptions.AuthFilePath = options.Authfile
|
||||||
pullOptions.Writer = os.Stderr
|
pullOptions.Writer = os.Stderr
|
||||||
|
|
||||||
pulledImages, err := runtime.LibimageRuntime().Pull(context.Background(), name, config.PullPolicyAlways, pullOptions)
|
pulledImages, err := runtime.LibimageRuntime().Pull(ctx, name, config.PullPolicyAlways, pullOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,6 @@ func (ic *ContainerEngine) AutoUpdate(ctx context.Context, options entities.Auto
|
|||||||
// them in the entities package as low-level packages must not leak
|
// them in the entities package as low-level packages must not leak
|
||||||
// into the remote client.
|
// into the remote client.
|
||||||
autoOpts := autoupdate.Options{Authfile: options.Authfile}
|
autoOpts := autoupdate.Options{Authfile: options.Authfile}
|
||||||
units, failures := autoupdate.AutoUpdate(ic.Libpod, autoOpts)
|
units, failures := autoupdate.AutoUpdate(ctx, ic.Libpod, autoOpts)
|
||||||
return &entities.AutoUpdateReport{Units: units}, failures
|
return &entities.AutoUpdateReport{Units: units}, failures
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user