...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package client
17
18 import (
19 "context"
20
21 "github.com/hasura/go-graphql-client"
22 "github.com/pkg/errors"
23 )
24
25 func (c *CtrlClient) KillProcesses(ctx context.Context, namespace, name string, pids []string) ([]string, error) {
26 var graphqlPids []graphql.String
27 for _, p := range pids {
28 graphqlPids = append(graphqlPids, graphql.String(p))
29 }
30 var mutation struct {
31 Pod struct {
32 KillProcesses []struct {
33 Pid, Command string
34 } `graphql:"killProcesses(pids: $pids)"`
35 } `graphql:"pod(ns: $ns, name: $name)"`
36 }
37
38 err := c.QueryClient.Mutate(ctx, &mutation, map[string]interface{}{
39 "pids": graphqlPids,
40 "ns": graphql.String(namespace),
41 "name": graphql.String(name),
42 })
43
44 if err != nil {
45 return nil, errors.Wrapf(err, "kill processes(%v)", pids)
46 }
47
48 var killedPids []string
49 for _, p := range mutation.Pod.KillProcesses {
50 killedPids = append(killedPids, p.Pid)
51 }
52 return killedPids, nil
53 }
54