metadata: expand container runtime into bucket
Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
parent
6fbe4bd568
commit
ea44901921
@ -1,10 +1,7 @@
|
|||||||
package containers
|
package containers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"context"
|
"context"
|
||||||
"encoding/gob"
|
|
||||||
"errors"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -28,39 +25,6 @@ type RuntimeInfo struct {
|
|||||||
Options map[string]string
|
Options map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
type marshaledRuntimeInfo struct {
|
|
||||||
Name string
|
|
||||||
Options map[string]string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *RuntimeInfo) MarshalBinary() ([]byte, error) {
|
|
||||||
buf := bytes.NewBuffer(nil)
|
|
||||||
if err := gob.NewEncoder(buf).Encode(marshaledRuntimeInfo{
|
|
||||||
Name: r.Name,
|
|
||||||
Options: r.Options,
|
|
||||||
}); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return buf.Bytes(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *RuntimeInfo) UnmarshalBinary(data []byte) error {
|
|
||||||
buf := data
|
|
||||||
if len(buf) == 0 {
|
|
||||||
return errors.New("RuntimeInfo: no data")
|
|
||||||
}
|
|
||||||
var (
|
|
||||||
mr marshaledRuntimeInfo
|
|
||||||
reader = bytes.NewReader(buf)
|
|
||||||
)
|
|
||||||
if err := gob.NewDecoder(reader).Decode(&mr); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
r.Name = mr.Name
|
|
||||||
r.Options = mr.Options
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type Store interface {
|
type Store interface {
|
||||||
Get(ctx context.Context, id string) (Container, error)
|
Get(ctx context.Context, id string) (Container, error)
|
||||||
List(ctx context.Context, filter string) ([]Container, error)
|
List(ctx context.Context, filter string) ([]Container, error)
|
||||||
|
@ -39,6 +39,8 @@ var (
|
|||||||
bucketKeyLabels = []byte("labels")
|
bucketKeyLabels = []byte("labels")
|
||||||
bucketKeyImage = []byte("image")
|
bucketKeyImage = []byte("image")
|
||||||
bucketKeyRuntime = []byte("runtime")
|
bucketKeyRuntime = []byte("runtime")
|
||||||
|
bucketKeyName = []byte("name")
|
||||||
|
bucketKeyOptions = []byte("options")
|
||||||
bucketKeySpec = []byte("spec")
|
bucketKeySpec = []byte("spec")
|
||||||
bucketKeyRootFS = []byte("rootfs")
|
bucketKeyRootFS = []byte("rootfs")
|
||||||
bucketKeyCreatedAt = []byte("createdat")
|
bucketKeyCreatedAt = []byte("createdat")
|
||||||
|
@ -146,9 +146,26 @@ func readContainer(container *containers.Container, bkt *bolt.Bucket) error {
|
|||||||
case string(bucketKeyImage):
|
case string(bucketKeyImage):
|
||||||
container.Image = string(v)
|
container.Image = string(v)
|
||||||
case string(bucketKeyRuntime):
|
case string(bucketKeyRuntime):
|
||||||
if err := container.Runtime.UnmarshalBinary(v); err != nil {
|
rbkt := bkt.Bucket(bucketKeyRuntime)
|
||||||
return err
|
if rbkt == nil {
|
||||||
|
return nil // skip runtime. should be an error?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
n := rbkt.Get(bucketKeyName)
|
||||||
|
if n != nil {
|
||||||
|
container.Runtime.Name = string(n)
|
||||||
|
}
|
||||||
|
|
||||||
|
obkt := rbkt.Bucket(bucketKeyOptions)
|
||||||
|
if obkt == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
container.Runtime.Options = map[string]string{}
|
||||||
|
return obkt.ForEach(func(k, v []byte) error {
|
||||||
|
container.Runtime.Options[string(k)] = string(v)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
case string(bucketKeySpec):
|
case string(bucketKeySpec):
|
||||||
container.Spec = make([]byte, len(v))
|
container.Spec = make([]byte, len(v))
|
||||||
copy(container.Spec, v)
|
copy(container.Spec, v)
|
||||||
@ -189,13 +206,9 @@ func writeContainer(container *containers.Container, bkt *bolt.Bucket) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
runtime, err := container.Runtime.MarshalBinary()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
for _, v := range [][2][]byte{
|
for _, v := range [][2][]byte{
|
||||||
{bucketKeyImage, []byte(container.Image)},
|
{bucketKeyImage, []byte(container.Image)},
|
||||||
{bucketKeyRuntime, runtime},
|
|
||||||
{bucketKeySpec, container.Spec},
|
{bucketKeySpec, container.Spec},
|
||||||
{bucketKeyRootFS, []byte(container.RootFS)},
|
{bucketKeyRootFS, []byte(container.RootFS)},
|
||||||
{bucketKeyCreatedAt, createdAt},
|
{bucketKeyCreatedAt, createdAt},
|
||||||
@ -205,6 +218,33 @@ func writeContainer(container *containers.Container, bkt *bolt.Bucket) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if rbkt := bkt.Bucket(bucketKeyRuntime); rbkt != nil {
|
||||||
|
if err := bkt.DeleteBucket(bucketKeyRuntime); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rbkt, err := bkt.CreateBucket(bucketKeyRuntime)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := rbkt.Put(bucketKeyName, []byte(container.Runtime.Name)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
obkt, err := rbkt.CreateBucket(bucketKeyOptions)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for k, v := range container.Runtime.Options {
|
||||||
|
if err := obkt.Put([]byte(k), []byte(v)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Remove existing labels to keep from merging
|
// Remove existing labels to keep from merging
|
||||||
if lbkt := bkt.Bucket(bucketKeyLabels); lbkt != nil {
|
if lbkt := bkt.Bucket(bucketKeyLabels); lbkt != nil {
|
||||||
if err := bkt.DeleteBucket(bucketKeyLabels); err != nil {
|
if err := bkt.DeleteBucket(bucketKeyLabels); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user