Skip to content

Commit c86d63d

Browse files
committed
cli: operator debug: region and namespace env vars
NOMAD_REGION and NOMAD_NAMESPACE were being ignored
1 parent b116190 commit c86d63d

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

.changelog/25716.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
cli: respect NOMAD_REGION and NOMAD_NAMESPACE in operator debug command
3+
```

command/meta.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ type Meta struct {
5151
// Whether to force colorized output
5252
forceColor bool
5353

54-
// The region to send API requests
54+
// The value of the -region CLI flag to send with API requests
55+
// note: does not reflect any environment variables
5556
region string
5657

57-
// namespace to send API requests
58+
// The value of the -namespace CLI flag to send with API requests
59+
// note: does not reflect any environment variables
5860
namespace string
5961

6062
// token is used for ACLs to access privileged information
@@ -203,6 +205,18 @@ func (m *Meta) Client() (*api.Client, error) {
203205
return api.NewClient(m.clientConfig())
204206
}
205207

208+
// Namespace returns the Nomad namespace used for API calls,
209+
// from either the -namespace flag, or the NOMAD_NAMESPACE env var.
210+
func (m *Meta) Namespace() string {
211+
return m.clientConfig().Namespace
212+
}
213+
214+
// Region returns the Nomad region used for API calls,
215+
// from either the -region flag, or the NOMAD_REGION env var.
216+
func (m *Meta) Region() string {
217+
return m.clientConfig().Region
218+
}
219+
206220
func (m *Meta) allNamespaces() bool {
207221
return m.clientConfig().Namespace == api.AllNamespacesNamespace
208222
}

command/operator_debug.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ func (c *OperatorDebugCommand) Run(args []string) int {
512512
}
513513

514514
c.opts = &api.QueryOptions{
515-
Region: c.Meta.region,
515+
Region: c.Meta.Region(),
516516
AllowStale: allowStale,
517517
AuthToken: c.Meta.token,
518518
}
@@ -612,7 +612,7 @@ func (c *OperatorDebugCommand) Run(args []string) int {
612612
}
613613

614614
// Filter for servers matching criteria
615-
c.serverIDs, err = filterServerMembers(c.members, serverIDs, c.region)
615+
c.serverIDs, err = filterServerMembers(c.members, serverIDs, c.Meta.Region())
616616
if err != nil {
617617
c.Ui.Error(fmt.Sprintf("Failed to parse server list; err: %v", err))
618618
return 1
@@ -638,8 +638,8 @@ func (c *OperatorDebugCommand) Run(args []string) int {
638638
c.Ui.Output("Starting debugger...")
639639
c.Ui.Output("")
640640
c.Ui.Output(fmt.Sprintf("Nomad CLI Version: %s", version.GetVersion().FullVersionNumber(true)))
641-
c.Ui.Output(fmt.Sprintf(" Region: %s", c.region))
642-
c.Ui.Output(fmt.Sprintf(" Namespace: %s", c.namespace))
641+
c.Ui.Output(fmt.Sprintf(" Region: %s", c.Meta.Region()))
642+
c.Ui.Output(fmt.Sprintf(" Namespace: %s", c.Meta.Namespace()))
643643
c.Ui.Output(fmt.Sprintf(" Servers: (%d/%d) %v", serverCaptureCount, serversFound, c.serverIDs))
644644
c.Ui.Output(fmt.Sprintf(" Clients: (%d/%d) %v", nodeCaptureCount, nodesFound, c.nodeIDs))
645645
if nodeCaptureCount > 0 && nodeCaptureCount == c.maxNodes {

0 commit comments

Comments
 (0)