Skip to content

Commit f08a5f7

Browse files
author
Mrunal Patel
authored
Merge pull request cri-o#824 from runcom/enhance-inspect
server: inspect: add log path and mount point for cadvisor
2 parents 378b9c0 + b16d73a commit f08a5f7

File tree

8 files changed

+60
-13
lines changed

8 files changed

+60
-13
lines changed

libkpod/container_server.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ func (c *ContainerServer) LoadSandbox(id string) error {
361361
if err != nil {
362362
return err
363363
}
364+
scontainer.SetMountPoint(m.Annotations[annotations.MountPoint])
364365

365366
if m.Annotations[annotations.Volumes] != "" {
366367
containerVolumes := []oci.ContainerVolume{}
@@ -483,6 +484,7 @@ func (c *ContainerServer) LoadContainer(id string) error {
483484
if err != nil {
484485
return err
485486
}
487+
ctr.SetMountPoint(m.Annotations[annotations.MountPoint])
486488

487489
c.ContainerStateFromDisk(ctr)
488490

oci/container.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type Container struct {
4646
imageName string
4747
imageRef string
4848
volumes []ContainerVolume
49+
mountPoint string
4950
}
5051

5152
// ContainerVolume is a bind mount for the container.
@@ -222,3 +223,13 @@ func (c *Container) Volumes() []ContainerVolume {
222223
return c.volumes
223224

224225
}
226+
227+
// SetMountPoint sets the container mount point
228+
func (c *Container) SetMountPoint(mp string) {
229+
c.mountPoint = mp
230+
}
231+
232+
// MountPoint returns the container mount point
233+
func (c *Container) MountPoint() string {
234+
return c.mountPoint
235+
}

pkg/annotations/annotations.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ const (
5858
// ShmPath is the shared memory path annotation
5959
ShmPath = "io.kubernetes.cri-o.ShmPath"
6060

61+
// MountPoint is the mount point of the container rootfs
62+
MountPoint = "io.kubernetes.cri-o.MountPoint"
63+
6164
// TrustedSandbox is the annotation for trusted sandboxes
6265
TrustedSandbox = "io.kubernetes.cri-o.TrustedSandbox"
6366

pkg/storage/image.go

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type imageService struct {
4141
// implementation.
4242
type ImageServer interface {
4343
// ListImages returns list of all images which match the filter.
44-
ListImages(filter string) ([]ImageResult, error)
44+
ListImages(systemContext *types.SystemContext, filter string) ([]ImageResult, error)
4545
// ImageStatus returns status of an image which matches the filter.
4646
ImageStatus(systemContext *types.SystemContext, filter string) (*ImageResult, error)
4747
// PullImage imports an image from the specified location.
@@ -59,25 +59,38 @@ type ImageServer interface {
5959
ResolveNames(imageName string) ([]string, error)
6060
}
6161

62-
func (svc *imageService) ListImages(filter string) ([]ImageResult, error) {
62+
func (svc *imageService) getRef(name string) (types.ImageReference, error) {
63+
ref, err := alltransports.ParseImageName(name)
64+
if err != nil {
65+
ref2, err2 := istorage.Transport.ParseStoreReference(svc.store, "@"+name)
66+
if err2 != nil {
67+
ref3, err3 := istorage.Transport.ParseStoreReference(svc.store, name)
68+
if err3 != nil {
69+
return nil, err
70+
}
71+
ref2 = ref3
72+
}
73+
ref = ref2
74+
}
75+
return ref, nil
76+
}
77+
78+
func (svc *imageService) ListImages(systemContext *types.SystemContext, filter string) ([]ImageResult, error) {
6379
results := []ImageResult{}
6480
if filter != "" {
65-
ref, err := alltransports.ParseImageName(filter)
81+
ref, err := svc.getRef(filter)
6682
if err != nil {
67-
ref2, err2 := istorage.Transport.ParseStoreReference(svc.store, "@"+filter)
68-
if err2 != nil {
69-
ref3, err3 := istorage.Transport.ParseStoreReference(svc.store, filter)
70-
if err3 != nil {
71-
return nil, err
72-
}
73-
ref2 = ref3
74-
}
75-
ref = ref2
83+
return nil, err
7684
}
7785
if image, err := istorage.Transport.GetStoreImage(svc.store, ref); err == nil {
86+
img, err := ref.NewImage(systemContext)
87+
if err != nil {
88+
return nil, err
89+
}
7890
results = append(results, ImageResult{
7991
ID: image.ID,
8092
Names: image.Names,
93+
Size: imageSize(img),
8194
})
8295
}
8396
} else {
@@ -86,9 +99,18 @@ func (svc *imageService) ListImages(filter string) ([]ImageResult, error) {
8699
return nil, err
87100
}
88101
for _, image := range images {
102+
ref, err := svc.getRef(image.Names[0])
103+
if err != nil {
104+
return nil, err
105+
}
106+
img, err := ref.NewImage(systemContext)
107+
if err != nil {
108+
return nil, err
109+
}
89110
results = append(results, ImageResult{
90111
ID: image.ID,
91112
Names: image.Names,
113+
Size: imageSize(img),
92114
})
93115
}
94116
}

server/container_create.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,7 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
698698
if err != nil {
699699
return nil, fmt.Errorf("failed to mount container %s(%s): %v", containerName, containerID, err)
700700
}
701+
specgen.AddAnnotation(annotations.MountPoint, mountPoint)
701702

702703
containerImageConfig := containerInfo.Config
703704
if containerImageConfig == nil {
@@ -789,6 +790,7 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
789790
if err != nil {
790791
return nil, err
791792
}
793+
container.SetMountPoint(mountPoint)
792794

793795
for _, cv := range containerVolumes {
794796
container.AddVolume(cv)

server/image_list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func (s *Server) ListImages(ctx context.Context, req *pb.ListImagesRequest) (*pb
1717
filter = filterImage.Image
1818
}
1919
}
20-
results, err := s.StorageImageServer().ListImages(filter)
20+
results, err := s.StorageImageServer().ListImages(s.ImageContext(), filter)
2121
if err != nil {
2222
return nil, err
2323
}

server/inspect.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"fmt"
66
"net/http"
7+
"path/filepath"
78

89
"github.com/go-zoo/bone"
910
)
@@ -15,6 +16,8 @@ type ContainerInfo struct {
1516
CreatedTime int64 `json:"created_time"`
1617
Labels map[string]string `json:"labels"`
1718
Annotations map[string]string `json:"annotations"`
19+
LogPath string `json:"log_path"`
20+
Root string `json:"root"`
1821
}
1922

2023
// CrioInfo stores information about the crio daemon
@@ -61,6 +64,8 @@ func (s *Server) StartInfoEndpoints() error {
6164
CreatedTime: ctrState.Created.UnixNano(),
6265
Labels: ctr.Labels(),
6366
Annotations: ctr.Annotations(),
67+
Root: ctr.MountPoint(),
68+
LogPath: filepath.Dir(ctr.LogPath()),
6469
}
6570
js, err := json.Marshal(ci)
6671
if err != nil {

server/sandbox_run.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
442442
if err != nil {
443443
return nil, fmt.Errorf("failed to mount container %s in pod sandbox %s(%s): %v", containerName, sb.Name(), id, err)
444444
}
445+
g.AddAnnotation(annotations.MountPoint, mountPoint)
445446
g.SetRootPath(mountPoint)
446447
err = g.SaveToFile(filepath.Join(podContainer.Dir, "config.json"), saveOptions)
447448
if err != nil {
@@ -455,6 +456,7 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
455456
if err != nil {
456457
return nil, err
457458
}
459+
container.SetMountPoint(mountPoint)
458460

459461
sb.SetInfraContainer(container)
460462

0 commit comments

Comments
 (0)