store annotations and image for a container

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
Antonio Murdaca 2016-12-12 11:12:03 +01:00
parent 5142b8a4d7
commit 430297dd81
No known key found for this signature in database
GPG key ID: B2BEAD150DE936B9
6 changed files with 66 additions and 33 deletions

View file

@ -505,6 +505,9 @@ func ListContainers(client pb.RuntimeServiceClient, opts listOptions) error {
if c.State != nil { if c.State != nil {
fmt.Printf("Status: %s\n", *c.State) fmt.Printf("Status: %s\n", *c.State)
} }
if c.Image != nil {
fmt.Printf("Image: %s\n", c.Image.GetImage())
}
if c.CreatedAt != nil { if c.CreatedAt != nil {
ctm := time.Unix(0, *c.CreatedAt) ctm := time.Unix(0, *c.CreatedAt)
fmt.Printf("Created: %v\n", ctm) fmt.Printf("Created: %v\n", ctm)

View file

@ -341,6 +341,8 @@ type Container struct {
bundlePath string bundlePath string
logPath string logPath string
labels fields.Set labels fields.Set
annotations fields.Set
image *pb.ImageSpec
sandbox string sandbox string
terminal bool terminal bool
state *ContainerState state *ContainerState
@ -358,7 +360,7 @@ type ContainerState struct {
} }
// NewContainer creates a container object. // NewContainer creates a container object.
func NewContainer(id string, name string, bundlePath string, logPath string, labels map[string]string, metadata *pb.ContainerMetadata, sandbox string, terminal bool) (*Container, error) { func NewContainer(id string, name string, bundlePath string, logPath string, labels map[string]string, annotations map[string]string, image *pb.ImageSpec, metadata *pb.ContainerMetadata, sandbox string, terminal bool) (*Container, error) {
c := &Container{ c := &Container{
id: id, id: id,
name: name, name: name,
@ -368,6 +370,8 @@ func NewContainer(id string, name string, bundlePath string, logPath string, lab
sandbox: sandbox, sandbox: sandbox,
terminal: terminal, terminal: terminal,
metadata: metadata, metadata: metadata,
annotations: annotations,
image: image,
} }
return c, nil return c, nil
} }
@ -397,6 +401,16 @@ func (c *Container) Labels() map[string]string {
return c.labels return c.labels
} }
// Annotations returns the annotations of the container.
func (c *Container) Annotations() map[string]string {
return c.annotations
}
// Image returns the image of the container.
func (c *Container) Image() *pb.ImageSpec {
return c.image
}
// Sandbox returns the sandbox name of the container. // Sandbox returns the sandbox name of the container.
func (c *Container) Sandbox() string { func (c *Container) Sandbox() string {
return c.sandbox return c.sandbox

View file

@ -283,6 +283,16 @@ func (s *Server) createSandboxContainer(containerID string, containerName string
} }
} }
imageSpec := containerConfig.GetImage()
if imageSpec == nil {
return nil, fmt.Errorf("CreateContainerRequest.ContainerConfig.Image is nil")
}
image := imageSpec.GetImage()
if image == "" {
return nil, fmt.Errorf("CreateContainerRequest.ContainerConfig.Image.Image is empty")
}
// bind mount the pod shm // bind mount the pod shm
specgen.AddBindMount(sb.shmPath, "/dev/shm", []string{"rw"}) specgen.AddBindMount(sb.shmPath, "/dev/shm", []string{"rw"})
@ -292,6 +302,7 @@ func (s *Server) createSandboxContainer(containerID string, containerName string
specgen.AddAnnotation("ocid/container_type", containerTypeContainer) specgen.AddAnnotation("ocid/container_type", containerTypeContainer)
specgen.AddAnnotation("ocid/log_path", logPath) specgen.AddAnnotation("ocid/log_path", logPath)
specgen.AddAnnotation("ocid/tty", fmt.Sprintf("%v", containerConfig.GetTty())) specgen.AddAnnotation("ocid/tty", fmt.Sprintf("%v", containerConfig.GetTty()))
specgen.AddAnnotation("ocid/image", image)
metadataJSON, err := json.Marshal(metadata) metadataJSON, err := json.Marshal(metadata)
if err != nil { if err != nil {
@ -313,23 +324,13 @@ func (s *Server) createSandboxContainer(containerID string, containerName string
return nil, err return nil, err
} }
imageSpec := containerConfig.GetImage()
if imageSpec == nil {
return nil, fmt.Errorf("CreateContainerRequest.ContainerConfig.Image is nil")
}
image := imageSpec.GetImage()
if image == "" {
return nil, fmt.Errorf("CreateContainerRequest.ContainerConfig.Image.Image is empty")
}
// TODO: copy the rootfs into the bundle. // TODO: copy the rootfs into the bundle.
// Currently, utils.CreateFakeRootfs is used to populate the rootfs. // Currently, utils.CreateFakeRootfs is used to populate the rootfs.
if err = utils.CreateFakeRootfs(containerDir, image); err != nil { if err = utils.CreateFakeRootfs(containerDir, image); err != nil {
return nil, err return nil, err
} }
container, err := oci.NewContainer(containerID, containerName, containerDir, logPath, labels, metadata, sb.id, containerConfig.GetTty()) container, err := oci.NewContainer(containerID, containerName, containerDir, logPath, labels, annotations, imageSpec, metadata, sb.id, containerConfig.GetTty())
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -82,6 +82,8 @@ func (s *Server) ListContainers(ctx context.Context, req *pb.ListContainersReque
CreatedAt: int64Ptr(created), CreatedAt: int64Ptr(created),
Labels: ctr.Labels(), Labels: ctr.Labels(),
Metadata: ctr.Metadata(), Metadata: ctr.Metadata(),
Annotations: ctr.Annotations(),
Image: ctr.Image(),
} }
switch cState.Status { switch cState.Status {

View file

@ -267,7 +267,7 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
} }
} }
container, err := oci.NewContainer(containerID, containerName, podSandboxDir, podSandboxDir, labels, nil, id, false) container, err := oci.NewContainer(containerID, containerName, podSandboxDir, podSandboxDir, labels, annotations, nil, nil, id, false)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -79,7 +79,20 @@ func (s *Server) loadContainer(id string) error {
} }
containerPath := filepath.Join(s.runtime.ContainerDir(), id) containerPath := filepath.Join(s.runtime.ContainerDir(), id)
ctr, err := oci.NewContainer(id, name, containerPath, m.Annotations["ocid/log_path"], labels, &metadata, sb.id, tty) var img *pb.ImageSpec
image, ok := m.Annotations["ocid/image"]
if ok {
img = &pb.ImageSpec{
Image: &image,
}
}
annotations := make(map[string]string)
if err = json.Unmarshal([]byte(m.Annotations["ocid/annotations"]), &annotations); err != nil {
return err
}
ctr, err := oci.NewContainer(id, name, containerPath, m.Annotations["ocid/log_path"], labels, annotations, img, &metadata, sb.id, tty)
if err != nil { if err != nil {
return err return err
} }
@ -150,7 +163,7 @@ func (s *Server) loadSandbox(id string) error {
if err != nil { if err != nil {
return err return err
} }
scontainer, err := oci.NewContainer(m.Annotations["ocid/container_id"], cname, sandboxPath, sandboxPath, labels, nil, id, false) scontainer, err := oci.NewContainer(m.Annotations["ocid/container_id"], cname, sandboxPath, sandboxPath, labels, annotations, nil, nil, id, false)
if err != nil { if err != nil {
return err return err
} }