Merge pull request #824 from runcom/enhance-inspect
server: inspect: add log path and mount point for cadvisor
This commit is contained in:
commit
f08a5f7162
8 changed files with 60 additions and 13 deletions
|
@ -361,6 +361,7 @@ func (c *ContainerServer) LoadSandbox(id string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
scontainer.SetMountPoint(m.Annotations[annotations.MountPoint])
|
||||||
|
|
||||||
if m.Annotations[annotations.Volumes] != "" {
|
if m.Annotations[annotations.Volumes] != "" {
|
||||||
containerVolumes := []oci.ContainerVolume{}
|
containerVolumes := []oci.ContainerVolume{}
|
||||||
|
@ -483,6 +484,7 @@ func (c *ContainerServer) LoadContainer(id string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
ctr.SetMountPoint(m.Annotations[annotations.MountPoint])
|
||||||
|
|
||||||
c.ContainerStateFromDisk(ctr)
|
c.ContainerStateFromDisk(ctr)
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,7 @@ type Container struct {
|
||||||
imageName string
|
imageName string
|
||||||
imageRef string
|
imageRef string
|
||||||
volumes []ContainerVolume
|
volumes []ContainerVolume
|
||||||
|
mountPoint string
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContainerVolume is a bind mount for the container.
|
// ContainerVolume is a bind mount for the container.
|
||||||
|
@ -222,3 +223,13 @@ func (c *Container) Volumes() []ContainerVolume {
|
||||||
return c.volumes
|
return c.volumes
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetMountPoint sets the container mount point
|
||||||
|
func (c *Container) SetMountPoint(mp string) {
|
||||||
|
c.mountPoint = mp
|
||||||
|
}
|
||||||
|
|
||||||
|
// MountPoint returns the container mount point
|
||||||
|
func (c *Container) MountPoint() string {
|
||||||
|
return c.mountPoint
|
||||||
|
}
|
||||||
|
|
|
@ -58,6 +58,9 @@ const (
|
||||||
// ShmPath is the shared memory path annotation
|
// ShmPath is the shared memory path annotation
|
||||||
ShmPath = "io.kubernetes.cri-o.ShmPath"
|
ShmPath = "io.kubernetes.cri-o.ShmPath"
|
||||||
|
|
||||||
|
// MountPoint is the mount point of the container rootfs
|
||||||
|
MountPoint = "io.kubernetes.cri-o.MountPoint"
|
||||||
|
|
||||||
// TrustedSandbox is the annotation for trusted sandboxes
|
// TrustedSandbox is the annotation for trusted sandboxes
|
||||||
TrustedSandbox = "io.kubernetes.cri-o.TrustedSandbox"
|
TrustedSandbox = "io.kubernetes.cri-o.TrustedSandbox"
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ type imageService struct {
|
||||||
// implementation.
|
// implementation.
|
||||||
type ImageServer interface {
|
type ImageServer interface {
|
||||||
// ListImages returns list of all images which match the filter.
|
// ListImages returns list of all images which match the filter.
|
||||||
ListImages(filter string) ([]ImageResult, error)
|
ListImages(systemContext *types.SystemContext, filter string) ([]ImageResult, error)
|
||||||
// ImageStatus returns status of an image which matches the filter.
|
// ImageStatus returns status of an image which matches the filter.
|
||||||
ImageStatus(systemContext *types.SystemContext, filter string) (*ImageResult, error)
|
ImageStatus(systemContext *types.SystemContext, filter string) (*ImageResult, error)
|
||||||
// PullImage imports an image from the specified location.
|
// PullImage imports an image from the specified location.
|
||||||
|
@ -59,14 +59,12 @@ type ImageServer interface {
|
||||||
ResolveNames(imageName string) ([]string, error)
|
ResolveNames(imageName string) ([]string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (svc *imageService) ListImages(filter string) ([]ImageResult, error) {
|
func (svc *imageService) getRef(name string) (types.ImageReference, error) {
|
||||||
results := []ImageResult{}
|
ref, err := alltransports.ParseImageName(name)
|
||||||
if filter != "" {
|
|
||||||
ref, err := alltransports.ParseImageName(filter)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ref2, err2 := istorage.Transport.ParseStoreReference(svc.store, "@"+filter)
|
ref2, err2 := istorage.Transport.ParseStoreReference(svc.store, "@"+name)
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
ref3, err3 := istorage.Transport.ParseStoreReference(svc.store, filter)
|
ref3, err3 := istorage.Transport.ParseStoreReference(svc.store, name)
|
||||||
if err3 != nil {
|
if err3 != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -74,10 +72,25 @@ func (svc *imageService) ListImages(filter string) ([]ImageResult, error) {
|
||||||
}
|
}
|
||||||
ref = ref2
|
ref = ref2
|
||||||
}
|
}
|
||||||
|
return ref, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (svc *imageService) ListImages(systemContext *types.SystemContext, filter string) ([]ImageResult, error) {
|
||||||
|
results := []ImageResult{}
|
||||||
|
if filter != "" {
|
||||||
|
ref, err := svc.getRef(filter)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
if image, err := istorage.Transport.GetStoreImage(svc.store, ref); err == nil {
|
if image, err := istorage.Transport.GetStoreImage(svc.store, ref); err == nil {
|
||||||
|
img, err := ref.NewImage(systemContext)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
results = append(results, ImageResult{
|
results = append(results, ImageResult{
|
||||||
ID: image.ID,
|
ID: image.ID,
|
||||||
Names: image.Names,
|
Names: image.Names,
|
||||||
|
Size: imageSize(img),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -86,9 +99,18 @@ func (svc *imageService) ListImages(filter string) ([]ImageResult, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, image := range images {
|
for _, image := range images {
|
||||||
|
ref, err := svc.getRef(image.Names[0])
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
img, err := ref.NewImage(systemContext)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
results = append(results, ImageResult{
|
results = append(results, ImageResult{
|
||||||
ID: image.ID,
|
ID: image.ID,
|
||||||
Names: image.Names,
|
Names: image.Names,
|
||||||
|
Size: imageSize(img),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -698,6 +698,7 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to mount container %s(%s): %v", containerName, containerID, err)
|
return nil, fmt.Errorf("failed to mount container %s(%s): %v", containerName, containerID, err)
|
||||||
}
|
}
|
||||||
|
specgen.AddAnnotation(annotations.MountPoint, mountPoint)
|
||||||
|
|
||||||
containerImageConfig := containerInfo.Config
|
containerImageConfig := containerInfo.Config
|
||||||
if containerImageConfig == nil {
|
if containerImageConfig == nil {
|
||||||
|
@ -789,6 +790,7 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
container.SetMountPoint(mountPoint)
|
||||||
|
|
||||||
for _, cv := range containerVolumes {
|
for _, cv := range containerVolumes {
|
||||||
container.AddVolume(cv)
|
container.AddVolume(cv)
|
||||||
|
|
|
@ -17,7 +17,7 @@ func (s *Server) ListImages(ctx context.Context, req *pb.ListImagesRequest) (*pb
|
||||||
filter = filterImage.Image
|
filter = filterImage.Image
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
results, err := s.StorageImageServer().ListImages(filter)
|
results, err := s.StorageImageServer().ListImages(s.ImageContext(), filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/go-zoo/bone"
|
"github.com/go-zoo/bone"
|
||||||
)
|
)
|
||||||
|
@ -15,6 +16,8 @@ type ContainerInfo struct {
|
||||||
CreatedTime int64 `json:"created_time"`
|
CreatedTime int64 `json:"created_time"`
|
||||||
Labels map[string]string `json:"labels"`
|
Labels map[string]string `json:"labels"`
|
||||||
Annotations map[string]string `json:"annotations"`
|
Annotations map[string]string `json:"annotations"`
|
||||||
|
LogPath string `json:"log_path"`
|
||||||
|
Root string `json:"root"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CrioInfo stores information about the crio daemon
|
// CrioInfo stores information about the crio daemon
|
||||||
|
@ -61,6 +64,8 @@ func (s *Server) StartInfoEndpoints() error {
|
||||||
CreatedTime: ctrState.Created.UnixNano(),
|
CreatedTime: ctrState.Created.UnixNano(),
|
||||||
Labels: ctr.Labels(),
|
Labels: ctr.Labels(),
|
||||||
Annotations: ctr.Annotations(),
|
Annotations: ctr.Annotations(),
|
||||||
|
Root: ctr.MountPoint(),
|
||||||
|
LogPath: filepath.Dir(ctr.LogPath()),
|
||||||
}
|
}
|
||||||
js, err := json.Marshal(ci)
|
js, err := json.Marshal(ci)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -442,6 +442,7 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to mount container %s in pod sandbox %s(%s): %v", containerName, sb.Name(), id, err)
|
return nil, fmt.Errorf("failed to mount container %s in pod sandbox %s(%s): %v", containerName, sb.Name(), id, err)
|
||||||
}
|
}
|
||||||
|
g.AddAnnotation(annotations.MountPoint, mountPoint)
|
||||||
g.SetRootPath(mountPoint)
|
g.SetRootPath(mountPoint)
|
||||||
err = g.SaveToFile(filepath.Join(podContainer.Dir, "config.json"), saveOptions)
|
err = g.SaveToFile(filepath.Join(podContainer.Dir, "config.json"), saveOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -455,6 +456,7 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
container.SetMountPoint(mountPoint)
|
||||||
|
|
||||||
sb.SetInfraContainer(container)
|
sb.SetInfraContainer(container)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue