Merge pull request #2277 from crosbymichael/update-validation

Allow image and snapshotkey to be updated
This commit is contained in:
Phil Estes 2018-04-05 17:17:17 -04:00 committed by GitHub
commit f1cea3fa7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 {
// 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)
}

View File

@ -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{