From 9af8d56cddf3f000ebf6325998208cb4633b1ba9 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Thu, 5 Apr 2018 16:43:08 -0400 Subject: [PATCH] Allow image and snapshotkey to be updated This allows a container's image and snapshot key to be updated via the Update APIs. Signed-off-by: Michael Crosby --- metadata/containers.go | 14 +++---- metadata/containers_test.go | 77 ++++++++++++++++++++++++++----------- 2 files changed, 59 insertions(+), 32 deletions(-) diff --git a/metadata/containers.go b/metadata/containers.go index 2ba45c72f..2c9726fc2 100644 --- a/metadata/containers.go +++ b/metadata/containers.go @@ -164,19 +164,11 @@ func (s *containerStore) Update(ctx context.Context, container containers.Contai if len(fieldpaths) == 0 { // only allow updates to these field on full replace. - fieldpaths = []string{"labels", "spec", "extensions"} + fieldpaths = []string{"labels", "spec", "extensions", "image", "snapshotkey"} // Fields that are immutable must cause an error when no field paths // are provided. This allows these fields to become mutable in the // future. - if updated.Image != container.Image { - return containers.Container{}, errors.Wrapf(errdefs.ErrInvalidArgument, "container.Image field is immutable") - } - - if updated.SnapshotKey != container.SnapshotKey { - return containers.Container{}, errors.Wrapf(errdefs.ErrInvalidArgument, "container.SnapshotKey field is immutable") - } - if updated.Snapshotter != container.Snapshotter { return containers.Container{}, errors.Wrapf(errdefs.ErrInvalidArgument, "container.Snapshotter field is immutable") } @@ -215,6 +207,10 @@ func (s *containerStore) Update(ctx context.Context, container containers.Contai updated.Spec = container.Spec case "extensions": updated.Extensions = container.Extensions + case "image": + updated.Image = container.Image + case "snapshotkey": + updated.SnapshotKey = container.SnapshotKey default: return containers.Container{}, errors.Wrapf(errdefs.ErrInvalidArgument, "cannot update %q field on %q", path, container.ID) } diff --git a/metadata/containers_test.go b/metadata/containers_test.go index fa2c66789..ccad0cf4b 100644 --- a/metadata/containers_test.go +++ b/metadata/containers_test.go @@ -263,29 +263,6 @@ func TestContainersCreateUpdateDelete(t *testing.T) { fieldpaths: []string{"runtime"}, cause: errdefs.ErrInvalidArgument, }, - { - name: "UpdateFail", - original: containers.Container{ - Spec: encoded, - SnapshotKey: "test-snapshot-key", - Snapshotter: "snapshotter", - - Runtime: containers.RuntimeInfo{ - Name: "testruntime", - }, - Image: "test image", - }, - input: containers.Container{ - Spec: encoded, - Runtime: containers.RuntimeInfo{ - Name: "testruntime", - }, - SnapshotKey: "test-snapshot-key", - Snapshotter: "snapshotter", - // try to clear image field - }, - cause: errdefs.ErrInvalidArgument, - }, { name: "UpdateSpec", original: containers.Container{ @@ -311,6 +288,60 @@ func TestContainersCreateUpdateDelete(t *testing.T) { Image: "test image", }, }, + { + name: "UpdateSnapshot", + original: containers.Container{ + + Spec: encoded, + SnapshotKey: "test-snapshot-key", + Snapshotter: "snapshotter", + Runtime: containers.RuntimeInfo{ + Name: "testruntime", + }, + Image: "test image", + }, + input: containers.Container{ + SnapshotKey: "test2-snapshot-key", + }, + fieldpaths: []string{"snapshotkey"}, + expected: containers.Container{ + + Spec: encoded, + SnapshotKey: "test2-snapshot-key", + Snapshotter: "snapshotter", + Runtime: containers.RuntimeInfo{ + Name: "testruntime", + }, + Image: "test image", + }, + }, + { + name: "UpdateImage", + original: containers.Container{ + + Spec: encoded, + SnapshotKey: "test-snapshot-key", + Snapshotter: "snapshotter", + Runtime: containers.RuntimeInfo{ + Name: "testruntime", + }, + Image: "test image", + }, + input: containers.Container{ + Image: "test2 image", + }, + fieldpaths: []string{"image"}, + expected: containers.Container{ + + Spec: encoded, + SnapshotKey: "test-snapshot-key", + Snapshotter: "snapshotter", + Runtime: containers.RuntimeInfo{ + Name: "testruntime", + }, + Image: "test2 image", + }, + }, { name: "UpdateLabel", original: containers.Container{