Return container mounts in status from stored list
Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
This commit is contained in:
parent
fa317b41fd
commit
3f1b42ee9e
1 changed files with 7 additions and 50 deletions
|
@ -1,10 +1,7 @@
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"github.com/kubernetes-incubator/cri-o/oci"
|
"github.com/kubernetes-incubator/cri-o/oci"
|
||||||
rspec "github.com/opencontainers/runtime-spec/specs-go"
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
pb "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
|
pb "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
|
||||||
|
@ -36,11 +33,14 @@ func (s *Server) ContainerStatus(ctx context.Context, req *pb.ContainerStatusReq
|
||||||
}
|
}
|
||||||
resp.Status.Image = &pb.ImageSpec{Image: c.ImageName()}
|
resp.Status.Image = &pb.ImageSpec{Image: c.ImageName()}
|
||||||
|
|
||||||
mounts, err := s.getMounts(containerID)
|
mounts := []*pb.Mount{}
|
||||||
if err != nil {
|
for _, cv := range c.Volumes() {
|
||||||
return nil, err
|
mounts = append(mounts, &pb.Mount{
|
||||||
|
ContainerPath: cv.ContainerPath,
|
||||||
|
HostPath: cv.HostPath,
|
||||||
|
Readonly: cv.Readonly,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
resp.Status.Mounts = mounts
|
resp.Status.Mounts = mounts
|
||||||
|
|
||||||
cState := s.Runtime().ContainerStatus(c)
|
cState := s.Runtime().ContainerStatus(c)
|
||||||
|
@ -82,46 +82,3 @@ func (s *Server) ContainerStatus(ctx context.Context, req *pb.ContainerStatusReq
|
||||||
logrus.Debugf("ContainerStatusResponse: %+v", resp)
|
logrus.Debugf("ContainerStatusResponse: %+v", resp)
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) getMounts(id string) ([]*pb.Mount, error) {
|
|
||||||
config, err := s.Store().FromContainerDirectory(id, "config.json")
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
var m rspec.Spec
|
|
||||||
if err = json.Unmarshal(config, &m); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
isRO := func(m rspec.Mount) bool {
|
|
||||||
var ro bool
|
|
||||||
for _, o := range m.Options {
|
|
||||||
if o == "ro" {
|
|
||||||
ro = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ro
|
|
||||||
}
|
|
||||||
isBind := func(m rspec.Mount) bool {
|
|
||||||
var bind bool
|
|
||||||
for _, o := range m.Options {
|
|
||||||
if o == "bind" || o == "rbind" {
|
|
||||||
bind = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return bind
|
|
||||||
}
|
|
||||||
mounts := []*pb.Mount{}
|
|
||||||
for _, b := range m.Mounts {
|
|
||||||
if !isBind(b) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
mounts = append(mounts, &pb.Mount{
|
|
||||||
ContainerPath: b.Destination,
|
|
||||||
HostPath: b.Source,
|
|
||||||
Readonly: isRO(b),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return mounts, nil
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue