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 <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby 2018-04-05 16:43:08 -04:00
parent 2bc17ef2cb
commit 9af8d56cdd
2 changed files with 59 additions and 32 deletions

View File

@ -164,19 +164,11 @@ func (s *containerStore) Update(ctx context.Context, container containers.Contai
if len(fieldpaths) == 0 { if len(fieldpaths) == 0 {
// only allow updates to these field on full replace. // 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 // Fields that are immutable must cause an error when no field paths
// are provided. This allows these fields to become mutable in the // are provided. This allows these fields to become mutable in the
// future. // 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 { if updated.Snapshotter != container.Snapshotter {
return containers.Container{}, errors.Wrapf(errdefs.ErrInvalidArgument, "container.Snapshotter field is immutable") 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 updated.Spec = container.Spec
case "extensions": case "extensions":
updated.Extensions = container.Extensions updated.Extensions = container.Extensions
case "image":
updated.Image = container.Image
case "snapshotkey":
updated.SnapshotKey = container.SnapshotKey
default: default:
return containers.Container{}, errors.Wrapf(errdefs.ErrInvalidArgument, "cannot update %q field on %q", path, container.ID) return containers.Container{}, errors.Wrapf(errdefs.ErrInvalidArgument, "cannot update %q field on %q", path, container.ID)
} }

View File

@ -263,29 +263,6 @@ func TestContainersCreateUpdateDelete(t *testing.T) {
fieldpaths: []string{"runtime"}, fieldpaths: []string{"runtime"},
cause: errdefs.ErrInvalidArgument, 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", name: "UpdateSpec",
original: containers.Container{ original: containers.Container{
@ -311,6 +288,60 @@ func TestContainersCreateUpdateDelete(t *testing.T) {
Image: "test image", 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", name: "UpdateLabel",
original: containers.Container{ original: containers.Container{