/
dashboard.go
664 lines (562 loc) · 20.5 KB
/
dashboard.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
// Copyright Istio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package dashboard
import (
"context"
"errors"
"fmt"
"io"
"os"
"os/exec"
"os/signal"
"runtime"
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"istio.io/istio/istioctl/pkg/cli"
"istio.io/istio/istioctl/pkg/clioptions"
"istio.io/istio/istioctl/pkg/util"
"istio.io/istio/pkg/kube"
"istio.io/istio/pkg/log"
)
var (
listenPort = 0
controlZport = 0
promPort = 0
grafanaPort = 0
kialiPort = 0
jaegerPort = 0
zipkinPort = 0
skywalkingPort = 0
bindAddress = ""
// open browser or not, default is true
browser = true
// label selector
labelSelector = ""
proxyAdminPort int
)
const (
defaultPrometheusPort = 9090
defaultGrafanaPort = 3000
defaultKialiPort = 20001
defaultJaegerPort = 16686
defaultZipkinPort = 9411
defaultSkywalkingPort = 8080
)
// port-forward to Istio System Prometheus; open browser
func promDashCmd(ctx cli.Context) *cobra.Command {
var opts clioptions.ControlPlaneOptions
cmd := &cobra.Command{
Use: "prometheus",
Short: "Open Prometheus web UI",
Long: `Open Istio's Prometheus dashboard`,
Example: ` istioctl dashboard prometheus
# with short syntax
istioctl dash prometheus
istioctl d prometheus`,
RunE: func(cmd *cobra.Command, args []string) error {
client, err := ctx.CLIClientWithRevision(opts.Revision)
if err != nil {
return fmt.Errorf("failed to create k8s client: %v", err)
}
name, namespace, err := inferPodMeta(ctx, client, "app.kubernetes.io/name=prometheus")
if err != nil {
return err
}
return portForward(name, namespace, "Prometheus",
"http://%s", bindAddress, promPort, client, cmd.OutOrStdout(), browser)
},
}
return cmd
}
// port-forward to Istio System Grafana; open browser
func grafanaDashCmd(ctx cli.Context) *cobra.Command {
var opts clioptions.ControlPlaneOptions
cmd := &cobra.Command{
Use: "grafana",
Short: "Open Grafana web UI",
Long: `Open Istio's Grafana dashboard`,
Example: ` istioctl dashboard grafana
# with short syntax
istioctl dash grafana
istioctl d grafana`,
RunE: func(cmd *cobra.Command, args []string) error {
client, err := ctx.CLIClientWithRevision(opts.Revision)
if err != nil {
return fmt.Errorf("failed to create k8s client: %v", err)
}
name, namespace, err := inferPodMeta(ctx, client, "app.kubernetes.io/name=grafana")
if err != nil {
return err
}
return portForward(name, namespace, "Grafana",
"http://%s", bindAddress, grafanaPort, client, cmd.OutOrStdout(), browser)
},
}
return cmd
}
// port-forward to Istio System Kiali; open browser
func kialiDashCmd(ctx cli.Context) *cobra.Command {
var opts clioptions.ControlPlaneOptions
cmd := &cobra.Command{
Use: "kiali",
Short: "Open Kiali web UI",
Long: `Open Istio's Kiali dashboard`,
Example: ` istioctl dashboard kiali
# with short syntax
istioctl dash kiali
istioctl d kiali`,
RunE: func(cmd *cobra.Command, args []string) error {
client, err := ctx.CLIClientWithRevision(opts.Revision)
if err != nil {
return fmt.Errorf("failed to create k8s client: %v", err)
}
name, namespace, err := inferPodMeta(ctx, client, "app=kiali")
if err != nil {
return err
}
return portForward(name, namespace, "Kiali",
"http://%s/kiali", bindAddress, kialiPort, client, cmd.OutOrStdout(), browser)
},
}
return cmd
}
// port-forward to Istio System Jaeger; open browser
func jaegerDashCmd(ctx cli.Context) *cobra.Command {
var opts clioptions.ControlPlaneOptions
cmd := &cobra.Command{
Use: "jaeger",
Short: "Open Jaeger web UI",
Long: `Open Istio's Jaeger dashboard`,
Example: ` istioctl dashboard jaeger
# with short syntax
istioctl dash jaeger
istioctl d jaeger`,
RunE: func(cmd *cobra.Command, args []string) error {
client, err := ctx.CLIClientWithRevision(opts.Revision)
if err != nil {
return fmt.Errorf("failed to create k8s client: %v", err)
}
name, namespace, err := inferPodMeta(ctx, client, "app=jaeger")
if err != nil {
return err
}
return portForward(name, namespace, "Jaeger",
"http://%s", bindAddress, jaegerPort, client, cmd.OutOrStdout(), browser)
},
}
return cmd
}
// port-forward to Istio System Zipkin; open browser
func zipkinDashCmd(ctx cli.Context) *cobra.Command {
var opts clioptions.ControlPlaneOptions
cmd := &cobra.Command{
Use: "zipkin",
Short: "Open Zipkin web UI",
Long: `Open Istio's Zipkin dashboard`,
Example: ` istioctl dashboard zipkin
# with short syntax
istioctl dash zipkin
istioctl d zipkin`,
RunE: func(cmd *cobra.Command, args []string) error {
client, err := ctx.CLIClientWithRevision(opts.Revision)
if err != nil {
return fmt.Errorf("failed to create k8s client: %v", err)
}
name, namespace, err := inferPodMeta(ctx, client, "app=zipkin")
if err != nil {
return err
}
return portForward(name, namespace, "Zipkin",
"http://%s", bindAddress, zipkinPort, client, cmd.OutOrStdout(), browser)
},
}
return cmd
}
type CreateProxyDashCmdConfig struct {
CommandUsage string
CommandShort string
CommandLong string
CommandExample string
}
func createDashCmd(ctx cli.Context, config CreateProxyDashCmdConfig) *cobra.Command {
cmd := &cobra.Command{
Use: config.CommandUsage,
Short: config.CommandShort,
Long: config.CommandLong,
Example: config.CommandExample,
RunE: func(c *cobra.Command, args []string) error {
kubeClient, err := ctx.CLIClient()
if err != nil {
return fmt.Errorf("failed to create k8s client: %v", err)
}
if labelSelector == "" && len(args) < 1 {
c.Println(c.UsageString())
return fmt.Errorf("specify a pod or --selector")
}
if labelSelector != "" && len(args) > 0 {
c.Println(c.UsageString())
return fmt.Errorf("name cannot be provided when a selector is specified")
}
if err != nil {
return fmt.Errorf("failed to create k8s client: %v", err)
}
var podName, ns string
if labelSelector != "" {
pl, err := kubeClient.PodsForSelector(context.TODO(), ctx.NamespaceOrDefault(ctx.Namespace()), labelSelector)
if err != nil {
return fmt.Errorf("not able to locate pod with selector %s: %v", labelSelector, err)
}
if len(pl.Items) < 1 {
return errors.New("no pods found")
}
if len(pl.Items) > 1 {
log.Warnf("more than 1 pods fits selector: %s; will use pod: %s", labelSelector, pl.Items[0].Name)
}
// only use the first pod in the list
podName = pl.Items[0].Name
ns = pl.Items[0].Namespace
} else {
podName, ns, err = ctx.InferPodInfoFromTypedResource(args[0], ctx.NamespaceOrDefault(ctx.Namespace()))
if err != nil {
return err
}
}
return portForward(podName, ns, fmt.Sprintf("Envoy sidecar %s", podName),
"http://%s", bindAddress, proxyAdminPort, kubeClient, c.OutOrStdout(), browser)
},
}
return cmd
}
// port-forward to sidecar Envoy admin port; open browser
func envoyDashCmd(ctx cli.Context) *cobra.Command {
return createDashCmd(ctx, CreateProxyDashCmdConfig{
CommandUsage: "envoy [<type>/]<name>[.<namespace>]",
CommandShort: "Open Envoy admin web UI",
CommandLong: `Open the Envoy admin dashboard for a sidecar`,
CommandExample: ` # Open Envoy dashboard for the productpage-123-456.default pod
istioctl dashboard envoy productpage-123-456.default
# Open Envoy dashboard for one pod under a deployment
istioctl dashboard envoy deployment/productpage-v1
# with short syntax
istioctl dash envoy productpage-123-456.default
istioctl d envoy productpage-123-456.default
`,
})
}
func proxyDashCmd(ctx cli.Context) *cobra.Command {
return createDashCmd(ctx, CreateProxyDashCmdConfig{
CommandUsage: "proxy [<type>/]<name>[.<namespace>]",
CommandShort: "Open admin web UI for a proxy",
CommandLong: `Open the admin dashboard for a proxy, like envoy and ztunnel pods`,
CommandExample: ` # Open envoy admin dashboard for the productpage-123-456.default pod
istioctl dashboard proxy productpage-123-456.default
# Open envoy admin dashboard for one pod under a deployment
istioctl dashboard proxy deployment/productpage-v1
# Open dashboard for the ztunnel-bwh89.istio-system pod
istioctl dashboard proxy ztunnel-bwh89.istio-system
# Open dashboard for a waypoint pod
istioctl dashboard proxy namespace-istio-waypoint-869b56b69c-7khz4
# with short syntax
istioctl dash proxy ztunnel-bwh89.istio-system
istioctl d proxy ztunnel-bwh89.istio-system
`,
})
}
// port-forward to sidecar ControlZ port; open browser
func controlZDashCmd(ctx cli.Context) *cobra.Command {
var opts clioptions.ControlPlaneOptions
cmd := &cobra.Command{
Use: "controlz [<type>/]<name>[.<namespace>]",
Short: "Open ControlZ web UI",
Long: `Open the ControlZ web UI for a pod in the Istio control plane`,
Example: ` # Open ControlZ web UI for the istiod-123-456.istio-system pod
istioctl dashboard controlz istiod-123-456.istio-system
# Open ControlZ web UI for the istiod-56dd66799-jfdvs pod in a custom namespace
istioctl dashboard controlz istiod-123-456 -n custom-ns
# Open ControlZ web UI for any Istiod pod
istioctl dashboard controlz deployment/istiod.istio-system
# with short syntax
istioctl dash controlz pilot-123-456.istio-system
istioctl d controlz pilot-123-456.istio-system
`,
RunE: func(c *cobra.Command, args []string) error {
if labelSelector == "" && len(args) < 1 {
c.Println(c.UsageString())
return fmt.Errorf("specify a pod or --selector")
}
if labelSelector != "" && len(args) > 0 {
c.Println(c.UsageString())
return fmt.Errorf("name cannot be provided when a selector is specified")
}
client, err := ctx.CLIClientWithRevision(opts.Revision)
if err != nil {
return fmt.Errorf("failed to create k8s client: %v", err)
}
var podName, ns string
if labelSelector != "" {
pl, err := client.PodsForSelector(context.TODO(), ctx.NamespaceOrDefault(ctx.IstioNamespace()), labelSelector)
if err != nil {
return fmt.Errorf("not able to locate pod with selector %s: %v", labelSelector, err)
}
if len(pl.Items) < 1 {
return errors.New("no pods found")
}
if len(pl.Items) > 1 {
log.Warnf("more than 1 pods fits selector: %s; will use pod: %s", labelSelector, pl.Items[0].Name)
}
// only use the first pod in the list
podName = pl.Items[0].Name
ns = pl.Items[0].Namespace
} else {
podName, ns, err = ctx.InferPodInfoFromTypedResource(args[0], ctx.IstioNamespace())
if err != nil {
return err
}
}
return portForward(podName, ns, fmt.Sprintf("ControlZ %s", podName),
"http://%s", bindAddress, controlZport, client, c.OutOrStdout(), browser)
},
}
return cmd
}
// istioDebugDashCmd port-forwards to istio monitoring port; open browser to the debug page
func istioDebugDashCmd(ctx cli.Context) *cobra.Command {
var opts clioptions.ControlPlaneOptions
cmd := &cobra.Command{
Use: "istiod-debug [<type>/]<name>[.<namespace>]",
Short: "Open Istio debug web UI",
Long: `Open the debug web UI for a Istio control plane pod`,
Example: ` # Open Istio debug web UI for the istiod-123-456.istio-system pod
istioctl dashboard istiod-debug istiod-123-456.istio-system
# Open Istio debug web UI for the istiod-56dd66799-jfdvs pod in a custom namespace
istioctl dashboard istiod-debug istiod-123-456 -n custom-ns
# Open Istio debug web UI for any Istiod pod
istioctl dashboard istiod-debug deployment/istiod.istio-system
# with short syntax
istioctl dash istiod-debug pilot-123-456.istio-system
istioctl d istiod-debug pilot-123-456.istio-system
`,
RunE: func(c *cobra.Command, args []string) error {
if labelSelector == "" && len(args) < 1 {
c.Println(c.UsageString())
return fmt.Errorf("specify a pod or --selector")
}
if labelSelector != "" && len(args) > 0 {
c.Println(c.UsageString())
return fmt.Errorf("name cannot be provided when a selector is specified")
}
client, err := ctx.CLIClientWithRevision(opts.Revision)
if err != nil {
return fmt.Errorf("failed to create k8s client: %v", err)
}
var podName, ns string
if labelSelector != "" {
pl, err := client.PodsForSelector(context.TODO(), ctx.NamespaceOrDefault(ctx.IstioNamespace()), labelSelector)
if err != nil {
return fmt.Errorf("not able to locate pod with selector %s: %v", labelSelector, err)
}
if len(pl.Items) < 1 {
return errors.New("no pods found")
}
if len(pl.Items) > 1 {
log.Warnf("more than 1 pods fits selector: %s; will use pod: %s", labelSelector, pl.Items[0].Name)
}
// only use the first pod in the list
podName = pl.Items[0].Name
ns = pl.Items[0].Namespace
} else {
podName, ns, err = ctx.InferPodInfoFromTypedResource(args[0], ctx.IstioNamespace())
if err != nil {
return err
}
}
port := inferMonitoringPort(client, podName, ns)
return portForward(podName, ns, fmt.Sprintf("Istio debug %s", podName),
"http://%s/debug", bindAddress, port, client, c.OutOrStdout(), browser)
},
}
return cmd
}
func inferMonitoringPort(client kube.Client, name, ns string) int {
port := 15014
pod, err := client.Kube().CoreV1().Pods(ns).Get(context.Background(), name, metav1.GetOptions{})
if err != nil {
return port
}
return kube.FindIstiodMonitoringPort(pod)
}
// port-forward to SkyWalking UI on istio-system
func skywalkingDashCmd(ctx cli.Context) *cobra.Command {
var opts clioptions.ControlPlaneOptions
cmd := &cobra.Command{
Use: "skywalking",
Short: "Open SkyWalking UI",
Long: "Open the Istio dashboard in the SkyWalking UI",
Example: ` istioctl dashboard skywalking
# with short syntax
istioctl dash skywalking
istioctl d skywalking`,
RunE: func(cmd *cobra.Command, args []string) error {
client, err := ctx.CLIClientWithRevision(opts.Revision)
if err != nil {
return fmt.Errorf("failed to create k8s client: %v", err)
}
name, namespace, err := inferPodMeta(ctx, client, "app=skywalking-ui")
if err != nil {
return err
}
return portForward(name, namespace, "SkyWalking",
"http://%s", bindAddress, skywalkingPort, client, cmd.OutOrStdout(), browser)
},
}
return cmd
}
// portForward first tries to forward localhost:remotePort to podName:remotePort, falls back to dynamic local port
func portForward(podName, namespace, flavor, urlFormat, localAddress string, remotePort int,
client kube.CLIClient, writer io.Writer, browser bool,
) error {
// port preference:
// - If --listenPort is specified, use it
// - without --listenPort, prefer the remotePort but fall back to a random port
var portPrefs []int
if listenPort != 0 {
portPrefs = []int{listenPort}
} else {
portPrefs = []int{remotePort, 0}
}
var err error
for _, localPort := range portPrefs {
var fw kube.PortForwarder
fw, err = client.NewPortForwarder(podName, namespace, localAddress, localPort, remotePort)
if err != nil {
return fmt.Errorf("could not build port forwarder for %s: %v", flavor, err)
}
if err = fw.Start(); err != nil {
fw.Close()
// Try the next port
continue
}
// Close the port forwarder when the command is terminated.
ClosePortForwarderOnInterrupt(fw)
log.Debugf(fmt.Sprintf("port-forward to %s pod ready", flavor))
openBrowser(fmt.Sprintf(urlFormat, fw.Address()), writer, browser)
// Wait for stop
fw.WaitForStop()
return nil
}
return fmt.Errorf("failure running port forward process: %v", err)
}
func ClosePortForwarderOnInterrupt(fw kube.PortForwarder) {
go func() {
signals := make(chan os.Signal, 1)
signal.Notify(signals, os.Interrupt)
defer signal.Stop(signals)
<-signals
fw.Close()
}()
}
func openBrowser(url string, writer io.Writer, browser bool) {
var err error
fmt.Fprintf(writer, "%s\n", url)
if !browser {
fmt.Fprint(writer, "skipping opening a browser")
return
}
switch runtime.GOOS {
case "linux":
err = exec.Command("xdg-open", url).Start()
case "windows":
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
case "darwin":
err = exec.Command("open", url).Start()
default:
fmt.Fprintf(writer, "Unsupported platform %q; open %s in your browser.\n", runtime.GOOS, url)
}
if err != nil {
fmt.Fprintf(writer, "Failed to open browser; open %s in your browser.\n", url)
}
}
func Dashboard(cliContext cli.Context) *cobra.Command {
dashboardCmd := &cobra.Command{
Use: "dashboard",
Aliases: []string{"dash", "d"},
Short: "Access to Istio web UIs",
Args: func(cmd *cobra.Command, args []string) error {
if len(args) != 0 {
return fmt.Errorf("unknown dashboard %q", args[0])
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
cmd.HelpFunc()(cmd, args)
return nil
},
}
dashboardCmd.PersistentFlags().IntVarP(&listenPort, "port", "p", 0, "Local port to listen to")
dashboardCmd.PersistentFlags().StringVar(&bindAddress, "address", "localhost",
"Address to listen on. Only accepts IP address or localhost as a value. "+
"When localhost is supplied, istioctl will try to bind on both 127.0.0.1 and ::1 "+
"and will fail if neither of these address are available to bind.")
dashboardCmd.PersistentFlags().BoolVar(&browser, "browser", true,
"When --browser is supplied as false, istioctl dashboard will not open the browser. "+
"Default is true which means istioctl dashboard will always open a browser to view the dashboard.")
kiali := kialiDashCmd(cliContext)
kiali.PersistentFlags().IntVar(&kialiPort, "ui-port", defaultKialiPort, "The component dashboard UI port.")
dashboardCmd.AddCommand(kiali)
prom := promDashCmd(cliContext)
prom.PersistentFlags().IntVar(&promPort, "ui-port", defaultPrometheusPort, "The component dashboard UI port.")
dashboardCmd.AddCommand(prom)
graf := grafanaDashCmd(cliContext)
graf.PersistentFlags().IntVar(&grafanaPort, "ui-port", defaultGrafanaPort, "The component dashboard UI port.")
dashboardCmd.AddCommand(graf)
jaeger := jaegerDashCmd(cliContext)
jaeger.PersistentFlags().IntVar(&jaegerPort, "ui-port", defaultJaegerPort, "The component dashboard UI port.")
dashboardCmd.AddCommand(jaeger)
zipkin := zipkinDashCmd(cliContext)
zipkin.PersistentFlags().IntVar(&zipkinPort, "ui-port", defaultZipkinPort, "The component dashboard UI port.")
dashboardCmd.AddCommand(zipkin)
skywalking := skywalkingDashCmd(cliContext)
skywalking.PersistentFlags().IntVar(&skywalkingPort, "ui-port", defaultSkywalkingPort, "The component dashboard UI port.")
dashboardCmd.AddCommand(skywalking)
envoy := envoyDashCmd(cliContext)
envoy.Long += fmt.Sprintf("\n\n%s\n", "Note: envoy command is deprecated and can be replaced with proxy command, "+
"e.g. `istioctl dashboard proxy --help`")
envoy.PersistentFlags().StringVarP(&labelSelector, "selector", "l", "", "Label selector")
envoy.PersistentFlags().IntVar(&proxyAdminPort, "ui-port", util.DefaultProxyAdminPort, "The component dashboard UI port.")
dashboardCmd.AddCommand(envoy)
proxy := proxyDashCmd(cliContext)
proxy.PersistentFlags().StringVarP(&labelSelector, "selector", "l", "", "Label selector")
proxy.PersistentFlags().IntVar(&proxyAdminPort, "ui-port", util.DefaultProxyAdminPort, "The component dashboard UI port.")
dashboardCmd.AddCommand(proxy)
controlz := controlZDashCmd(cliContext)
controlz.PersistentFlags().IntVar(&controlZport, "ctrlz_port", 9876, "ControlZ port")
controlz.PersistentFlags().StringVarP(&labelSelector, "selector", "l", "", "Label selector")
dashboardCmd.AddCommand(controlz)
istioDebug := istioDebugDashCmd(cliContext)
istioDebug.PersistentFlags().StringVarP(&labelSelector, "selector", "l", "", "Label selector")
dashboardCmd.AddCommand(istioDebug)
return dashboardCmd
}
func inferPodMeta(ctx cli.Context, client kube.CLIClient, labelSelector string) (name, namespace string, err error) {
for _, ns := range []string{ctx.IstioNamespace(), ctx.NamespaceOrDefault(ctx.Namespace())} {
pl, err := client.PodsForSelector(context.TODO(), ns, labelSelector)
if err != nil {
continue
}
if len(pl.Items) > 0 {
return pl.Items[0].Name, pl.Items[0].Namespace, nil
}
}
return "", "", fmt.Errorf("no pods found with selector %s", labelSelector)
}