Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/25716.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
cli: Respect NOMAD_REGION environment variable in operator debug command
```
18 changes: 16 additions & 2 deletions command/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ type Meta struct {
// Whether to force colorized output
forceColor bool

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

// namespace to send API requests
// The value of the -namespace CLI flag to send with API requests
// note: does not reflect any environment variables
namespace string

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

// Namespace returns the Nomad namespace used for API calls,
// from either the -namespace flag, or the NOMAD_NAMESPACE env var.
func (m *Meta) Namespace() string {
return m.clientConfig().Namespace
}

// Region returns the Nomad region used for API calls,
// from either the -region flag, or the NOMAD_REGION env var.
func (m *Meta) Region() string {
return m.clientConfig().Region
}

func (m *Meta) allNamespaces() bool {
return m.clientConfig().Namespace == api.AllNamespacesNamespace
}
Expand Down
7 changes: 3 additions & 4 deletions command/operator_debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,6 @@ func (c *OperatorDebugCommand) Run(args []string) int {
}

c.opts = &api.QueryOptions{
Region: c.Meta.region,
AllowStale: allowStale,
AuthToken: c.Meta.token,
}
Expand Down Expand Up @@ -612,7 +611,7 @@ func (c *OperatorDebugCommand) Run(args []string) int {
}

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