...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package chaosdaemon
17
18 import (
19 "context"
20 "fmt"
21
22 "github.com/golang/protobuf/ptypes/empty"
23
24 pb "github.com/chaos-mesh/chaos-mesh/pkg/chaosdaemon/pb"
25 )
26
27
28 func (s *DaemonServer) ContainerKill(ctx context.Context, req *pb.ContainerRequest) (*empty.Empty, error) {
29 log.Info("Container Kill", "request", req)
30
31 action := req.Action.Action
32 if action != pb.ContainerAction_KILL {
33 err := fmt.Errorf("container action is %s , not kill", action)
34 log.Error(err, "container action is not expected")
35 return nil, err
36 }
37
38 err := s.crClient.ContainerKillByContainerID(ctx, req.ContainerId)
39 if err != nil {
40 log.Error(err, "error while killing container")
41 return nil, err
42 }
43
44 return &empty.Empty{}, nil
45 }
46
47 func (s *DaemonServer) ContainerGetPid(ctx context.Context, req *pb.ContainerRequest) (*pb.ContainerResponse, error) {
48 log.Info("container GetPid", "request", req)
49
50 action := req.Action.Action
51 if action != pb.ContainerAction_GETPID {
52 err := fmt.Errorf("container action is %s , not getpid", action)
53 log.Error(err, "container action is not expected")
54 return nil, err
55 }
56
57 pid, err := s.crClient.GetPidFromContainerID(ctx, req.ContainerId)
58 if err != nil {
59 log.Error(err, "error while getting pid from container")
60 return nil, err
61 }
62
63 return &pb.ContainerResponse{Pid: pid}, nil
64 }
65