Merge pull request #1378 from cpuguy83/container_store_extra_data
Add `Container` field to store client-defined data
This commit is contained in:
commit
e517952bc7
@ -185,6 +185,17 @@ file {
|
|||||||
}
|
}
|
||||||
json_name: "updatedAt"
|
json_name: "updatedAt"
|
||||||
}
|
}
|
||||||
|
field {
|
||||||
|
name: "extensions"
|
||||||
|
number: 10
|
||||||
|
label: LABEL_REPEATED
|
||||||
|
type: TYPE_MESSAGE
|
||||||
|
type_name: ".containerd.services.containers.v1.Container.ExtensionsEntry"
|
||||||
|
options {
|
||||||
|
65001: 0
|
||||||
|
}
|
||||||
|
json_name: "extensions"
|
||||||
|
}
|
||||||
nested_type {
|
nested_type {
|
||||||
name: "LabelsEntry"
|
name: "LabelsEntry"
|
||||||
field {
|
field {
|
||||||
@ -223,6 +234,27 @@ file {
|
|||||||
json_name: "options"
|
json_name: "options"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
nested_type {
|
||||||
|
name: "ExtensionsEntry"
|
||||||
|
field {
|
||||||
|
name: "key"
|
||||||
|
number: 1
|
||||||
|
label: LABEL_OPTIONAL
|
||||||
|
type: TYPE_STRING
|
||||||
|
json_name: "key"
|
||||||
|
}
|
||||||
|
field {
|
||||||
|
name: "value"
|
||||||
|
number: 2
|
||||||
|
label: LABEL_OPTIONAL
|
||||||
|
type: TYPE_MESSAGE
|
||||||
|
type_name: ".google.protobuf.Any"
|
||||||
|
json_name: "value"
|
||||||
|
}
|
||||||
|
options {
|
||||||
|
map_entry: true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
message_type {
|
message_type {
|
||||||
name: "GetContainerRequest"
|
name: "GetContainerRequest"
|
||||||
|
@ -94,6 +94,16 @@ type Container struct {
|
|||||||
CreatedAt time.Time `protobuf:"bytes,8,opt,name=created_at,json=createdAt,stdtime" json:"created_at"`
|
CreatedAt time.Time `protobuf:"bytes,8,opt,name=created_at,json=createdAt,stdtime" json:"created_at"`
|
||||||
// UpdatedAt is the last time the container was mutated.
|
// UpdatedAt is the last time the container was mutated.
|
||||||
UpdatedAt time.Time `protobuf:"bytes,9,opt,name=updated_at,json=updatedAt,stdtime" json:"updated_at"`
|
UpdatedAt time.Time `protobuf:"bytes,9,opt,name=updated_at,json=updatedAt,stdtime" json:"updated_at"`
|
||||||
|
// Extensions allow clients to provide zero or more blobs that are directly
|
||||||
|
// associated with the container. One may provide protobuf, json, or other
|
||||||
|
// encoding formats. The primary use of this is to further decorate the
|
||||||
|
// container object with fields that may be specific to a client integration.
|
||||||
|
//
|
||||||
|
// The key portion of this map should identify a "name" for the extension
|
||||||
|
// that should be unique against other extensions. When updating extension
|
||||||
|
// data, one should only update the specified extension using field paths
|
||||||
|
// to select a specific map key.
|
||||||
|
Extensions map[string]google_protobuf1.Any `protobuf:"bytes,10,rep,name=extensions" json:"extensions" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Container) Reset() { *m = Container{} }
|
func (m *Container) Reset() { *m = Container{} }
|
||||||
@ -518,6 +528,32 @@ func (m *Container) MarshalTo(dAtA []byte) (int, error) {
|
|||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
i += n4
|
i += n4
|
||||||
|
if len(m.Extensions) > 0 {
|
||||||
|
for k, _ := range m.Extensions {
|
||||||
|
dAtA[i] = 0x52
|
||||||
|
i++
|
||||||
|
v := m.Extensions[k]
|
||||||
|
msgSize := 0
|
||||||
|
if (&v) != nil {
|
||||||
|
msgSize = (&v).Size()
|
||||||
|
msgSize += 1 + sovContainers(uint64(msgSize))
|
||||||
|
}
|
||||||
|
mapSize := 1 + len(k) + sovContainers(uint64(len(k))) + msgSize
|
||||||
|
i = encodeVarintContainers(dAtA, i, uint64(mapSize))
|
||||||
|
dAtA[i] = 0xa
|
||||||
|
i++
|
||||||
|
i = encodeVarintContainers(dAtA, i, uint64(len(k)))
|
||||||
|
i += copy(dAtA[i:], k)
|
||||||
|
dAtA[i] = 0x12
|
||||||
|
i++
|
||||||
|
i = encodeVarintContainers(dAtA, i, uint64((&v).Size()))
|
||||||
|
n5, err := (&v).MarshalTo(dAtA[i:])
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
i += n5
|
||||||
|
}
|
||||||
|
}
|
||||||
return i, nil
|
return i, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -546,11 +582,11 @@ func (m *Container_Runtime) MarshalTo(dAtA []byte) (int, error) {
|
|||||||
dAtA[i] = 0x12
|
dAtA[i] = 0x12
|
||||||
i++
|
i++
|
||||||
i = encodeVarintContainers(dAtA, i, uint64(m.Options.Size()))
|
i = encodeVarintContainers(dAtA, i, uint64(m.Options.Size()))
|
||||||
n5, err := m.Options.MarshalTo(dAtA[i:])
|
n6, err := m.Options.MarshalTo(dAtA[i:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
i += n5
|
i += n6
|
||||||
}
|
}
|
||||||
return i, nil
|
return i, nil
|
||||||
}
|
}
|
||||||
@ -597,11 +633,11 @@ func (m *GetContainerResponse) MarshalTo(dAtA []byte) (int, error) {
|
|||||||
dAtA[i] = 0xa
|
dAtA[i] = 0xa
|
||||||
i++
|
i++
|
||||||
i = encodeVarintContainers(dAtA, i, uint64(m.Container.Size()))
|
i = encodeVarintContainers(dAtA, i, uint64(m.Container.Size()))
|
||||||
n6, err := m.Container.MarshalTo(dAtA[i:])
|
n7, err := m.Container.MarshalTo(dAtA[i:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
i += n6
|
i += n7
|
||||||
return i, nil
|
return i, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -686,11 +722,11 @@ func (m *CreateContainerRequest) MarshalTo(dAtA []byte) (int, error) {
|
|||||||
dAtA[i] = 0xa
|
dAtA[i] = 0xa
|
||||||
i++
|
i++
|
||||||
i = encodeVarintContainers(dAtA, i, uint64(m.Container.Size()))
|
i = encodeVarintContainers(dAtA, i, uint64(m.Container.Size()))
|
||||||
n7, err := m.Container.MarshalTo(dAtA[i:])
|
n8, err := m.Container.MarshalTo(dAtA[i:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
i += n7
|
i += n8
|
||||||
return i, nil
|
return i, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -712,11 +748,11 @@ func (m *CreateContainerResponse) MarshalTo(dAtA []byte) (int, error) {
|
|||||||
dAtA[i] = 0xa
|
dAtA[i] = 0xa
|
||||||
i++
|
i++
|
||||||
i = encodeVarintContainers(dAtA, i, uint64(m.Container.Size()))
|
i = encodeVarintContainers(dAtA, i, uint64(m.Container.Size()))
|
||||||
n8, err := m.Container.MarshalTo(dAtA[i:])
|
n9, err := m.Container.MarshalTo(dAtA[i:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
i += n8
|
i += n9
|
||||||
return i, nil
|
return i, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -738,20 +774,20 @@ func (m *UpdateContainerRequest) MarshalTo(dAtA []byte) (int, error) {
|
|||||||
dAtA[i] = 0xa
|
dAtA[i] = 0xa
|
||||||
i++
|
i++
|
||||||
i = encodeVarintContainers(dAtA, i, uint64(m.Container.Size()))
|
i = encodeVarintContainers(dAtA, i, uint64(m.Container.Size()))
|
||||||
n9, err := m.Container.MarshalTo(dAtA[i:])
|
n10, err := m.Container.MarshalTo(dAtA[i:])
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
i += n9
|
|
||||||
if m.UpdateMask != nil {
|
|
||||||
dAtA[i] = 0x12
|
|
||||||
i++
|
|
||||||
i = encodeVarintContainers(dAtA, i, uint64(m.UpdateMask.Size()))
|
|
||||||
n10, err := m.UpdateMask.MarshalTo(dAtA[i:])
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
i += n10
|
i += n10
|
||||||
|
if m.UpdateMask != nil {
|
||||||
|
dAtA[i] = 0x12
|
||||||
|
i++
|
||||||
|
i = encodeVarintContainers(dAtA, i, uint64(m.UpdateMask.Size()))
|
||||||
|
n11, err := m.UpdateMask.MarshalTo(dAtA[i:])
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
i += n11
|
||||||
}
|
}
|
||||||
return i, nil
|
return i, nil
|
||||||
}
|
}
|
||||||
@ -774,11 +810,11 @@ func (m *UpdateContainerResponse) MarshalTo(dAtA []byte) (int, error) {
|
|||||||
dAtA[i] = 0xa
|
dAtA[i] = 0xa
|
||||||
i++
|
i++
|
||||||
i = encodeVarintContainers(dAtA, i, uint64(m.Container.Size()))
|
i = encodeVarintContainers(dAtA, i, uint64(m.Container.Size()))
|
||||||
n11, err := m.Container.MarshalTo(dAtA[i:])
|
n12, err := m.Container.MarshalTo(dAtA[i:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
i += n11
|
i += n12
|
||||||
return i, nil
|
return i, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -872,6 +908,15 @@ func (m *Container) Size() (n int) {
|
|||||||
n += 1 + l + sovContainers(uint64(l))
|
n += 1 + l + sovContainers(uint64(l))
|
||||||
l = github_com_gogo_protobuf_types.SizeOfStdTime(m.UpdatedAt)
|
l = github_com_gogo_protobuf_types.SizeOfStdTime(m.UpdatedAt)
|
||||||
n += 1 + l + sovContainers(uint64(l))
|
n += 1 + l + sovContainers(uint64(l))
|
||||||
|
if len(m.Extensions) > 0 {
|
||||||
|
for k, v := range m.Extensions {
|
||||||
|
_ = k
|
||||||
|
_ = v
|
||||||
|
l = v.Size()
|
||||||
|
mapEntrySize := 1 + len(k) + sovContainers(uint64(len(k))) + 1 + l + sovContainers(uint64(l))
|
||||||
|
n += mapEntrySize + 1 + sovContainers(uint64(mapEntrySize))
|
||||||
|
}
|
||||||
|
}
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1004,6 +1049,16 @@ func (this *Container) String() string {
|
|||||||
mapStringForLabels += fmt.Sprintf("%v: %v,", k, this.Labels[k])
|
mapStringForLabels += fmt.Sprintf("%v: %v,", k, this.Labels[k])
|
||||||
}
|
}
|
||||||
mapStringForLabels += "}"
|
mapStringForLabels += "}"
|
||||||
|
keysForExtensions := make([]string, 0, len(this.Extensions))
|
||||||
|
for k, _ := range this.Extensions {
|
||||||
|
keysForExtensions = append(keysForExtensions, k)
|
||||||
|
}
|
||||||
|
github_com_gogo_protobuf_sortkeys.Strings(keysForExtensions)
|
||||||
|
mapStringForExtensions := "map[string]google_protobuf1.Any{"
|
||||||
|
for _, k := range keysForExtensions {
|
||||||
|
mapStringForExtensions += fmt.Sprintf("%v: %v,", k, this.Extensions[k])
|
||||||
|
}
|
||||||
|
mapStringForExtensions += "}"
|
||||||
s := strings.Join([]string{`&Container{`,
|
s := strings.Join([]string{`&Container{`,
|
||||||
`ID:` + fmt.Sprintf("%v", this.ID) + `,`,
|
`ID:` + fmt.Sprintf("%v", this.ID) + `,`,
|
||||||
`Labels:` + mapStringForLabels + `,`,
|
`Labels:` + mapStringForLabels + `,`,
|
||||||
@ -1014,6 +1069,7 @@ func (this *Container) String() string {
|
|||||||
`SnapshotKey:` + fmt.Sprintf("%v", this.SnapshotKey) + `,`,
|
`SnapshotKey:` + fmt.Sprintf("%v", this.SnapshotKey) + `,`,
|
||||||
`CreatedAt:` + strings.Replace(strings.Replace(this.CreatedAt.String(), "Timestamp", "google_protobuf4.Timestamp", 1), `&`, ``, 1) + `,`,
|
`CreatedAt:` + strings.Replace(strings.Replace(this.CreatedAt.String(), "Timestamp", "google_protobuf4.Timestamp", 1), `&`, ``, 1) + `,`,
|
||||||
`UpdatedAt:` + strings.Replace(strings.Replace(this.UpdatedAt.String(), "Timestamp", "google_protobuf4.Timestamp", 1), `&`, ``, 1) + `,`,
|
`UpdatedAt:` + strings.Replace(strings.Replace(this.UpdatedAt.String(), "Timestamp", "google_protobuf4.Timestamp", 1), `&`, ``, 1) + `,`,
|
||||||
|
`Extensions:` + mapStringForExtensions + `,`,
|
||||||
`}`,
|
`}`,
|
||||||
}, "")
|
}, "")
|
||||||
return s
|
return s
|
||||||
@ -1515,6 +1571,127 @@ func (m *Container) Unmarshal(dAtA []byte) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
iNdEx = postIndex
|
iNdEx = postIndex
|
||||||
|
case 10:
|
||||||
|
if wireType != 2 {
|
||||||
|
return fmt.Errorf("proto: wrong wireType = %d for field Extensions", wireType)
|
||||||
|
}
|
||||||
|
var msglen int
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return ErrIntOverflowContainers
|
||||||
|
}
|
||||||
|
if iNdEx >= l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
b := dAtA[iNdEx]
|
||||||
|
iNdEx++
|
||||||
|
msglen |= (int(b) & 0x7F) << shift
|
||||||
|
if b < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if msglen < 0 {
|
||||||
|
return ErrInvalidLengthContainers
|
||||||
|
}
|
||||||
|
postIndex := iNdEx + msglen
|
||||||
|
if postIndex > l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
var keykey uint64
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return ErrIntOverflowContainers
|
||||||
|
}
|
||||||
|
if iNdEx >= l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
b := dAtA[iNdEx]
|
||||||
|
iNdEx++
|
||||||
|
keykey |= (uint64(b) & 0x7F) << shift
|
||||||
|
if b < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var stringLenmapkey uint64
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return ErrIntOverflowContainers
|
||||||
|
}
|
||||||
|
if iNdEx >= l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
b := dAtA[iNdEx]
|
||||||
|
iNdEx++
|
||||||
|
stringLenmapkey |= (uint64(b) & 0x7F) << shift
|
||||||
|
if b < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
intStringLenmapkey := int(stringLenmapkey)
|
||||||
|
if intStringLenmapkey < 0 {
|
||||||
|
return ErrInvalidLengthContainers
|
||||||
|
}
|
||||||
|
postStringIndexmapkey := iNdEx + intStringLenmapkey
|
||||||
|
if postStringIndexmapkey > l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
mapkey := string(dAtA[iNdEx:postStringIndexmapkey])
|
||||||
|
iNdEx = postStringIndexmapkey
|
||||||
|
if m.Extensions == nil {
|
||||||
|
m.Extensions = make(map[string]google_protobuf1.Any)
|
||||||
|
}
|
||||||
|
if iNdEx < postIndex {
|
||||||
|
var valuekey uint64
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return ErrIntOverflowContainers
|
||||||
|
}
|
||||||
|
if iNdEx >= l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
b := dAtA[iNdEx]
|
||||||
|
iNdEx++
|
||||||
|
valuekey |= (uint64(b) & 0x7F) << shift
|
||||||
|
if b < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var mapmsglen int
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return ErrIntOverflowContainers
|
||||||
|
}
|
||||||
|
if iNdEx >= l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
b := dAtA[iNdEx]
|
||||||
|
iNdEx++
|
||||||
|
mapmsglen |= (int(b) & 0x7F) << shift
|
||||||
|
if b < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if mapmsglen < 0 {
|
||||||
|
return ErrInvalidLengthContainers
|
||||||
|
}
|
||||||
|
postmsgIndex := iNdEx + mapmsglen
|
||||||
|
if mapmsglen < 0 {
|
||||||
|
return ErrInvalidLengthContainers
|
||||||
|
}
|
||||||
|
if postmsgIndex > l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
mapvalue := &google_protobuf1.Any{}
|
||||||
|
if err := mapvalue.Unmarshal(dAtA[iNdEx:postmsgIndex]); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
iNdEx = postmsgIndex
|
||||||
|
m.Extensions[mapkey] = *mapvalue
|
||||||
|
} else {
|
||||||
|
var mapvalue google_protobuf1.Any
|
||||||
|
m.Extensions[mapkey] = mapvalue
|
||||||
|
}
|
||||||
|
iNdEx = postIndex
|
||||||
default:
|
default:
|
||||||
iNdEx = preIndex
|
iNdEx = preIndex
|
||||||
skippy, err := skipContainers(dAtA[iNdEx:])
|
skippy, err := skipContainers(dAtA[iNdEx:])
|
||||||
@ -2509,51 +2686,54 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var fileDescriptorContainers = []byte{
|
var fileDescriptorContainers = []byte{
|
||||||
// 730 bytes of a gzipped FileDescriptorProto
|
// 776 bytes of a gzipped FileDescriptorProto
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0xcb, 0x72, 0x12, 0x41,
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0xcd, 0x72, 0x12, 0x5b,
|
||||||
0x14, 0xcd, 0xc0, 0x04, 0xc2, 0xc5, 0x85, 0xd5, 0x22, 0x8e, 0x63, 0x15, 0x10, 0x56, 0x2c, 0x74,
|
0x10, 0xce, 0x00, 0x81, 0xd0, 0xdc, 0xaa, 0x7b, 0xeb, 0x5c, 0x2e, 0x77, 0x1c, 0xab, 0x80, 0xb0,
|
||||||
0x30, 0x68, 0x69, 0x1e, 0xab, 0x90, 0x57, 0x59, 0x26, 0x56, 0xaa, 0x4b, 0x37, 0xba, 0x88, 0x0d,
|
0xa2, 0x2c, 0x1d, 0x0c, 0x5a, 0x9a, 0x1f, 0x37, 0x21, 0x7f, 0x65, 0x99, 0x58, 0xa9, 0x51, 0x37,
|
||||||
0x74, 0xc8, 0xc8, 0xbc, 0x9c, 0x6e, 0xa8, 0xa2, 0x5c, 0xe8, 0x27, 0xf8, 0x17, 0xfe, 0x4a, 0x96,
|
0xba, 0x88, 0x03, 0x74, 0xc8, 0xc8, 0xfc, 0x39, 0xe7, 0x40, 0x49, 0xb9, 0xd0, 0x47, 0x70, 0xe7,
|
||||||
0x2e, 0x5d, 0xc5, 0x84, 0x2f, 0xb1, 0xba, 0x67, 0x26, 0x43, 0x78, 0x94, 0x10, 0x65, 0x77, 0x2f,
|
0x23, 0xf8, 0x2a, 0x59, 0xba, 0x74, 0x15, 0x13, 0x9e, 0xc4, 0x9a, 0x33, 0x33, 0xcc, 0x04, 0x06,
|
||||||
0x7d, 0xcf, 0xbd, 0x67, 0x4e, 0x9f, 0x3b, 0x0c, 0x1c, 0xb6, 0x4d, 0x7e, 0xd6, 0x6d, 0x18, 0x4d,
|
0x85, 0x68, 0x76, 0xa7, 0x39, 0xfd, 0x7d, 0xfd, 0xf1, 0x75, 0xf7, 0x01, 0xd8, 0xef, 0x68, 0xec,
|
||||||
0xd7, 0xae, 0x36, 0x5d, 0x87, 0x13, 0xd3, 0xa1, 0x7e, 0x6b, 0x38, 0x24, 0x9e, 0x59, 0x65, 0xd4,
|
0xa4, 0xd7, 0x94, 0x5b, 0x96, 0x51, 0x6b, 0x59, 0x26, 0x53, 0x35, 0x13, 0x9d, 0x76, 0xf4, 0xa8,
|
||||||
0xef, 0x99, 0x4d, 0xca, 0xe2, 0xdf, 0x59, 0xb5, 0xb7, 0x36, 0x94, 0x19, 0x9e, 0xef, 0x72, 0x17,
|
0xda, 0x5a, 0x8d, 0xa2, 0xd3, 0xd7, 0x5a, 0x48, 0xc3, 0xcf, 0x69, 0xad, 0xbf, 0x12, 0x89, 0x64,
|
||||||
0xad, 0xc6, 0x38, 0x23, 0xc2, 0x18, 0x43, 0x55, 0xbd, 0x35, 0x3d, 0xd7, 0x76, 0xdb, 0xae, 0xac,
|
0xdb, 0xb1, 0x98, 0x45, 0x96, 0x43, 0x9c, 0x1c, 0x60, 0xe4, 0x48, 0x56, 0x7f, 0x45, 0xca, 0x77,
|
||||||
0xae, 0x8a, 0x28, 0x00, 0xea, 0x0f, 0xdb, 0xae, 0xdb, 0xb6, 0x68, 0x55, 0x66, 0x8d, 0xee, 0x69,
|
0xac, 0x8e, 0xc5, 0xb3, 0x6b, 0xee, 0xc9, 0x03, 0x4a, 0x37, 0x3a, 0x96, 0xd5, 0xd1, 0xb1, 0xc6,
|
||||||
0x95, 0x38, 0xfd, 0xf0, 0xe8, 0xd1, 0xe8, 0x11, 0xb5, 0x3d, 0x1e, 0x1d, 0x96, 0x46, 0x0f, 0x4f,
|
0xa3, 0x66, 0xef, 0xb8, 0xa6, 0x9a, 0x03, 0xff, 0xea, 0xe6, 0xf8, 0x15, 0x1a, 0x36, 0x0b, 0x2e,
|
||||||
0x4d, 0x6a, 0xb5, 0x4e, 0x6c, 0xc2, 0x3a, 0x61, 0x45, 0x71, 0xb4, 0x82, 0x9b, 0x36, 0x65, 0x9c,
|
0xcb, 0xe3, 0x97, 0xc7, 0x1a, 0xea, 0xed, 0x23, 0x43, 0xa5, 0x5d, 0x3f, 0xa3, 0x34, 0x9e, 0xc1,
|
||||||
0xd8, 0x5e, 0x50, 0x50, 0xbe, 0x50, 0x21, 0xb3, 0x13, 0x51, 0x44, 0x79, 0x48, 0x98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d,
|
||||||
0xd2, 0x64, 0xf2, 0x42, 0xe9, 0x9b, 0xb7, 0x81, 0xc6, 0x04, 0x02, 0x8f, 0xcc, 0x44, 0x60, 0xb2,
|
0x3c, 0x05, 0x10, 0x0e, 0x23, 0xe9, 0x43, 0x72, 0x0f, 0x19, 0x79, 0x30, 0x83, 0x8c, 0x98, 0x95,
|
||||||
0xef, 0x67, 0x22, 0x30, 0xcd, 0x89, 0x1f, 0x20, 0x15, 0xf8, 0x66, 0x26, 0x02, 0x93, 0x2d, 0xa6,
|
0x94, 0x1e, 0xce, 0x8d, 0xf3, 0xad, 0x78, 0x0f, 0x29, 0x77, 0x2d, 0xc8, 0x2c, 0x3f, 0x67, 0xb1,
|
||||||
0xe7, 0xc7, 0x36, 0x62, 0x4f, 0x7c, 0x68, 0xd4, 0x3f, 0x9e, 0x5f, 0x15, 0x96, 0x7e, 0x5d, 0x15,
|
0x2b, 0x27, 0xad, 0x5d, 0x01, 0xe9, 0x17, 0xff, 0x00, 0x69, 0x6f, 0x72, 0xc9, 0x2c, 0x24, 0xf1,
|
||||||
0x96, 0xbe, 0x0d, 0x0a, 0xca, 0xf9, 0xa0, 0xa0, 0xfc, 0x1c, 0x14, 0x94, 0xcb, 0x41, 0x41, 0x79,
|
0x0b, 0x25, 0xad, 0x5f, 0x05, 0x1a, 0x0a, 0xf0, 0x66, 0x64, 0x26, 0x01, 0xf1, 0x73, 0x3f, 0x93,
|
||||||
0xbf, 0xff, 0x0f, 0xdf, 0x4e, 0x5b, 0x71, 0xd6, 0x48, 0xc9, 0x89, 0xcf, 0xfe, 0x04, 0x00, 0x00,
|
0x80, 0x69, 0x93, 0xf8, 0x0a, 0xd2, 0xde, 0xdc, 0xcc, 0x24, 0x20, 0x7e, 0xc4, 0xa4, 0xc2, 0xc4,
|
||||||
0xff, 0xff, 0x7e, 0x6d, 0xca, 0xbd, 0x8c, 0x09, 0x00, 0x00,
|
0x46, 0xec, 0xb8, 0xff, 0x90, 0x1a, 0xaf, 0x4f, 0x2f, 0x8a, 0x0b, 0xdf, 0x2e, 0x8a, 0x0b, 0x1f,
|
||||||
|
0x87, 0x45, 0xe1, 0x74, 0x58, 0x14, 0xbe, 0x0e, 0x8b, 0xc2, 0xf9, 0xb0, 0x28, 0xbc, 0xdc, 0xfd,
|
||||||
|
0x8d, 0x3f, 0x7d, 0x1b, 0x61, 0xd4, 0x4c, 0xf3, 0x8a, 0xf7, 0x7e, 0x04, 0x00, 0x00, 0xff, 0xff,
|
||||||
|
0x17, 0x73, 0xba, 0x43, 0x45, 0x0a, 0x00, 0x00,
|
||||||
}
|
}
|
||||||
|
@ -84,6 +84,17 @@ message Container {
|
|||||||
|
|
||||||
// UpdatedAt is the last time the container was mutated.
|
// UpdatedAt is the last time the container was mutated.
|
||||||
google.protobuf.Timestamp updated_at = 9 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
|
google.protobuf.Timestamp updated_at = 9 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
|
||||||
|
|
||||||
|
// Extensions allow clients to provide zero or more blobs that are directly
|
||||||
|
// associated with the container. One may provide protobuf, json, or other
|
||||||
|
// encoding formats. The primary use of this is to further decorate the
|
||||||
|
// container object with fields that may be specific to a client integration.
|
||||||
|
//
|
||||||
|
// The key portion of this map should identify a "name" for the extension
|
||||||
|
// that should be unique against other extensions. When updating extension
|
||||||
|
// data, one should only update the specified extension using field paths
|
||||||
|
// to select a specific map key.
|
||||||
|
map<string, google.protobuf.Any> extensions = 10 [(gogoproto.nullable) = false];
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetContainerRequest {
|
message GetContainerRequest {
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/containerd/containerd/containers"
|
"github.com/containerd/containerd/containers"
|
||||||
"github.com/containerd/containerd/errdefs"
|
"github.com/containerd/containerd/errdefs"
|
||||||
"github.com/containerd/containerd/typeurl"
|
"github.com/containerd/containerd/typeurl"
|
||||||
|
prototypes "github.com/gogo/protobuf/types"
|
||||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
@ -42,6 +43,8 @@ type Container interface {
|
|||||||
Labels(context.Context) (map[string]string, error)
|
Labels(context.Context) (map[string]string, error)
|
||||||
// SetLabels sets the provided labels for the container and returns the final label set
|
// SetLabels sets the provided labels for the container and returns the final label set
|
||||||
SetLabels(context.Context, map[string]string) (map[string]string, error)
|
SetLabels(context.Context, map[string]string) (map[string]string, error)
|
||||||
|
// Extensions returns the extensions set on the container
|
||||||
|
Extensions() map[string]prototypes.Any
|
||||||
}
|
}
|
||||||
|
|
||||||
func containerFromRecord(client *Client, c containers.Container) *container {
|
func containerFromRecord(client *Client, c containers.Container) *container {
|
||||||
@ -158,6 +161,12 @@ func (c *container) Image(ctx context.Context) (Image, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *container) Extensions() map[string]prototypes.Any {
|
||||||
|
c.mu.Lock()
|
||||||
|
defer c.mu.Unlock()
|
||||||
|
return c.c.Extensions
|
||||||
|
}
|
||||||
|
|
||||||
func (c *container) NewTask(ctx context.Context, ioCreate IOCreation, opts ...NewTaskOpts) (Task, error) {
|
func (c *container) NewTask(ctx context.Context, ioCreate IOCreation, opts ...NewTaskOpts) (Task, error) {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
defer c.mu.Unlock()
|
defer c.mu.Unlock()
|
||||||
|
@ -128,3 +128,28 @@ func setSnapshotterIfEmpty(c *containers.Container) {
|
|||||||
c.Snapshotter = DefaultSnapshotter
|
c.Snapshotter = DefaultSnapshotter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithContainerExtension appends extension data to the container object.
|
||||||
|
// Use this to decorate the container object with additional data for the client
|
||||||
|
// integration.
|
||||||
|
//
|
||||||
|
// Make sure to register the type of `extension` in the typeurl package via
|
||||||
|
// `typeurl.Register` otherwise the type data will be inferred, including how
|
||||||
|
// to encode and decode the object.
|
||||||
|
func WithContainerExtension(name string, extension interface{}) NewContainerOpts {
|
||||||
|
return func(ctx context.Context, client *Client, c *containers.Container) error {
|
||||||
|
any, err := typeurl.MarshalAny(extension)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if name == "" {
|
||||||
|
return errors.Wrapf(errdefs.ErrInvalidArgument, "extension key must not be zero-length")
|
||||||
|
}
|
||||||
|
if c.Extensions == nil {
|
||||||
|
c.Extensions = make(map[string]types.Any)
|
||||||
|
}
|
||||||
|
c.Extensions[name] = *any
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
_ "github.com/containerd/containerd/runtime"
|
_ "github.com/containerd/containerd/runtime"
|
||||||
|
|
||||||
"github.com/containerd/containerd/errdefs"
|
"github.com/containerd/containerd/errdefs"
|
||||||
|
gogotypes "github.com/gogo/protobuf/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func empty() IOCreation {
|
func empty() IOCreation {
|
||||||
@ -1368,3 +1369,45 @@ func TestContainerMetrics(t *testing.T) {
|
|||||||
|
|
||||||
<-statusC
|
<-statusC
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestContainerExtensions(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
ctx, cancel := testContext()
|
||||||
|
defer cancel()
|
||||||
|
id := t.Name()
|
||||||
|
|
||||||
|
client, err := newClient(t, address)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer client.Close()
|
||||||
|
|
||||||
|
ext := gogotypes.Any{TypeUrl: "test.ext.url", Value: []byte("hello")}
|
||||||
|
container, err := client.NewContainer(ctx, id, WithNewSpec(), WithContainerExtension("hello", &ext))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer container.Delete(ctx)
|
||||||
|
|
||||||
|
checkExt := func(container Container) {
|
||||||
|
cExts := container.Extensions()
|
||||||
|
if len(cExts) != 1 {
|
||||||
|
t.Fatal("expected 1 container extension")
|
||||||
|
}
|
||||||
|
if cExts["hello"].TypeUrl != ext.TypeUrl {
|
||||||
|
t.Fatalf("got unexpected type url for extension: %s", cExts["hello"].TypeUrl)
|
||||||
|
}
|
||||||
|
if !bytes.Equal(cExts["hello"].Value, ext.Value) {
|
||||||
|
t.Fatalf("expected extension value %q, got: %q", ext.Value, cExts["hello"].Value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
checkExt(container)
|
||||||
|
|
||||||
|
container, err = client.LoadContainer(ctx, container.ID())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
checkExt(container)
|
||||||
|
}
|
||||||
|
@ -57,6 +57,9 @@ type Container struct {
|
|||||||
|
|
||||||
// UpdatedAt is the time at which the container was updated.
|
// UpdatedAt is the time at which the container was updated.
|
||||||
UpdatedAt time.Time
|
UpdatedAt time.Time
|
||||||
|
|
||||||
|
// Extensions stores client-specified metadata
|
||||||
|
Extensions map[string]types.Any
|
||||||
}
|
}
|
||||||
|
|
||||||
type RuntimeInfo struct {
|
type RuntimeInfo struct {
|
||||||
|
@ -97,6 +97,7 @@ func containerToProto(container *containers.Container) containersapi.Container {
|
|||||||
Spec: container.Spec,
|
Spec: container.Spec,
|
||||||
Snapshotter: container.Snapshotter,
|
Snapshotter: container.Snapshotter,
|
||||||
SnapshotKey: container.SnapshotKey,
|
SnapshotKey: container.SnapshotKey,
|
||||||
|
Extensions: container.Extensions,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,6 +117,7 @@ func containerFromProto(containerpb *containersapi.Container) containers.Contain
|
|||||||
Spec: containerpb.Spec,
|
Spec: containerpb.Spec,
|
||||||
Snapshotter: containerpb.Snapshotter,
|
Snapshotter: containerpb.Snapshotter,
|
||||||
SnapshotKey: containerpb.SnapshotKey,
|
SnapshotKey: containerpb.SnapshotKey,
|
||||||
|
Extensions: containerpb.Extensions,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,6 +50,7 @@ var (
|
|||||||
bucketKeySnapshotKey = []byte("snapshotKey")
|
bucketKeySnapshotKey = []byte("snapshotKey")
|
||||||
bucketKeySnapshotter = []byte("snapshotter")
|
bucketKeySnapshotter = []byte("snapshotter")
|
||||||
bucketKeyTarget = []byte("target")
|
bucketKeyTarget = []byte("target")
|
||||||
|
bucketKeyExtensions = []byte("extensions")
|
||||||
)
|
)
|
||||||
|
|
||||||
func getBucket(tx *bolt.Tx, keys ...[]byte) *bolt.Bucket {
|
func getBucket(tx *bolt.Tx, keys ...[]byte) *bolt.Bucket {
|
||||||
|
@ -146,7 +146,7 @@ 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"}
|
fieldpaths = []string{"labels", "spec", "extensions"}
|
||||||
|
|
||||||
// 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
|
||||||
@ -181,11 +181,22 @@ func (s *containerStore) Update(ctx context.Context, container containers.Contai
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(path, "extensions.") {
|
||||||
|
if updated.Extensions == nil {
|
||||||
|
updated.Extensions = map[string]types.Any{}
|
||||||
|
}
|
||||||
|
key := strings.TrimPrefix(path, "extensions.")
|
||||||
|
updated.Extensions[key] = container.Extensions[key]
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
switch path {
|
switch path {
|
||||||
case "labels":
|
case "labels":
|
||||||
updated.Labels = container.Labels
|
updated.Labels = container.Labels
|
||||||
case "spec":
|
case "spec":
|
||||||
updated.Spec = container.Spec
|
updated.Spec = container.Spec
|
||||||
|
case "extensions":
|
||||||
|
updated.Extensions = container.Extensions
|
||||||
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)
|
||||||
}
|
}
|
||||||
@ -226,6 +237,12 @@ func validateContainer(container *containers.Container) error {
|
|||||||
return errors.Wrapf(err, "container.ID validation error")
|
return errors.Wrapf(err, "container.ID validation error")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for k := range container.Extensions {
|
||||||
|
if k == "" {
|
||||||
|
return errors.Wrapf(errdefs.ErrInvalidArgument, "container.Extension keys must not be zero-length")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// labels and image have no validation
|
// labels and image have no validation
|
||||||
if container.Runtime.Name == "" {
|
if container.Runtime.Name == "" {
|
||||||
return errors.Wrapf(errdefs.ErrInvalidArgument, "container.Runtime.Name must be set")
|
return errors.Wrapf(errdefs.ErrInvalidArgument, "container.Runtime.Name must be set")
|
||||||
@ -288,6 +305,27 @@ func readContainer(container *containers.Container, bkt *bolt.Bucket) error {
|
|||||||
container.SnapshotKey = string(v)
|
container.SnapshotKey = string(v)
|
||||||
case string(bucketKeySnapshotter):
|
case string(bucketKeySnapshotter):
|
||||||
container.Snapshotter = string(v)
|
container.Snapshotter = string(v)
|
||||||
|
case string(bucketKeyExtensions):
|
||||||
|
ebkt := bkt.Bucket(bucketKeyExtensions)
|
||||||
|
if ebkt == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
extensions := make(map[string]types.Any)
|
||||||
|
if err := ebkt.ForEach(func(k, v []byte) error {
|
||||||
|
var a types.Any
|
||||||
|
if err := proto.Unmarshal(v, &a); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
extensions[string(k)] = a
|
||||||
|
return nil
|
||||||
|
}); err != nil {
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
container.Extensions = extensions
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -335,6 +373,24 @@ func writeContainer(bkt *bolt.Bucket, container *containers.Container) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(container.Extensions) > 0 {
|
||||||
|
ebkt, err := bkt.CreateBucketIfNotExists(bucketKeyExtensions)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for name, ext := range container.Extensions {
|
||||||
|
p, err := proto.Marshal(&ext)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := ebkt.Put([]byte(name), p); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if container.Runtime.Options != nil {
|
if container.Runtime.Options != nil {
|
||||||
data, err := proto.Marshal(container.Runtime.Options)
|
data, err := proto.Marshal(container.Runtime.Options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -16,6 +16,7 @@ import (
|
|||||||
"github.com/containerd/containerd/filters"
|
"github.com/containerd/containerd/filters"
|
||||||
"github.com/containerd/containerd/namespaces"
|
"github.com/containerd/containerd/namespaces"
|
||||||
"github.com/containerd/containerd/typeurl"
|
"github.com/containerd/containerd/typeurl"
|
||||||
|
"github.com/gogo/protobuf/types"
|
||||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
@ -420,6 +421,169 @@ func TestContainersCreateUpdateDelete(t *testing.T) {
|
|||||||
},
|
},
|
||||||
createerr: errdefs.ErrInvalidArgument,
|
createerr: errdefs.ErrInvalidArgument,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "UpdateExtensionsFull",
|
||||||
|
original: containers.Container{
|
||||||
|
Spec: encoded,
|
||||||
|
Runtime: containers.RuntimeInfo{
|
||||||
|
Name: "testruntime",
|
||||||
|
},
|
||||||
|
Extensions: map[string]types.Any{
|
||||||
|
"hello": {
|
||||||
|
TypeUrl: "test.update.extensions",
|
||||||
|
Value: []byte("hello"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
input: containers.Container{
|
||||||
|
Spec: encoded,
|
||||||
|
Runtime: containers.RuntimeInfo{
|
||||||
|
Name: "testruntime",
|
||||||
|
},
|
||||||
|
Extensions: map[string]types.Any{
|
||||||
|
"hello": {
|
||||||
|
TypeUrl: "test.update.extensions",
|
||||||
|
Value: []byte("world"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: containers.Container{
|
||||||
|
Spec: encoded,
|
||||||
|
Runtime: containers.RuntimeInfo{
|
||||||
|
Name: "testruntime",
|
||||||
|
},
|
||||||
|
Extensions: map[string]types.Any{
|
||||||
|
"hello": {
|
||||||
|
TypeUrl: "test.update.extensions",
|
||||||
|
Value: []byte("world"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "UpdateExtensionsNotInFieldpath",
|
||||||
|
original: containers.Container{
|
||||||
|
Spec: encoded,
|
||||||
|
Runtime: containers.RuntimeInfo{
|
||||||
|
Name: "testruntime",
|
||||||
|
},
|
||||||
|
Extensions: map[string]types.Any{
|
||||||
|
"hello": {
|
||||||
|
TypeUrl: "test.update.extensions",
|
||||||
|
Value: []byte("hello"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
input: containers.Container{
|
||||||
|
Spec: encoded,
|
||||||
|
Runtime: containers.RuntimeInfo{
|
||||||
|
Name: "testruntime",
|
||||||
|
},
|
||||||
|
Extensions: map[string]types.Any{
|
||||||
|
"hello": {
|
||||||
|
TypeUrl: "test.update.extensions",
|
||||||
|
Value: []byte("world"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fieldpaths: []string{"labels"},
|
||||||
|
expected: containers.Container{
|
||||||
|
Spec: encoded,
|
||||||
|
Runtime: containers.RuntimeInfo{
|
||||||
|
Name: "testruntime",
|
||||||
|
},
|
||||||
|
Extensions: map[string]types.Any{
|
||||||
|
"hello": {
|
||||||
|
TypeUrl: "test.update.extensions",
|
||||||
|
Value: []byte("hello"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "UpdateExtensionsFieldPath",
|
||||||
|
original: containers.Container{
|
||||||
|
Spec: encoded,
|
||||||
|
Runtime: containers.RuntimeInfo{
|
||||||
|
Name: "testruntime",
|
||||||
|
},
|
||||||
|
Extensions: map[string]types.Any{
|
||||||
|
"hello": {
|
||||||
|
TypeUrl: "test.update.extensions",
|
||||||
|
Value: []byte("hello"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
input: containers.Container{
|
||||||
|
Labels: map[string]string{
|
||||||
|
"foo": "one",
|
||||||
|
},
|
||||||
|
Extensions: map[string]types.Any{
|
||||||
|
"hello": {
|
||||||
|
TypeUrl: "test.update.extensions",
|
||||||
|
Value: []byte("world"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fieldpaths: []string{"extensions"},
|
||||||
|
expected: containers.Container{
|
||||||
|
Spec: encoded,
|
||||||
|
Runtime: containers.RuntimeInfo{
|
||||||
|
Name: "testruntime",
|
||||||
|
},
|
||||||
|
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) {
|
t.Run(testcase.name, func(t *testing.T) {
|
||||||
testcase.original.ID = testcase.name
|
testcase.original.ID = testcase.name
|
||||||
@ -529,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{}) {
|
func checkContainersEqual(t *testing.T, a, b *containers.Container, format string, args ...interface{}) {
|
||||||
if !reflect.DeepEqual(a, b) {
|
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...)...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ func containerToProto(container *containers.Container) api.Container {
|
|||||||
Spec: container.Spec,
|
Spec: container.Spec,
|
||||||
Snapshotter: container.Snapshotter,
|
Snapshotter: container.Snapshotter,
|
||||||
SnapshotKey: container.SnapshotKey,
|
SnapshotKey: container.SnapshotKey,
|
||||||
|
Extensions: container.Extensions,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,5 +47,6 @@ func containerFromProto(containerpb *api.Container) containers.Container {
|
|||||||
Spec: containerpb.Spec,
|
Spec: containerpb.Spec,
|
||||||
Snapshotter: containerpb.Snapshotter,
|
Snapshotter: containerpb.Snapshotter,
|
||||||
SnapshotKey: containerpb.SnapshotKey,
|
SnapshotKey: containerpb.SnapshotKey,
|
||||||
|
Extensions: containerpb.Extensions,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user