API: remove ProcessListContainer/ListProcesses

This commit will remove ProcessListContainer API from VCSandbox
and ListProcesses from agent.proto.

Fixes: #1668

Signed-off-by: bin <bin@hyper.sh>
This commit is contained in:
bin 2021-04-09 16:03:29 +08:00
parent d75fe95685
commit 421439c633
17 changed files with 255 additions and 1012 deletions

View File

@ -65,7 +65,7 @@ $GOPATH/src/github.com/kata-containers/kata-containers/src/agent/protocols/proto
}
if [ "$(basename $(pwd))" != "agent" ]; then
die "Please go to directory of protocols before execute this shell"
die "Please go to root directory of agent before execute this shell"
fi
# Protocol buffer files required to generate golang/rust bindings.

View File

@ -32,7 +32,6 @@ service AgentService {
rpc ExecProcess(ExecProcessRequest) returns (google.protobuf.Empty);
rpc SignalProcess(SignalProcessRequest) returns (google.protobuf.Empty);
rpc WaitProcess(WaitProcessRequest) returns (WaitProcessResponse); // wait & reap like waitpid(2)
rpc ListProcesses(ListProcessesRequest) returns (ListProcessesResponse);
rpc UpdateContainer(UpdateContainerRequest) returns (google.protobuf.Empty);
rpc StatsContainer(StatsContainerRequest) returns (StatsContainerResponse);
rpc PauseContainer(PauseContainerRequest) returns (google.protobuf.Empty);
@ -126,18 +125,6 @@ message WaitProcessResponse {
int32 status = 1;
}
// ListProcessesRequest contains the options used to list running processes inside the container
message ListProcessesRequest {
string container_id = 1;
string format = 2;
repeated string args = 3;
}
// ListProcessesResponse represents the list of running processes inside the container
message ListProcessesResponse {
bytes process_list = 1;
}
message UpdateContainerRequest {
string container_id = 1;
LinuxResources resources = 2;

View File

@ -20,9 +20,8 @@ use anyhow::{anyhow, Context, Result};
use oci::{LinuxNamespace, Root, Spec};
use protobuf::{RepeatedField, SingularPtrField};
use protocols::agent::{
AgentDetails, CopyFileRequest, GuestDetailsResponse, Interfaces, ListProcessesResponse,
Metrics, OOMEvent, ReadStreamResponse, Routes, StatsContainerResponse, WaitProcessResponse,
WriteStreamResponse,
AgentDetails, CopyFileRequest, GuestDetailsResponse, Interfaces, Metrics, OOMEvent,
ReadStreamResponse, Routes, StatsContainerResponse, WaitProcessResponse, WriteStreamResponse,
};
use protocols::empty::Empty;
use protocols::health::{
@ -576,91 +575,6 @@ impl protocols::agent_ttrpc::AgentService for AgentService {
.map_err(|e| ttrpc_error(ttrpc::Code::INTERNAL, e.to_string()))
}
async fn list_processes(
&self,
_ctx: &TtrpcContext,
req: protocols::agent::ListProcessesRequest,
) -> ttrpc::Result<ListProcessesResponse> {
let cid = req.container_id.clone();
let format = req.format.clone();
let mut args = req.args.into_vec();
let mut resp = ListProcessesResponse::new();
let s = Arc::clone(&self.sandbox);
let mut sandbox = s.lock().await;
let ctr = sandbox.get_container(&cid).ok_or_else(|| {
ttrpc_error(
ttrpc::Code::INVALID_ARGUMENT,
"invalid container id".to_string(),
)
})?;
let pids = ctr.processes().unwrap();
match format.as_str() {
"table" => {}
"json" => {
resp.process_list = serde_json::to_vec(&pids).unwrap();
return Ok(resp);
}
_ => {
return Err(ttrpc_error(
ttrpc::Code::INVALID_ARGUMENT,
"invalid format!".to_string(),
));
}
}
// format "table"
if args.is_empty() {
// default argument
args = vec!["-ef".to_string()];
}
let output = tokio::process::Command::new("ps")
.args(args.as_slice())
.stdout(Stdio::piped())
.output()
.await
.expect("ps failed");
let out: String = String::from_utf8(output.stdout).unwrap();
let mut lines: Vec<String> = out.split('\n').map(|v| v.to_string()).collect();
let pid_index = lines[0]
.split_whitespace()
.position(|v| v == "PID")
.unwrap();
let mut result = String::new();
result.push_str(lines[0].as_str());
lines.remove(0);
for line in &lines {
if line.trim().is_empty() {
continue;
}
let fields: Vec<String> = line.split_whitespace().map(|v| v.to_string()).collect();
if fields.len() < pid_index + 1 {
warn!(sl!(), "corrupted output?");
continue;
}
let pid = fields[pid_index].trim().parse::<i32>().unwrap();
for p in &pids {
if pid == *p {
result.push_str(line.as_str());
}
}
}
resp.process_list = Vec::from(result);
Ok(resp)
}
async fn update_container(
&self,
_ctx: &TtrpcContext,

View File

@ -132,9 +132,6 @@ type agent interface {
// readProcessStderr will tell the agent to read a process stderr
readProcessStderr(ctx context.Context, c *Container, processID string, data []byte) (int, error)
// processListContainer will list the processes running inside the container
processListContainer(ctx context.Context, sandbox *Sandbox, c Container, options ProcessListOptions) (ProcessList, error)
// updateContainer will update the resources of a running container
updateContainer(ctx context.Context, sandbox *Sandbox, c Container, resources specs.LinuxResources) error

View File

@ -1125,18 +1125,6 @@ func (c *Container) ioStream(processID string) (io.WriteCloser, io.Reader, io.Re
return stream.stdin(), stream.stdout(), stream.stderr(), nil
}
func (c *Container) processList(ctx context.Context, options ProcessListOptions) (ProcessList, error) {
if err := c.checkSandboxRunning("ps"); err != nil {
return nil, err
}
if c.state.State != types.StateRunning {
return nil, fmt.Errorf("Container not running, impossible to list processes")
}
return c.sandbox.agent.processListContainer(ctx, c.sandbox, *c, options)
}
func (c *Container) stats(ctx context.Context) (*ContainerStats, error) {
if err := c.checkSandboxRunning("stats"); err != nil {
return nil, err

View File

@ -582,7 +582,6 @@ type VCSandbox interface {
ResumeContainer(containerID string) error
EnterContainer(containerID string, cmd types.Cmd) (VCContainer, *Process, error)
UpdateContainer(containerID string, resources specs.LinuxResources) error
ProcessListContainer(containerID string, options ProcessListOptions) (ProcessList, error)
WaitProcess(containerID, processID string) (int32, error)
SignalProcess(containerID, processID string, signal syscall.Signal, all bool) error
WinsizeProcess(containerID, processID string, height, width uint32) error
@ -916,7 +915,6 @@ type VCContainer interface {
* [`EnterContainer`](#entercontainer)
* [`StatusContainer`](#statuscontainer)
* [`KillContainer`](#killcontainer)
* [`ProcessListContainer`](#processlistcontainer)
* [`StatsContainer`](#statscontainer)
* [`PauseContainer`](#pausecontainer)
* [`ResumeContainer`](#resumecontainer)
@ -977,13 +975,6 @@ func StatusContainer(sandboxID, containerID string) (ContainerStatus, error)
func KillContainer(sandboxID, containerID string, signal syscall.Signal, all bool) error
```
#### `ProcessListContainer`
```Go
// ProcessListContainer is the virtcontainers entry point to list
// processes running inside a container
func ProcessListContainer(sandboxID, containerID string, options ProcessListOptions) (ProcessList, error)
```
#### `StatsContainer`
```Go
// StatsContainer return the stats of a running container

View File

@ -57,7 +57,6 @@ type VCSandbox interface {
ResumeContainer(ctx context.Context, containerID string) error
EnterContainer(ctx context.Context, containerID string, cmd types.Cmd) (VCContainer, *Process, error)
UpdateContainer(ctx context.Context, containerID string, resources specs.LinuxResources) error
ProcessListContainer(ctx context.Context, containerID string, options ProcessListOptions) (ProcessList, error)
WaitProcess(ctx context.Context, containerID, processID string) (int32, error)
SignalProcess(ctx context.Context, containerID, processID string, signal syscall.Signal, all bool) error
WinsizeProcess(ctx context.Context, containerID, processID string, height, width uint32) error

View File

@ -120,7 +120,6 @@ const (
grpcListRoutesRequest = "grpc.ListRoutesRequest"
grpcAddARPNeighborsRequest = "grpc.AddARPNeighborsRequest"
grpcOnlineCPUMemRequest = "grpc.OnlineCPUMemRequest"
grpcListProcessesRequest = "grpc.ListProcessesRequest"
grpcUpdateContainerRequest = "grpc.UpdateContainerRequest"
grpcWaitProcessRequest = "grpc.WaitProcessRequest"
grpcTtyWinResizeRequest = "grpc.TtyWinResizeRequest"
@ -1662,26 +1661,6 @@ func (k *kataAgent) winsizeProcess(ctx context.Context, c *Container, processID
return err
}
func (k *kataAgent) processListContainer(ctx context.Context, sandbox *Sandbox, c Container, options ProcessListOptions) (ProcessList, error) {
req := &grpc.ListProcessesRequest{
ContainerId: c.id,
Format: options.Format,
Args: options.Args,
}
resp, err := k.sendReq(ctx, req)
if err != nil {
return nil, err
}
processList, ok := resp.(*grpc.ListProcessesResponse)
if !ok {
return nil, fmt.Errorf("Bad list processes response")
}
return processList.ProcessList, nil
}
func (k *kataAgent) updateContainer(ctx context.Context, sandbox *Sandbox, c Container, resources specs.LinuxResources) error {
grpcResources, err := grpc.ResourcesOCItoGRPC(&resources)
if err != nil {
@ -1939,9 +1918,6 @@ func (k *kataAgent) installReqFunc(c *kataclient.AgentClient) {
k.reqHandlers[grpcOnlineCPUMemRequest] = func(ctx context.Context, req interface{}) (interface{}, error) {
return k.client.AgentServiceClient.OnlineCPUMem(ctx, req.(*grpc.OnlineCPUMemRequest))
}
k.reqHandlers[grpcListProcessesRequest] = func(ctx context.Context, req interface{}) (interface{}, error) {
return k.client.AgentServiceClient.ListProcesses(ctx, req.(*grpc.ListProcessesRequest))
}
k.reqHandlers[grpcUpdateContainerRequest] = func(ctx context.Context, req interface{}) (interface{}, error) {
return k.client.AgentServiceClient.UpdateContainer(ctx, req.(*grpc.UpdateContainerRequest))
}

View File

@ -143,9 +143,6 @@ func TestKataAgentSendReq(t *testing.T) {
err = k.winsizeProcess(ctx, container, execid, 100, 200)
assert.Nil(err)
_, err = k.processListContainer(ctx, sandbox, Container{}, ProcessListOptions{})
assert.Nil(err)
err = k.updateContainer(ctx, sandbox, Container{}, specs.LinuxResources{})
assert.Nil(err)

View File

@ -86,11 +86,6 @@ func (n *mockAgent) signalProcess(ctx context.Context, c *Container, processID s
return nil
}
// processListContainer is the Noop agent Container ps implementation. It does nothing.
func (n *mockAgent) processListContainer(ctx context.Context, sandbox *Sandbox, c Container, options ProcessListOptions) (ProcessList, error) {
return nil, nil
}
// updateContainer is the Noop agent Container update implementation. It does nothing.
func (n *mockAgent) updateContainer(ctx context.Context, sandbox *Sandbox, c Container, resources specs.LinuxResources) error {
return nil

View File

@ -107,10 +107,6 @@ func (p *HybridVSockTTRPCMockImp) WaitProcess(ctx context.Context, req *pb.WaitP
return &pb.WaitProcessResponse{}, nil
}
func (p *HybridVSockTTRPCMockImp) ListProcesses(ctx context.Context, req *pb.ListProcessesRequest) (*pb.ListProcessesResponse, error) {
return &pb.ListProcessesResponse{}, nil
}
func (p *HybridVSockTTRPCMockImp) UpdateContainer(ctx context.Context, req *pb.UpdateContainerRequest) (*gpb.Empty, error) {
return emptyResp, nil
}

View File

@ -166,11 +166,6 @@ func (s *Sandbox) UpdateContainer(ctx context.Context, containerID string, resou
return nil
}
// ProcessListContainer implements the VCSandbox function of the same name.
func (s *Sandbox) ProcessListContainer(ctx context.Context, containerID string, options vc.ProcessListOptions) (vc.ProcessList, error) {
return nil, nil
}
// WaitProcess implements the VCSandbox function of the same name.
func (s *Sandbox) WaitProcess(ctx context.Context, containerID, processID string) (int32, error) {
return 0, nil

View File

@ -53,7 +53,6 @@ type Sandbox struct {
EnterContainerFunc func(containerID string, cmd types.Cmd) (vc.VCContainer, *vc.Process, error)
MonitorFunc func() (chan error, error)
UpdateContainerFunc func(containerID string, resources specs.LinuxResources) error
ProcessListContainerFunc func(containerID string, options vc.ProcessListOptions) (vc.ProcessList, error)
WaitProcessFunc func(containerID, processID string) (int32, error)
SignalProcessFunc func(containerID, processID string, signal syscall.Signal, all bool) error
WinsizeProcessFunc func(containerID, processID string, height, width uint32) error

View File

@ -1273,19 +1273,6 @@ func (s *Sandbox) DeleteContainer(ctx context.Context, containerID string) (VCCo
return c, nil
}
// ProcessListContainer lists every process running inside a specific
// container in the sandbox.
func (s *Sandbox) ProcessListContainer(ctx context.Context, containerID string, options ProcessListOptions) (ProcessList, error) {
// Fetch the container.
c, err := s.findContainer(containerID)
if err != nil {
return nil, err
}
// Get the process list related to the container.
return c.processList(ctx, options)
}
// StatusContainer gets the status of a container
// TODO: update container status properly, see kata-containers/runtime#253
func (s *Sandbox) StatusContainer(containerID string) (ContainerStatus, error) {

View File

@ -146,14 +146,13 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "cgroups-rs"
version = "0.2.1"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "348eb6d8e20a9f5247209686b7d0ffc2f4df40ddcb95f9940de55a94a655b3f5"
checksum = "d4cec688ee0fcd143ffd7893ce2c9857bfc656eb1f2a27202244b72f08f5f8ed"
dependencies = [
"libc",
"log",
"nix 0.18.0",
"procinfo",
"nix 0.20.0",
"regex",
]
@ -484,9 +483,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.79"
version = "0.2.93"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2448f6066e80e3bfc792e9c98bf705b4b0fc6e8ef5b43e5889aff0eaa9c58743"
checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41"
[[package]]
name = "log"
@ -585,18 +584,6 @@ dependencies = [
"void",
]
[[package]]
name = "nix"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "83450fe6a6142ddd95fb064b746083fc4ef1705fe81f64a64e1d4b39f54a1055"
dependencies = [
"bitflags",
"cc",
"cfg-if 0.1.10",
"libc",
]
[[package]]
name = "nix"
version = "0.19.1"
@ -610,10 +597,16 @@ dependencies = [
]
[[package]]
name = "nom"
version = "2.2.1"
name = "nix"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf51a729ecf40266a2368ad335a5fdde43471f545a967109cd62146ecf8b66ff"
checksum = "fa9b4819da1bc61c0ea48b63b7bc8604064dd43013e7cc325df098d49cd7c18a"
dependencies = [
"bitflags",
"cc",
"cfg-if 1.0.0",
"libc",
]
[[package]]
name = "ntapi"
@ -738,7 +731,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "059a34f111a9dee2ce1ac2826a68b24601c4298cfeb1a587c3cb493d5ab46f52"
dependencies = [
"libc",
"nix 0.18.0",
"nix 0.19.1",
]
[[package]]
@ -771,18 +764,6 @@ dependencies = [
"unicode-xid 0.2.1",
]
[[package]]
name = "procinfo"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ab1427f3d2635891f842892dda177883dca0639e05fe66796a62c9d2f23b49c"
dependencies = [
"byteorder",
"libc",
"nom",
"rustc_version",
]
[[package]]
name = "prost"
version = "0.5.0"
@ -977,15 +958,6 @@ version = "0.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e3bad0ee36814ca07d7968269dd4b7ec89ec2da10c4bb613928d3077083c232"
[[package]]
name = "rustc_version"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
dependencies = [
"semver",
]
[[package]]
name = "rustjail"
version = "0.1.0"
@ -1038,21 +1010,6 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "semver"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
dependencies = [
"semver-parser",
]
[[package]]
name = "semver-parser"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
[[package]]
name = "serde"
version = "1.0.114"

View File

@ -79,9 +79,6 @@ const CMD_REPEAT: &'static str = "repeat";
const DEFAULT_PROC_SIGNAL: &'static str = "SIGKILL";
// Format is either "json" or "table".
const DEFAULT_PS_FORMAT: &str = "json";
const ERR_API_FAILED: &str = "API failed";
static AGENT_CMDS: &'static [AgentCmd] = &[
@ -155,11 +152,6 @@ static AGENT_CMDS: &'static [AgentCmd] = &[
st: ServiceType::Agent,
fp: agent_cmd_sandbox_list_routes,
},
AgentCmd {
name: "ListProcesses",
st: ServiceType::Agent,
fp: agent_cmd_container_list_processes,
},
AgentCmd {
name: "MemHotplugByProbe",
st: ServiceType::Agent,
@ -1101,40 +1093,6 @@ fn agent_cmd_sandbox_get_guest_details(
Ok(())
}
fn agent_cmd_container_list_processes(
ctx: &Context,
client: &AgentServiceClient,
_health: &HealthClient,
options: &mut Options,
args: &str,
) -> Result<()> {
let mut req = ListProcessesRequest::default();
let ctx = clone_context(ctx);
let cid = utils::get_option("cid", options, args);
let mut list_format = utils::get_option("format", options, args);
if list_format == "" {
list_format = DEFAULT_PS_FORMAT.to_string();
}
req.set_container_id(cid);
req.set_format(list_format);
debug!(sl!(), "sending request"; "request" => format!("{:?}", req));
let reply = client
.list_processes(ctx, &req)
.map_err(|e| anyhow!("{:?}", e).context(ERR_API_FAILED))?;
info!(sl!(), "response received";
"response" => format!("{:?}", reply));
Ok(())
}
fn agent_cmd_container_wait_process(
ctx: &Context,
client: &AgentServiceClient,