mirror of
https://github.com/aljazceru/kata-containers.git
synced 2026-02-21 22:44:27 +01:00
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:
@@ -72,6 +72,7 @@ type VCSandbox interface {
|
||||
ListRoutes() ([]*pbTypes.Route, error)
|
||||
|
||||
GetOOMEvent() (string, error)
|
||||
GetHypervisorPid() (int, error)
|
||||
|
||||
UpdateRuntimeMetrics() error
|
||||
GetAgentMetrics() (string, error)
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user