server: store creation in containers
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
parent
1f4a4742cb
commit
790c6d891a
6 changed files with 28 additions and 15 deletions
|
@ -42,7 +42,9 @@ type ContainerState struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewContainer creates a container object.
|
// NewContainer creates a container object.
|
||||||
func NewContainer(id string, name string, bundlePath string, logPath string, netns ns.NetNS, labels map[string]string, annotations map[string]string, image *pb.ImageSpec, metadata *pb.ContainerMetadata, sandbox string, terminal bool, privileged bool, dir string) (*Container, error) {
|
func NewContainer(id string, name string, bundlePath string, logPath string, netns ns.NetNS, labels map[string]string, annotations map[string]string, image *pb.ImageSpec, metadata *pb.ContainerMetadata, sandbox string, terminal bool, privileged bool, dir string, created time.Time) (*Container, error) {
|
||||||
|
state := &ContainerState{}
|
||||||
|
state.Created = created
|
||||||
c := &Container{
|
c := &Container{
|
||||||
id: id,
|
id: id,
|
||||||
name: name,
|
name: name,
|
||||||
|
@ -57,10 +59,16 @@ func NewContainer(id string, name string, bundlePath string, logPath string, net
|
||||||
annotations: annotations,
|
annotations: annotations,
|
||||||
image: image,
|
image: image,
|
||||||
dir: dir,
|
dir: dir,
|
||||||
|
state: state,
|
||||||
}
|
}
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreatedAt returns the container creation time
|
||||||
|
func (c *Container) CreatedAt() time.Time {
|
||||||
|
return c.state.Created
|
||||||
|
}
|
||||||
|
|
||||||
// Name returns the name of the container.
|
// Name returns the name of the container.
|
||||||
func (c *Container) Name() string {
|
func (c *Container) Name() string {
|
||||||
return c.name
|
return c.name
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/docker/docker/pkg/stringid"
|
"github.com/docker/docker/pkg/stringid"
|
||||||
|
@ -540,6 +541,9 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
|
||||||
specgen.AddAnnotation("crio/tty", fmt.Sprintf("%v", containerConfig.Tty))
|
specgen.AddAnnotation("crio/tty", fmt.Sprintf("%v", containerConfig.Tty))
|
||||||
specgen.AddAnnotation("crio/image", image)
|
specgen.AddAnnotation("crio/image", image)
|
||||||
|
|
||||||
|
created := time.Now()
|
||||||
|
specgen.AddAnnotation("crio/created", created.Format(time.RFC3339Nano))
|
||||||
|
|
||||||
metadataJSON, err := json.Marshal(metadata)
|
metadataJSON, err := json.Marshal(metadata)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -648,7 +652,7 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
container, err := oci.NewContainer(containerID, containerName, containerInfo.RunDir, logPath, sb.netNs(), labels, annotations, imageSpec, metadata, sb.id, containerConfig.Tty, sb.privileged, containerInfo.Dir)
|
container, err := oci.NewContainer(containerID, containerName, containerInfo.RunDir, logPath, sb.netNs(), labels, annotations, imageSpec, metadata, sb.id, containerConfig.Tty, sb.privileged, containerInfo.Dir, created)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/containernetworking/cni/pkg/ns"
|
"github.com/containernetworking/cni/pkg/ns"
|
||||||
|
@ -146,7 +145,6 @@ type sandbox struct {
|
||||||
privileged bool
|
privileged bool
|
||||||
resolvPath string
|
resolvPath string
|
||||||
hostname string
|
hostname string
|
||||||
created time.Time
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -289,7 +289,6 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
|
||||||
privileged: privileged,
|
privileged: privileged,
|
||||||
resolvPath: resolvPath,
|
resolvPath: resolvPath,
|
||||||
hostname: hostname,
|
hostname: hostname,
|
||||||
created: created,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
|
@ -408,7 +407,7 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
|
||||||
return nil, fmt.Errorf("failed to write runtime configuration for pod sandbox %s(%s): %v", sb.name, id, err)
|
return nil, fmt.Errorf("failed to write runtime configuration for pod sandbox %s(%s): %v", sb.name, id, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
container, err := oci.NewContainer(id, containerName, podContainer.RunDir, logPath, sb.netNs(), labels, annotations, nil, nil, id, false, sb.privileged, podContainer.Dir)
|
container, err := oci.NewContainer(id, containerName, podContainer.RunDir, logPath, sb.netNs(), labels, annotations, nil, nil, id, false, sb.privileged, podContainer.Dir, created)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ func (s *Server) PodSandboxStatus(ctx context.Context, req *pb.PodSandboxStatusR
|
||||||
resp := &pb.PodSandboxStatusResponse{
|
resp := &pb.PodSandboxStatusResponse{
|
||||||
Status: &pb.PodSandboxStatus{
|
Status: &pb.PodSandboxStatus{
|
||||||
Id: sandboxID,
|
Id: sandboxID,
|
||||||
CreatedAt: sb.created.UnixNano(),
|
CreatedAt: podInfraContainer.CreatedAt().UnixNano(),
|
||||||
Linux: &pb.LinuxPodSandboxStatus{
|
Linux: &pb.LinuxPodSandboxStatus{
|
||||||
Namespaces: &pb.Namespace{
|
Namespaces: &pb.Namespace{
|
||||||
Network: netNsPath,
|
Network: netNsPath,
|
||||||
|
|
|
@ -139,7 +139,12 @@ func (s *Server) loadContainer(id string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ctr, err := oci.NewContainer(id, name, containerPath, m.Annotations["crio/log_path"], sb.netNs(), labels, annotations, img, &metadata, sb.id, tty, sb.privileged, containerDir)
|
created, err := time.Parse(time.RFC3339Nano, m.Annotations["crio/created"])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
ctr, err := oci.NewContainer(id, name, containerPath, m.Annotations["crio/log_path"], sb.netNs(), labels, annotations, img, &metadata, sb.id, tty, sb.privileged, containerDir, created)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -206,11 +211,6 @@ func (s *Server) loadSandbox(id string) error {
|
||||||
|
|
||||||
privileged := m.Annotations["crio/privileged_runtime"] == "true"
|
privileged := m.Annotations["crio/privileged_runtime"] == "true"
|
||||||
|
|
||||||
created, err := time.Parse(time.RFC3339Nano, m.Annotations["crio/created"])
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
sb := &sandbox{
|
sb := &sandbox{
|
||||||
id: id,
|
id: id,
|
||||||
name: name,
|
name: name,
|
||||||
|
@ -225,7 +225,6 @@ func (s *Server) loadSandbox(id string) error {
|
||||||
shmPath: m.Annotations["crio/shm_path"],
|
shmPath: m.Annotations["crio/shm_path"],
|
||||||
privileged: privileged,
|
privileged: privileged,
|
||||||
resolvPath: m.Annotations["crio/resolv_path"],
|
resolvPath: m.Annotations["crio/resolv_path"],
|
||||||
created: created,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We add a netNS only if we can load a permanent one.
|
// We add a netNS only if we can load a permanent one.
|
||||||
|
@ -271,7 +270,12 @@ func (s *Server) loadSandbox(id string) error {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
scontainer, err := oci.NewContainer(m.Annotations["crio/container_id"], cname, sandboxPath, m.Annotations["crio/log_path"], sb.netNs(), labels, annotations, nil, nil, id, false, privileged, sandboxDir)
|
created, err := time.Parse(time.RFC3339Nano, m.Annotations["crio/created"])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
scontainer, err := oci.NewContainer(m.Annotations["crio/container_id"], cname, sandboxPath, m.Annotations["crio/log_path"], sb.netNs(), labels, annotations, nil, nil, id, false, privileged, sandboxDir, created)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue