Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 012d492

Browse files
committed
add grpc api of container signal
Signed-off-by: haozhang <crazykev@zju.edu.cn>
1 parent 90cf14d commit 012d492

File tree

5 files changed

+128
-6
lines changed

5 files changed

+128
-6
lines changed

integration/client.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,3 +735,17 @@ func (c *HyperClient) Ping() (*types.PingResponse, error) {
735735

736736
return resp, nil
737737
}
738+
739+
// ContainerSignal sends a signal to specified container of specified pod
740+
func (c *HyperClient) ContainerSignal(podID, containerID string, signal int64) error {
741+
_, err := c.client.ContainerSignal(c.ctx, &types.ContainerSignalRequest{
742+
PodID: podID,
743+
ContainerID: containerID,
744+
Signal: signal,
745+
})
746+
if err != nil {
747+
return err
748+
}
749+
750+
return nil
751+
}

integration/hyper_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,3 +494,41 @@ func (s *TestSuite) TestPing(c *C) {
494494
c.Assert(err, IsNil)
495495
c.Logf("Got HyperdStats %v", resp)
496496
}
497+
498+
func (s *TestSuite) TestSendContainerSignal(c *C) {
499+
sigKill := int64(9)
500+
spec := types.UserPod{
501+
Id: "busybox",
502+
}
503+
504+
pod, err := s.client.CreatePod(&spec)
505+
c.Assert(err, IsNil)
506+
c.Logf("Pod created: %s", pod)
507+
508+
defer func() {
509+
err = s.client.RemovePod(pod)
510+
c.Assert(err, IsNil)
511+
}()
512+
513+
container, err := s.client.CreateContainer(pod, &types.UserContainer{Image: "busybox"})
514+
c.Assert(err, IsNil)
515+
c.Logf("Container created: %s", container)
516+
517+
err = s.client.StartPod(pod, "", false)
518+
c.Assert(err, IsNil)
519+
520+
containerInfo, err := s.client.GetContainerInfo(container)
521+
c.Assert(err, IsNil)
522+
c.Assert(containerInfo.Status.Phase, Equals, "running")
523+
524+
err = s.client.ContainerSignal(pod, container, sigKill)
525+
c.Assert(err, IsNil)
526+
527+
exitCode, err := s.client.Wait(container, "", false)
528+
c.Assert(err, IsNil)
529+
c.Assert(exitCode, Equals, int32(137))
530+
531+
containerInfo, err = s.client.GetContainerInfo(container)
532+
c.Assert(err, IsNil)
533+
c.Assert(containerInfo.Status.Phase, Equals, "failed")
534+
}

serverrpc/container.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,16 @@ func (s *ServerRPC) ContainerRemove(ctx context.Context, req *types.ContainerRem
6666
}
6767
return &types.ContainerRemoveResponse{}, nil
6868
}
69+
70+
// ContainerSignal sends a singal to specified container of specified pod
71+
func (s *ServerRPC) ContainerSignal(ctx context.Context, req *types.ContainerSignalRequest) (*types.ContainerSignalResponse, error) {
72+
glog.V(3).Infof("ContainerSignal with request %s", req.String())
73+
74+
err := s.daemon.KillPodContainers(req.PodID, req.ContainerID, req.Signal)
75+
if err != nil {
76+
glog.Errorf("Kill Container %s of Pod %s with signal %d failed: %v", req.ContainerID, req.PodID, req.Signal, err)
77+
return nil, err
78+
}
79+
80+
return &types.ContainerSignalResponse{}, nil
81+
}

types/types.pb.go

Lines changed: 52 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

types/types.proto

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,14 @@ message PingResponse {
759759
string hyperdStats = 1;
760760
}
761761

762+
message ContainerSignalRequest {
763+
string podID = 1;
764+
string containerID = 2;
765+
int64 signal = 3;
766+
}
767+
768+
message ContainerSignalResponse{}
769+
762770
// PublicAPI defines the public APIs which are handled over TCP sockets.
763771
service PublicAPI {
764772
// PodList gets a list of pods
@@ -773,7 +781,7 @@ service PublicAPI {
773781
rpc PodStart(stream PodStartMessage) returns (stream PodStartMessage) {}
774782
// PodStop stops a pod
775783
rpc PodStop(PodStopRequest) returns (PodStopResponse) {}
776-
// PodSignal sends a singal to all containers of specified pod
784+
// PodSignal sends a signal to all containers of specified pod
777785
rpc PodSignal(PodSignalRequest) returns (PodSignalResponse) {}
778786
// PodPause pauses a pod
779787
rpc PodPause(PodPauseRequest) returns (PodPauseResponse) {}
@@ -806,7 +814,8 @@ service PublicAPI {
806814
// ContainerRename renames a container
807815
rpc ContainerRename(ContainerRenameRequest) returns (ContainerRenameResponse) {}
808816
// TODO: ContainerCommit commits the changes of the specified container
809-
// TODO: ContainerSignal sends a singla to specified container
817+
// ContainerSignal sends a signal to specified container
818+
rpc ContainerSignal(ContainerSignalRequest) returns (ContainerSignalResponse) {}
810819
// TODO: ContainerLabels updates labels of the specified container
811820
// ContainerStop stops the specified container
812821
rpc ContainerStop(ContainerStopRequest) returns (ContainerStopResponse) {}

0 commit comments

Comments
 (0)