shimv2: return the hypervisor's pid as the container pid

Since the kata's hypervisor process is in the network namespace,
which is close to container's process, and some host metrics
such as cadvisor can use this pid to access the network namespace
to get some network metrics. Thus this commit replace the shim's
pid with the hypervisor's pid.

Fixes: #1451

Signed-off-by: fupan.lfp <fupan.lfp@antfin.com>

(backport https://github.com/kata-containers/kata-containers/pull/1452)
Signed-off-by: Francesco Giudici <fgiudici@redhat.com>
This commit is contained in:
fupan.lfp
2021-02-24 13:26:05 +08:00
committed by Peng Tao
parent 4c9af982e6
commit 2dd859bfce
4 changed files with 34 additions and 14 deletions

View File

@@ -72,6 +72,7 @@ type VCSandbox interface {
ListRoutes() ([]*pbTypes.Route, error)
GetOOMEvent() (string, error)
GetHypervisorPid() (int, error)
UpdateRuntimeMetrics() error
GetAgentMetrics() (string, error)

View File

@@ -246,6 +246,16 @@ func (s *Sandbox) GetNetNs() string {
return s.networkNS.NetNsPath
}
// GetHypervisorPid returns the hypervisor's pid.
func (s *Sandbox) GetHypervisorPid() (int, error) {
pids := s.hypervisor.getPids()
if len(pids) == 0 || pids[0] == 0 {
return -1, fmt.Errorf("Invalid hypervisor PID: %+v", pids)
}
return pids[0], nil
}
// GetAllContainers returns all containers.
func (s *Sandbox) GetAllContainers() []VCContainer {
ifa := make([]VCContainer, len(s.containers))