diff --git a/.changelog/25716.txt b/.changelog/25716.txt new file mode 100644 index 00000000000..d6b8102ebe2 --- /dev/null +++ b/.changelog/25716.txt @@ -0,0 +1,3 @@ +```release-note:bug +cli: Respect NOMAD_REGION environment variable in operator debug command +``` diff --git a/command/meta.go b/command/meta.go index f1eb47148d4..a8368174a4b 100644 --- a/command/meta.go +++ b/command/meta.go @@ -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 @@ -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 } diff --git a/command/operator_debug.go b/command/operator_debug.go index e4ef4af0520..06f96c4ed93 100644 --- a/command/operator_debug.go +++ b/command/operator_debug.go @@ -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, } @@ -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 @@ -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 {