@@ -91,7 +91,7 @@ func certificatesConfigCmd(ctx cli.Context) *cobra.Command {
91
91
` ,
92
92
Aliases : []string {"certificates" , "certs" , "cert" },
93
93
Args : common .validateArgs ,
94
- RunE : runConfigDump (ctx , common , func (cw * ztunnelDump.ConfigWriter ) error {
94
+ RunE : runConfigDump (ctx , common , true , func (cw * ztunnelDump.ConfigWriter ) error {
95
95
switch common .outputFormat {
96
96
case summaryOutput :
97
97
return cw .PrintSecretSummary ()
@@ -124,7 +124,7 @@ func servicesCmd(ctx cli.Context) *cobra.Command {
124
124
` ,
125
125
Aliases : []string {"services" , "s" , "svc" },
126
126
Args : common .validateArgs ,
127
- RunE : runConfigDump (ctx , common , func (cw * ztunnelDump.ConfigWriter ) error {
127
+ RunE : runConfigDump (ctx , common , false , func (cw * ztunnelDump.ConfigWriter ) error {
128
128
filter := ztunnelDump.ServiceFilter {
129
129
Namespace : serviceNamespace ,
130
130
}
@@ -162,7 +162,7 @@ func policiesCmd(ctx cli.Context) *cobra.Command {
162
162
` ,
163
163
Aliases : []string {"policies" , "p" , "pol" },
164
164
Args : common .validateArgs ,
165
- RunE : runConfigDump (ctx , common , func (cw * ztunnelDump.ConfigWriter ) error {
165
+ RunE : runConfigDump (ctx , common , false , func (cw * ztunnelDump.ConfigWriter ) error {
166
166
filter := ztunnelDump.PolicyFilter {
167
167
Namespace : policyNamespace ,
168
168
}
@@ -198,7 +198,7 @@ func allCmd(ctx cli.Context) *cobra.Command {
198
198
istioctl ztunnel-config all <ztunnel-name[.namespace]> -o json
199
199
` ,
200
200
Args : common .validateArgs ,
201
- RunE : runConfigDump (ctx , common , func (cw * ztunnelDump.ConfigWriter ) error {
201
+ RunE : runConfigDump (ctx , common , false , func (cw * ztunnelDump.ConfigWriter ) error {
202
202
switch common .outputFormat {
203
203
case summaryOutput :
204
204
return cw .PrintFullSummary ()
@@ -245,7 +245,7 @@ func workloadConfigCmd(ctx cli.Context) *cobra.Command {
245
245
` ,
246
246
Aliases : []string {"w" , "workloads" },
247
247
Args : common .validateArgs ,
248
- RunE : runConfigDump (ctx , common , func (cw * ztunnelDump.ConfigWriter ) error {
248
+ RunE : runConfigDump (ctx , common , false , func (cw * ztunnelDump.ConfigWriter ) error {
249
249
filter := ztunnelDump.WorkloadFilter {
250
250
Namespace : workloadsNamespace ,
251
251
Address : address ,
@@ -280,10 +280,9 @@ func connectionsCmd(ctx cli.Context) *cobra.Command {
280
280
281
281
common := new (commonFlags )
282
282
cmd := & cobra.Command {
283
- Use : "connections [<type>/]<name>[.<namespace>]" ,
284
- Hidden : true ,
285
- Short : "Retrieves connections for the specified Ztunnel pod." ,
286
- Long : `Retrieve information about connections for the Ztunnel instance.` ,
283
+ Use : "connections [<type>/]<name>[.<namespace>]" ,
284
+ Short : "Retrieves connections for the specified Ztunnel pod." ,
285
+ Long : `Retrieve information about connections for the Ztunnel instance.` ,
287
286
Example : ` # Retrieve summary about connections for the ztunnel on a specific node.
288
287
istioctl ztunnel-config connections --node ambient-worker
289
288
@@ -292,7 +291,7 @@ func connectionsCmd(ctx cli.Context) *cobra.Command {
292
291
` ,
293
292
Aliases : []string {"cons" },
294
293
Args : common .validateArgs ,
295
- RunE : runConfigDump (ctx , common , func (cw * ztunnelDump.ConfigWriter ) error {
294
+ RunE : runConfigDump (ctx , common , true , func (cw * ztunnelDump.ConfigWriter ) error {
296
295
filter := ztunnelDump.ConnectionsFilter {
297
296
Namespace : workloadsNamespace ,
298
297
Direction : direction ,
@@ -421,7 +420,7 @@ func logCmd(ctx cli.Context) *cobra.Command {
421
420
var podNames []string
422
421
var podNamespace string
423
422
if len (args ) == 1 {
424
- podName , ns , err := getComponentPodName (ctx , args [0 ])
423
+ podName , ns , err := getComponentPodName (ctx , args [0 ], false )
425
424
if err != nil {
426
425
return err
427
426
}
@@ -522,13 +521,22 @@ func setupZtunnelLogs(kubeClient kube.CLIClient, param, podName, podNamespace st
522
521
}
523
522
524
523
// getComponentPodName returns the pod name and namespace of the Istio component
525
- func getComponentPodName (ctx cli.Context , podflag string ) (string , string , error ) {
524
+ func getComponentPodName (ctx cli.Context , podflag string , enforceSinglePod bool ) (string , string , error ) {
526
525
// If user passed --namespace, respect it. Else fallback to --istio-namespace (which is typically defaulted, to istio-system).
527
- return getPodNameWithNamespace (ctx , podflag , model .GetOrDefault (ctx .Namespace (), ctx .IstioNamespace ()))
526
+ return getPodNameWithNamespace (ctx , podflag , enforceSinglePod , model .GetOrDefault (ctx .Namespace (), ctx .IstioNamespace ()))
528
527
}
529
528
530
- func getPodNameWithNamespace (ctx cli.Context , podflag , ns string ) (string , string , error ) {
531
- var podName , podNamespace string
529
+ func getPodNameWithNamespace (ctx cli.Context , podflag string , enforceSinglePod bool , ns string ) (string , string , error ) {
530
+ if enforceSinglePod {
531
+ pods , podNamespace , err := ctx .InferPodsFromTypedResource (podflag , ns )
532
+ if err != nil {
533
+ return "" , "" , err
534
+ }
535
+ if len (pods ) != 1 {
536
+ return "" , "" , fmt .Errorf ("ztunnel pod name or --node must be set" )
537
+ }
538
+ return pods [0 ], podNamespace , nil
539
+ }
532
540
podName , podNamespace , err := ctx .InferPodInfoFromTypedResource (podflag , ns )
533
541
if err != nil {
534
542
return "" , "" , err
@@ -587,7 +595,15 @@ func setupFileZtunnelConfigdumpWriter(filename string, out io.Writer) (*ztunnelD
587
595
return setupConfigdumpZtunnelConfigWriter (data , out )
588
596
}
589
597
590
- func runConfigDump (ctx cli.Context , common * commonFlags , f func (cw * ztunnelDump.ConfigWriter ) error ) func (c * cobra.Command , args []string ) error {
598
+ // runConfigDump runs a function that acts on a configdump.
599
+ // enforceSinglePod can be set for commands where we enforce a user to explicitly specify a pod. This should be 'true' when
600
+ // the content is specific to a single Ztunnel pod, but 'false' if it is the same across all pods.
601
+ func runConfigDump (
602
+ ctx cli.Context ,
603
+ common * commonFlags ,
604
+ enforceSinglePod bool ,
605
+ f func (cw * ztunnelDump.ConfigWriter ) error ,
606
+ ) func (c * cobra.Command , args []string ) error {
591
607
return func (c * cobra.Command , args []string ) error {
592
608
var podName , podNamespace string
593
609
kubeClient , err := ctx .CLIClient ()
@@ -601,6 +617,8 @@ func runConfigDump(ctx cli.Context, common *commonFlags, f func(cw *ztunnelDump.
601
617
lookup := "daemonset/ztunnel"
602
618
if len (args ) > 0 {
603
619
lookup = args [0 ]
620
+ // If they explicitly asked for an unreliable container, allow it
621
+ enforceSinglePod = false
604
622
}
605
623
if common .node != "" {
606
624
nsn , err := PodOnNodeFromDaemonset (common .node , "ztunnel" , ctx .IstioNamespace (), kubeClient )
@@ -609,7 +627,7 @@ func runConfigDump(ctx cli.Context, common *commonFlags, f func(cw *ztunnelDump.
609
627
}
610
628
podName , podNamespace = nsn .Name , nsn .Namespace
611
629
} else {
612
- if podName , podNamespace , err = getComponentPodName (ctx , lookup ); err != nil {
630
+ if podName , podNamespace , err = getComponentPodName (ctx , lookup , enforceSinglePod ); err != nil {
613
631
return err
614
632
}
615
633
}
0 commit comments