store annotations and image for a container
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
parent
5142b8a4d7
commit
430297dd81
6 changed files with 66 additions and 33 deletions
|
@ -505,6 +505,9 @@ func ListContainers(client pb.RuntimeServiceClient, opts listOptions) error {
|
|||
if c.State != nil {
|
||||
fmt.Printf("Status: %s\n", *c.State)
|
||||
}
|
||||
if c.Image != nil {
|
||||
fmt.Printf("Image: %s\n", c.Image.GetImage())
|
||||
}
|
||||
if c.CreatedAt != nil {
|
||||
ctm := time.Unix(0, *c.CreatedAt)
|
||||
fmt.Printf("Created: %v\n", ctm)
|
||||
|
|
52
oci/oci.go
52
oci/oci.go
|
@ -336,16 +336,18 @@ func (r *Runtime) ContainerStatus(c *Container) *ContainerState {
|
|||
|
||||
// Container respresents a runtime container.
|
||||
type Container struct {
|
||||
id string
|
||||
name string
|
||||
bundlePath string
|
||||
logPath string
|
||||
labels fields.Set
|
||||
sandbox string
|
||||
terminal bool
|
||||
state *ContainerState
|
||||
metadata *pb.ContainerMetadata
|
||||
stateLock sync.Mutex
|
||||
id string
|
||||
name string
|
||||
bundlePath string
|
||||
logPath string
|
||||
labels fields.Set
|
||||
annotations fields.Set
|
||||
image *pb.ImageSpec
|
||||
sandbox string
|
||||
terminal bool
|
||||
state *ContainerState
|
||||
metadata *pb.ContainerMetadata
|
||||
stateLock sync.Mutex
|
||||
}
|
||||
|
||||
// ContainerState represents the status of a container.
|
||||
|
@ -358,16 +360,18 @@ type ContainerState struct {
|
|||
}
|
||||
|
||||
// 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{
|
||||
id: id,
|
||||
name: name,
|
||||
bundlePath: bundlePath,
|
||||
logPath: logPath,
|
||||
labels: labels,
|
||||
sandbox: sandbox,
|
||||
terminal: terminal,
|
||||
metadata: metadata,
|
||||
id: id,
|
||||
name: name,
|
||||
bundlePath: bundlePath,
|
||||
logPath: logPath,
|
||||
labels: labels,
|
||||
sandbox: sandbox,
|
||||
terminal: terminal,
|
||||
metadata: metadata,
|
||||
annotations: annotations,
|
||||
image: image,
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
|
@ -397,6 +401,16 @@ func (c *Container) Labels() map[string]string {
|
|||
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.
|
||||
func (c *Container) Sandbox() string {
|
||||
return c.sandbox
|
||||
|
|
|
@ -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
|
||||
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/log_path", logPath)
|
||||
specgen.AddAnnotation("ocid/tty", fmt.Sprintf("%v", containerConfig.GetTty()))
|
||||
specgen.AddAnnotation("ocid/image", image)
|
||||
|
||||
metadataJSON, err := json.Marshal(metadata)
|
||||
if err != nil {
|
||||
|
@ -313,23 +324,13 @@ func (s *Server) createSandboxContainer(containerID string, containerName string
|
|||
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.
|
||||
// Currently, utils.CreateFakeRootfs is used to populate the rootfs.
|
||||
if err = utils.CreateFakeRootfs(containerDir, image); err != nil {
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -82,6 +82,8 @@ func (s *Server) ListContainers(ctx context.Context, req *pb.ListContainersReque
|
|||
CreatedAt: int64Ptr(created),
|
||||
Labels: ctr.Labels(),
|
||||
Metadata: ctr.Metadata(),
|
||||
Annotations: ctr.Annotations(),
|
||||
Image: ctr.Image(),
|
||||
}
|
||||
|
||||
switch cState.Status {
|
||||
|
|
|
@ -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 {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -79,7 +79,20 @@ func (s *Server) loadContainer(id string) error {
|
|||
}
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
|
@ -150,7 +163,7 @@ func (s *Server) loadSandbox(id string) error {
|
|||
if err != nil {
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue