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