-
Notifications
You must be signed in to change notification settings - Fork 290
/
doctor.go
155 lines (121 loc) · 3.69 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package cli
import (
"context"
"fmt"
"runtime"
"time"
"github.com/spf13/cobra"
wmanalytics "github.com/windmilleng/wmclient/pkg/analytics"
"github.com/windmilleng/tilt/internal/analytics"
)
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 {
analytics.Get(ctx).Incr("cmd.doctor", map[string]string{})
defer analytics.Get(ctx).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()
clusterDocker, clusterDockerErr := wireDockerClusterClient(ctx)
if clusterDockerErr == nil {
clusterDockerErr = clusterDocker.CheckConnected()
}
localDocker, localDockerErr := wireDockerLocalClient(ctx)
if localDockerErr == nil {
localDockerErr = localDocker.CheckConnected()
}
isLocalDockerErr := localDockerErr != nil
isClusterDockerErr := clusterDockerErr != nil
twoDockerClients := (isLocalDockerErr != isClusterDockerErr) ||
(!isLocalDockerErr && !isClusterDockerErr && localDocker.Env().Host != clusterDocker.Env().Host)
fmt.Println("---")
if twoDockerClients {
fmt.Println("Docker (cluster)")
} else {
fmt.Println("Docker")
}
if clusterDockerErr != nil {
printField("Host", nil, clusterDockerErr)
} else {
dockerEnv := clusterDocker.Env()
host := dockerEnv.Host
if host == "" {
host = "[default]"
}
printField("Host", host, nil)
version := clusterDocker.ServerVersion()
printField("Version", version.APIVersion, nil)
builderVersion := clusterDocker.BuilderVersion()
printField("Builder", builderVersion, nil)
}
if twoDockerClients {
fmt.Println("---")
fmt.Println("Docker (local)")
if localDockerErr != nil {
printField("Host", nil, localDockerErr)
} else {
dockerEnv := localDocker.Env()
host := dockerEnv.Host
if host == "" {
host = "[default]"
}
printField("Host", host, nil)
version := localDocker.ServerVersion()
printField("Version", version.APIVersion, nil)
builderVersion := localDocker.BuilderVersion()
printField("Builder", builderVersion, nil)
}
}
fmt.Println("---")
fmt.Println("Kubernetes")
env, err := wireEnv(ctx)
printField("Env", env, err)
kContext, err := wireKubeContext(ctx)
printField("Context", kContext, err)
clusterName, err := wireClusterName(ctx)
if clusterName == "" {
clusterName = "Unknown"
}
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 the info above when filing bug reports. 💗")
fmt.Println("")
fmt.Println("The info below helps us understand how you're using Tilt so we can improve,")
fmt.Println("but is not required to ask for help.")
fmt.Println("---")
fmt.Println("Analytics Settings")
a := analytics.Get(ctx)
opt := a.UserOpt()
fmt.Printf("- User Mode: %s\n", opt)
machineHash := "[redacted]"
gitRepoHash := "[redacted]"
if opt == wmanalytics.OptIn {
machineHash = a.MachineHash()
gitRepoHash = a.GitRepoHash()
}
fmt.Printf("- Machine: %s\n", machineHash)
fmt.Printf("- Repo: %s\n", gitRepoHash)
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)
}
}