api, metadata: use map type for Container.Extensions
To allow for updating extensions without collisions, we have moved to using a map type that can be explicitly selected via the field path for updates. This ensures that multiple parties can operate on their extensions without stepping on each other's toes or incurring an inordinate number of round trips. Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
@@ -428,8 +428,8 @@ func TestContainersCreateUpdateDelete(t *testing.T) {
|
||||
Runtime: containers.RuntimeInfo{
|
||||
Name: "testruntime",
|
||||
},
|
||||
Extensions: []types.Any{
|
||||
{
|
||||
Extensions: map[string]types.Any{
|
||||
"hello": {
|
||||
TypeUrl: "test.update.extensions",
|
||||
Value: []byte("hello"),
|
||||
},
|
||||
@@ -440,8 +440,8 @@ func TestContainersCreateUpdateDelete(t *testing.T) {
|
||||
Runtime: containers.RuntimeInfo{
|
||||
Name: "testruntime",
|
||||
},
|
||||
Extensions: []types.Any{
|
||||
{
|
||||
Extensions: map[string]types.Any{
|
||||
"hello": {
|
||||
TypeUrl: "test.update.extensions",
|
||||
Value: []byte("world"),
|
||||
},
|
||||
@@ -452,8 +452,8 @@ func TestContainersCreateUpdateDelete(t *testing.T) {
|
||||
Runtime: containers.RuntimeInfo{
|
||||
Name: "testruntime",
|
||||
},
|
||||
Extensions: []types.Any{
|
||||
{
|
||||
Extensions: map[string]types.Any{
|
||||
"hello": {
|
||||
TypeUrl: "test.update.extensions",
|
||||
Value: []byte("world"),
|
||||
},
|
||||
@@ -467,8 +467,8 @@ func TestContainersCreateUpdateDelete(t *testing.T) {
|
||||
Runtime: containers.RuntimeInfo{
|
||||
Name: "testruntime",
|
||||
},
|
||||
Extensions: []types.Any{
|
||||
{
|
||||
Extensions: map[string]types.Any{
|
||||
"hello": {
|
||||
TypeUrl: "test.update.extensions",
|
||||
Value: []byte("hello"),
|
||||
},
|
||||
@@ -479,8 +479,8 @@ func TestContainersCreateUpdateDelete(t *testing.T) {
|
||||
Runtime: containers.RuntimeInfo{
|
||||
Name: "testruntime",
|
||||
},
|
||||
Extensions: []types.Any{
|
||||
{
|
||||
Extensions: map[string]types.Any{
|
||||
"hello": {
|
||||
TypeUrl: "test.update.extensions",
|
||||
Value: []byte("world"),
|
||||
},
|
||||
@@ -492,8 +492,8 @@ func TestContainersCreateUpdateDelete(t *testing.T) {
|
||||
Runtime: containers.RuntimeInfo{
|
||||
Name: "testruntime",
|
||||
},
|
||||
Extensions: []types.Any{
|
||||
{
|
||||
Extensions: map[string]types.Any{
|
||||
"hello": {
|
||||
TypeUrl: "test.update.extensions",
|
||||
Value: []byte("hello"),
|
||||
},
|
||||
@@ -507,8 +507,8 @@ func TestContainersCreateUpdateDelete(t *testing.T) {
|
||||
Runtime: containers.RuntimeInfo{
|
||||
Name: "testruntime",
|
||||
},
|
||||
Extensions: []types.Any{
|
||||
{
|
||||
Extensions: map[string]types.Any{
|
||||
"hello": {
|
||||
TypeUrl: "test.update.extensions",
|
||||
Value: []byte("hello"),
|
||||
},
|
||||
@@ -518,8 +518,8 @@ func TestContainersCreateUpdateDelete(t *testing.T) {
|
||||
Labels: map[string]string{
|
||||
"foo": "one",
|
||||
},
|
||||
Extensions: []types.Any{
|
||||
{
|
||||
Extensions: map[string]types.Any{
|
||||
"hello": {
|
||||
TypeUrl: "test.update.extensions",
|
||||
Value: []byte("world"),
|
||||
},
|
||||
@@ -531,14 +531,59 @@ func TestContainersCreateUpdateDelete(t *testing.T) {
|
||||
Runtime: containers.RuntimeInfo{
|
||||
Name: "testruntime",
|
||||
},
|
||||
Extensions: []types.Any{
|
||||
{
|
||||
Extensions: map[string]types.Any{
|
||||
"hello": {
|
||||
TypeUrl: "test.update.extensions",
|
||||
Value: []byte("world"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "UpdateExtensionsFieldPathIsolated",
|
||||
original: containers.Container{
|
||||
Spec: encoded,
|
||||
Runtime: containers.RuntimeInfo{
|
||||
Name: "testruntime",
|
||||
},
|
||||
Extensions: map[string]types.Any{
|
||||
// leaves hello in place.
|
||||
"hello": {
|
||||
TypeUrl: "test.update.extensions",
|
||||
Value: []byte("hello"),
|
||||
},
|
||||
},
|
||||
},
|
||||
input: containers.Container{
|
||||
Extensions: map[string]types.Any{
|
||||
"hello": {
|
||||
TypeUrl: "test.update.extensions",
|
||||
Value: []byte("universe"), // this will be ignored
|
||||
},
|
||||
"bar": {
|
||||
TypeUrl: "test.update.extensions",
|
||||
Value: []byte("foo"), // this will be added
|
||||
},
|
||||
},
|
||||
},
|
||||
fieldpaths: []string{"extensions.bar"}, //
|
||||
expected: containers.Container{
|
||||
Spec: encoded,
|
||||
Runtime: containers.RuntimeInfo{
|
||||
Name: "testruntime",
|
||||
},
|
||||
Extensions: map[string]types.Any{
|
||||
"hello": {
|
||||
TypeUrl: "test.update.extensions",
|
||||
Value: []byte("hello"), // remains as world
|
||||
},
|
||||
"bar": {
|
||||
TypeUrl: "test.update.extensions",
|
||||
Value: []byte("foo"), // this will be added
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} {
|
||||
t.Run(testcase.name, func(t *testing.T) {
|
||||
testcase.original.ID = testcase.name
|
||||
@@ -648,7 +693,7 @@ func checkContainerTimestamps(t *testing.T, c *containers.Container, now time.Ti
|
||||
|
||||
func checkContainersEqual(t *testing.T, a, b *containers.Container, format string, args ...interface{}) {
|
||||
if !reflect.DeepEqual(a, b) {
|
||||
t.Fatalf("containers not equal %v != %v: "+format, append([]interface{}{a, b}, args...)...)
|
||||
t.Fatalf("containers not equal \n\t%v != \n\t%v: "+format, append([]interface{}{a, b}, args...)...)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user