Skip to content

Commit cf887e7

Browse files
authored
Merge pull request #7105 from prasadkatti/add_desc_node_to_minikube_logs
Add kubectl desc nodes to minikube logs
2 parents 8e9d8a2 + 376271a commit cf887e7

File tree

6 files changed

+38
-29
lines changed

6 files changed

+38
-29
lines changed

cmd/minikube/cmd/logs.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,18 @@ var logsCmd = &cobra.Command{
9595
exit.WithError("Unable to get runtime", err)
9696
}
9797
if followLogs {
98-
err := logs.Follow(cr, bs, runner)
98+
err := logs.Follow(cr, bs, *cfg, runner)
9999
if err != nil {
100100
exit.WithError("Follow", err)
101101
}
102102
return
103103
}
104104
if showProblems {
105-
problems := logs.FindProblems(cr, bs, runner)
105+
problems := logs.FindProblems(cr, bs, *cfg, runner)
106106
logs.OutputProblems(problems, numberOfProblems)
107107
return
108108
}
109-
err = logs.Output(cr, bs, runner, numberOfLines)
109+
err = logs.Output(cr, bs, *cfg, runner, numberOfLines)
110110
if err != nil {
111111
exit.WithError("Error getting machine logs", err)
112112
}

pkg/minikube/bootstrapper/bootstrapper.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type Bootstrapper interface {
4444
UpdateNode(config.ClusterConfig, config.Node, cruntime.Manager) error
4545
GenerateToken(config.ClusterConfig) (string, error)
4646
// LogCommands returns a map of log type to a command which will display that log.
47-
LogCommands(LogOptions) map[string]string
47+
LogCommands(config.ClusterConfig, LogOptions) map[string]string
4848
SetupCerts(config.KubernetesConfig, config.Node) error
4949
GetKubeletStatus() (string, error)
5050
GetAPIServerStatus(net.IP, int) (string, error)

pkg/minikube/bootstrapper/bsutil/kverify/kverify.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
kconst "k8s.io/kubernetes/cmd/kubeadm/app/constants"
3838
"k8s.io/minikube/pkg/minikube/bootstrapper"
3939
"k8s.io/minikube/pkg/minikube/command"
40+
"k8s.io/minikube/pkg/minikube/config"
4041
"k8s.io/minikube/pkg/minikube/cruntime"
4142
"k8s.io/minikube/pkg/minikube/logs"
4243
)
@@ -45,15 +46,15 @@ import (
4546
const minLogCheckTime = 30 * time.Second
4647

4748
// WaitForAPIServerProcess waits for api server to be healthy returns error if it doesn't
48-
func WaitForAPIServerProcess(r cruntime.Manager, bs bootstrapper.Bootstrapper, cr command.Runner, start time.Time, timeout time.Duration) error {
49+
func WaitForAPIServerProcess(r cruntime.Manager, bs bootstrapper.Bootstrapper, cfg config.ClusterConfig, cr command.Runner, start time.Time, timeout time.Duration) error {
4950
glog.Infof("waiting for apiserver process to appear ...")
5051
err := wait.PollImmediate(time.Millisecond*500, timeout, func() (bool, error) {
5152
if time.Since(start) > timeout {
5253
return false, fmt.Errorf("cluster wait timed out during process check")
5354
}
5455

5556
if time.Since(start) > minLogCheckTime {
56-
announceProblems(r, bs, cr)
57+
announceProblems(r, bs, cfg, cr)
5758
time.Sleep(kconst.APICallRetryInterval * 5)
5859
}
5960

@@ -142,7 +143,7 @@ func podStatusMsg(pod core.Pod) string {
142143
}
143144

144145
// WaitForSystemPods verifies essential pods for running kurnetes is running
145-
func WaitForSystemPods(r cruntime.Manager, bs bootstrapper.Bootstrapper, cr command.Runner, client *kubernetes.Clientset, start time.Time, timeout time.Duration) error {
146+
func WaitForSystemPods(r cruntime.Manager, bs bootstrapper.Bootstrapper, cfg config.ClusterConfig, cr command.Runner, client *kubernetes.Clientset, start time.Time, timeout time.Duration) error {
146147
glog.Info("waiting for kube-system pods to appear ...")
147148
pStart := time.Now()
148149

@@ -151,7 +152,7 @@ func WaitForSystemPods(r cruntime.Manager, bs bootstrapper.Bootstrapper, cr comm
151152
return false, fmt.Errorf("cluster wait timed out during pod check")
152153
}
153154
if time.Since(start) > minLogCheckTime {
154-
announceProblems(r, bs, cr)
155+
announceProblems(r, bs, cfg, cr)
155156
time.Sleep(kconst.APICallRetryInterval * 5)
156157
}
157158

@@ -179,7 +180,7 @@ func WaitForSystemPods(r cruntime.Manager, bs bootstrapper.Bootstrapper, cr comm
179180
}
180181

181182
// WaitForHealthyAPIServer waits for api server status to be running
182-
func WaitForHealthyAPIServer(r cruntime.Manager, bs bootstrapper.Bootstrapper, cr command.Runner, start time.Time, ip string, port int, timeout time.Duration) error {
183+
func WaitForHealthyAPIServer(r cruntime.Manager, bs bootstrapper.Bootstrapper, cfg config.ClusterConfig, cr command.Runner, start time.Time, ip string, port int, timeout time.Duration) error {
183184
glog.Infof("waiting for apiserver healthz status ...")
184185
hStart := time.Now()
185186

@@ -189,7 +190,7 @@ func WaitForHealthyAPIServer(r cruntime.Manager, bs bootstrapper.Bootstrapper, c
189190
}
190191

191192
if time.Since(start) > minLogCheckTime {
192-
announceProblems(r, bs, cr)
193+
announceProblems(r, bs, cfg, cr)
193194
time.Sleep(kconst.APICallRetryInterval * 5)
194195
}
195196

@@ -212,8 +213,8 @@ func WaitForHealthyAPIServer(r cruntime.Manager, bs bootstrapper.Bootstrapper, c
212213
}
213214

214215
// announceProblems checks for problems, and slows polling down if any are found
215-
func announceProblems(r cruntime.Manager, bs bootstrapper.Bootstrapper, cr command.Runner) {
216-
problems := logs.FindProblems(r, bs, cr)
216+
func announceProblems(r cruntime.Manager, bs bootstrapper.Bootstrapper, cfg config.ClusterConfig, cr command.Runner) {
217+
problems := logs.FindProblems(r, bs, cfg, cr)
217218
if len(problems) > 0 {
218219
logs.OutputProblems(problems, 5)
219220
time.Sleep(kconst.APICallRetryInterval * 15)

pkg/minikube/bootstrapper/kubeadm/kubeadm.go

+14-8
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func (k *Bootstrapper) GetAPIServerStatus(ip net.IP, port int) (string, error) {
110110
}
111111

112112
// LogCommands returns a map of log type to a command which will display that log.
113-
func (k *Bootstrapper) LogCommands(o bootstrapper.LogOptions) map[string]string {
113+
func (k *Bootstrapper) LogCommands(cfg config.ClusterConfig, o bootstrapper.LogOptions) map[string]string {
114114
var kubelet strings.Builder
115115
kubelet.WriteString("sudo journalctl -u kubelet")
116116
if o.Lines > 0 {
@@ -128,9 +128,15 @@ func (k *Bootstrapper) LogCommands(o bootstrapper.LogOptions) map[string]string
128128
if o.Lines > 0 {
129129
dmesg.WriteString(fmt.Sprintf(" | tail -n %d", o.Lines))
130130
}
131+
132+
describeNodes := fmt.Sprintf("sudo %s describe node -A --kubeconfig=%s",
133+
path.Join(vmpath.GuestPersistentDir, "binaries", cfg.KubernetesConfig.KubernetesVersion, "kubectl"),
134+
path.Join(vmpath.GuestPersistentDir, "kubeconfig"))
135+
131136
return map[string]string{
132-
"kubelet": kubelet.String(),
133-
"dmesg": dmesg.String(),
137+
"kubelet": kubelet.String(),
138+
"dmesg": dmesg.String(),
139+
"describe nodes": describeNodes,
134140
}
135141
}
136142

@@ -287,7 +293,7 @@ func (k *Bootstrapper) WaitForNode(cfg config.ClusterConfig, n config.Node, time
287293
return err
288294
}
289295

290-
if err := kverify.WaitForAPIServerProcess(cr, k, k.c, start, timeout); err != nil {
296+
if err := kverify.WaitForAPIServerProcess(cr, k, cfg, k.c, start, timeout); err != nil {
291297
return err
292298
}
293299

@@ -296,7 +302,7 @@ func (k *Bootstrapper) WaitForNode(cfg config.ClusterConfig, n config.Node, time
296302
return err
297303
}
298304

299-
if err := kverify.WaitForHealthyAPIServer(cr, k, k.c, start, ip, port, timeout); err != nil {
305+
if err := kverify.WaitForHealthyAPIServer(cr, k, cfg, k.c, start, ip, port, timeout); err != nil {
300306
return err
301307
}
302308

@@ -305,7 +311,7 @@ func (k *Bootstrapper) WaitForNode(cfg config.ClusterConfig, n config.Node, time
305311
return errors.Wrap(err, "get k8s client")
306312
}
307313

308-
if err := kverify.WaitForSystemPods(cr, k, k.c, c, start, timeout); err != nil {
314+
if err := kverify.WaitForSystemPods(cr, k, cfg, k.c, c, start, timeout); err != nil {
309315
return errors.Wrap(err, "waiting for system pods")
310316
}
311317
return nil
@@ -411,11 +417,11 @@ func (k *Bootstrapper) restartCluster(cfg config.ClusterConfig) error {
411417
}
412418

413419
// We must ensure that the apiserver is healthy before proceeding
414-
if err := kverify.WaitForAPIServerProcess(cr, k, k.c, time.Now(), kconst.DefaultControlPlaneTimeout); err != nil {
420+
if err := kverify.WaitForAPIServerProcess(cr, k, cfg, k.c, time.Now(), kconst.DefaultControlPlaneTimeout); err != nil {
415421
return errors.Wrap(err, "apiserver healthz")
416422
}
417423

418-
if err := kverify.WaitForSystemPods(cr, k, k.c, client, time.Now(), kconst.DefaultControlPlaneTimeout); err != nil {
424+
if err := kverify.WaitForSystemPods(cr, k, cfg, k.c, client, time.Now(), kconst.DefaultControlPlaneTimeout); err != nil {
419425
return errors.Wrap(err, "system pods")
420426
}
421427

pkg/minikube/logs/logs.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/pkg/errors"
3232
"k8s.io/minikube/pkg/minikube/bootstrapper"
3333
"k8s.io/minikube/pkg/minikube/command"
34+
"k8s.io/minikube/pkg/minikube/config"
3435
"k8s.io/minikube/pkg/minikube/cruntime"
3536
"k8s.io/minikube/pkg/minikube/out"
3637
)
@@ -87,9 +88,9 @@ type logRunner interface {
8788
const lookBackwardsCount = 400
8889

8990
// Follow follows logs from multiple files in tail(1) format
90-
func Follow(r cruntime.Manager, bs bootstrapper.Bootstrapper, cr logRunner) error {
91+
func Follow(r cruntime.Manager, bs bootstrapper.Bootstrapper, cfg config.ClusterConfig, cr logRunner) error {
9192
cs := []string{}
92-
for _, v := range logCommands(r, bs, 0, true) {
93+
for _, v := range logCommands(r, bs, cfg, 0, true) {
9394
cs = append(cs, v+" &")
9495
}
9596
cs = append(cs, "wait")
@@ -109,9 +110,9 @@ func IsProblem(line string) bool {
109110
}
110111

111112
// FindProblems finds possible root causes among the logs
112-
func FindProblems(r cruntime.Manager, bs bootstrapper.Bootstrapper, cr logRunner) map[string][]string {
113+
func FindProblems(r cruntime.Manager, bs bootstrapper.Bootstrapper, cfg config.ClusterConfig, cr logRunner) map[string][]string {
113114
pMap := map[string][]string{}
114-
cmds := logCommands(r, bs, lookBackwardsCount, false)
115+
cmds := logCommands(r, bs, cfg, lookBackwardsCount, false)
115116
for name := range cmds {
116117
glog.Infof("Gathering logs for %s ...", name)
117118
var b bytes.Buffer
@@ -153,8 +154,8 @@ func OutputProblems(problems map[string][]string, maxLines int) {
153154
}
154155

155156
// Output displays logs from multiple sources in tail(1) format
156-
func Output(r cruntime.Manager, bs bootstrapper.Bootstrapper, runner command.Runner, lines int) error {
157-
cmds := logCommands(r, bs, lines, false)
157+
func Output(r cruntime.Manager, bs bootstrapper.Bootstrapper, cfg config.ClusterConfig, runner command.Runner, lines int) error {
158+
cmds := logCommands(r, bs, cfg, lines, false)
158159
cmds["kernel"] = "uptime && uname -a && grep PRETTY /etc/os-release"
159160

160161
names := []string{}
@@ -191,8 +192,8 @@ func Output(r cruntime.Manager, bs bootstrapper.Bootstrapper, runner command.Run
191192
}
192193

193194
// logCommands returns a list of commands that would be run to receive the anticipated logs
194-
func logCommands(r cruntime.Manager, bs bootstrapper.Bootstrapper, length int, follow bool) map[string]string {
195-
cmds := bs.LogCommands(bootstrapper.LogOptions{Lines: length, Follow: follow})
195+
func logCommands(r cruntime.Manager, bs bootstrapper.Bootstrapper, cfg config.ClusterConfig, length int, follow bool) map[string]string {
196+
cmds := bs.LogCommands(cfg, bootstrapper.LogOptions{Lines: length, Follow: follow})
196197
for _, pod := range importantPods {
197198
ids, err := r.ListContainers(cruntime.ListOptions{Name: pod})
198199
if err != nil {
@@ -211,5 +212,6 @@ func logCommands(r cruntime.Manager, bs bootstrapper.Bootstrapper, length int, f
211212
}
212213
cmds[r.Name()] = r.SystemLogCmd(length)
213214
cmds["container status"] = cruntime.ContainerStatusCommand()
215+
214216
return cmds
215217
}

pkg/minikube/node/start.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func Start(cc config.ClusterConfig, n config.Node, existingAddons map[string]boo
112112
bs = setupKubeAdm(machineAPI, cc, n)
113113
err = bs.StartCluster(cc)
114114
if err != nil {
115-
exit.WithLogEntries("Error starting cluster", err, logs.FindProblems(cr, bs, mRunner))
115+
exit.WithLogEntries("Error starting cluster", err, logs.FindProblems(cr, bs, cc, mRunner))
116116
}
117117
} else {
118118
bs, err = cluster.Bootstrapper(machineAPI, viper.GetString(cmdcfg.Bootstrapper), cc, n)

0 commit comments

Comments
 (0)