Timestamp added to container object.
Fix for #912 Signed-off-by: Kunal Kushwaha <kushwaha_kunal_v7@lab.ntt.co.jp>
This commit is contained in:
@@ -18,6 +18,8 @@ var (
|
||||
bucketKeyRuntime = []byte("runtime")
|
||||
bucketKeySpec = []byte("spec")
|
||||
bucketKeyRootFS = []byte("rootfs")
|
||||
bucketKeyCreatedAt = []byte("createdat")
|
||||
bucketKeyUpdatedAt = []byte("updatedat")
|
||||
)
|
||||
|
||||
// InitDB will initialize the database for use. The database must be opened for
|
||||
|
||||
@@ -2,6 +2,7 @@ package metadata
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/boltdb/bolt"
|
||||
"github.com/containerd/containerd/containers"
|
||||
@@ -74,6 +75,8 @@ func (s *containerStore) Create(ctx context.Context, container containers.Contai
|
||||
return containers.Container{}, err
|
||||
}
|
||||
|
||||
container.CreatedAt = time.Now()
|
||||
container.UpdatedAt = container.CreatedAt
|
||||
if err := writeContainer(&container, cbkt); err != nil {
|
||||
return containers.Container{}, errors.Wrap(err, "failed to write container")
|
||||
}
|
||||
@@ -92,6 +95,7 @@ func (s *containerStore) Update(ctx context.Context, container containers.Contai
|
||||
return containers.Container{}, errors.Wrap(ErrNotFound, "no content for id")
|
||||
}
|
||||
|
||||
container.UpdatedAt = time.Now()
|
||||
if err := writeContainer(&container, cbkt); err != nil {
|
||||
return containers.Container{}, errors.Wrap(err, "failed to write container")
|
||||
}
|
||||
@@ -123,6 +127,14 @@ func readContainer(container *containers.Container, bkt *bolt.Bucket) error {
|
||||
container.Spec = v
|
||||
case string(bucketKeyRootFS):
|
||||
container.RootFS = string(v)
|
||||
case string(bucketKeyCreatedAt):
|
||||
if err := container.CreatedAt.UnmarshalBinary(v); err != nil {
|
||||
return err
|
||||
}
|
||||
case string(bucketKeyUpdatedAt):
|
||||
if err := container.UpdatedAt.UnmarshalBinary(v); err != nil {
|
||||
return err
|
||||
}
|
||||
case string(bucketKeyLabels):
|
||||
lbkt := bkt.Bucket(bucketKeyLabels)
|
||||
if lbkt == nil {
|
||||
@@ -142,11 +154,21 @@ func readContainer(container *containers.Container, bkt *bolt.Bucket) error {
|
||||
}
|
||||
|
||||
func writeContainer(container *containers.Container, bkt *bolt.Bucket) error {
|
||||
createdAt, err := container.CreatedAt.MarshalBinary()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
updatedAt, err := container.UpdatedAt.MarshalBinary()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, v := range [][2][]byte{
|
||||
{bucketKeyImage, []byte(container.Image)},
|
||||
{bucketKeyRuntime, []byte(container.Runtime)},
|
||||
{bucketKeySpec, container.Spec},
|
||||
{bucketKeyRootFS, []byte(container.RootFS)},
|
||||
{bucketKeyCreatedAt, createdAt},
|
||||
{bucketKeyUpdatedAt, updatedAt},
|
||||
} {
|
||||
if err := bkt.Put(v[0], v[1]); err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user