-
Notifications
You must be signed in to change notification settings - Fork 73
/
healthcheck.go
62 lines (51 loc) 路 1.19 KB
/
healthcheck.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package cmd
import (
"context"
"fmt"
"github.com/urfave/cli/v2"
"github.com/testground/testground/pkg/api"
"github.com/testground/testground/pkg/client"
)
var HealthcheckCommand = cli.Command{
Name: "healthcheck",
Usage: "validate/fix the preconditions for the runner to be able to operate properly",
Action: healthcheckCommand,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "fix",
Usage: "attempt to fix failing preconditions",
},
&cli.StringFlag{
Name: "runner",
Usage: "specifies the runner to use; values include: 'local:exec', 'local:docker', 'cluster:k8s'",
Required: true,
},
},
}
func healthcheckCommand(c *cli.Context) error {
ctx, cancel := context.WithCancel(ProcessContext())
defer cancel()
var (
runner = c.String("runner")
fix = c.Bool("fix")
)
cl, _, err := setupClient(c)
if err != nil {
return err
}
r, err := cl.Healthcheck(ctx, &api.HealthcheckRequest{
Runner: runner,
Fix: fix,
})
if err != nil {
return err
}
defer r.Close()
resp, err := client.ParseHealthcheckResponse(r, c.App.Writer)
if err != nil {
return err
}
fmt.Printf("finished checking runner %s\n", runner)
fmt.Println(resp.String())
return nil
}