-
Notifications
You must be signed in to change notification settings - Fork 288
/
doctor.go
92 lines (73 loc) · 1.96 KB
/
doctor.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package cli
import (
"context"
"fmt"
"runtime"
"time"
"github.com/spf13/cobra"
)
type doctorCmd struct {
}
func (c *doctorCmd) register() *cobra.Command {
cmd := &cobra.Command{
Use: "doctor",
Short: "Print diagnostic information about the Tilt environment, for filing bug reports",
}
return cmd
}
func (c *doctorCmd) run(ctx context.Context, args []string) error {
analyticsService.Incr("cmd.doctor", map[string]string{})
defer analyticsService.Flush(time.Second)
fmt.Printf("Tilt: %s\n", buildStamp())
fmt.Printf("System: %s-%s\n", runtime.GOOS, runtime.GOARCH)
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
fmt.Println("---")
fmt.Println("Docker")
dockerEnv, err := wireDockerEnv(ctx)
if err != nil {
printField("Host", nil, err)
} else {
host := dockerEnv.Host
if host == "" {
host = "[default]"
}
printField("Host", host, err)
}
dockerVersion, err := wireDockerVersion(ctx)
if err != nil {
printField("Version", "", err)
} else {
printField("Version", dockerVersion.APIVersion, err)
}
fmt.Println("---")
fmt.Println("Kubernetes")
env, err := wireEnv(ctx)
printField("Env", env, err)
kContext, err := wireKubeContext(ctx)
printField("Context", kContext, err)
kConfig, err := wireKubeConfig(ctx)
kc, ok := kConfig.Contexts[kConfig.CurrentContext]
clusterName := "Unknown"
if ok {
clusterName = kc.Cluster
}
printField("Cluster Name", clusterName, err)
ns, err := wireNamespace(ctx)
printField("Namespace", ns, err)
runtime, err := wireRuntime(ctx)
printField("Container Runtime", runtime, err)
kVersion, err := wireK8sVersion(ctx)
printField("Version", kVersion, err)
fmt.Println("---")
fmt.Println("Thanks for seeing the Tilt Doctor!")
fmt.Println("Please send this info along when filing bug reports. 💗")
return nil
}
func printField(name string, v interface{}, err error) {
if err != nil {
fmt.Printf("- %s: Error: %v\n", name, err)
} else {
fmt.Printf("- %s: %s\n", name, v)
}
}