From 17d191ae248f051bfed41ce4d351df90a9ed60b4 Mon Sep 17 00:00:00 2001 From: Allison Larson Date: Mon, 31 Mar 2025 14:17:45 -0700 Subject: [PATCH] Add -group flag to `alloc exec`, `alloc logs` command (#25568) * Add -group flag to `alloc exec`, `alloc logs` command * fixup! Add -group flag to `alloc exec`, `alloc logs` command * Add -group option to alloc fs * Add changelog --- .changelog/25568.txt | 3 +++ command/alloc_exec.go | 9 +++++++-- command/alloc_fs.go | 8 +++++++- command/alloc_logs.go | 9 +++++++-- website/content/docs/commands/alloc/exec.mdx | 9 ++++++--- website/content/docs/commands/alloc/fs.mdx | 7 +++++-- website/content/docs/commands/alloc/logs.mdx | 9 ++++++--- 7 files changed, 41 insertions(+), 13 deletions(-) create mode 100644 .changelog/25568.txt diff --git a/.changelog/25568.txt b/.changelog/25568.txt new file mode 100644 index 000000000..558480734 --- /dev/null +++ b/.changelog/25568.txt @@ -0,0 +1,3 @@ +```release-note:improvement +cli: Add -group option to `alloc exec`, `alloc logs`, `alloc fs` commands +``` diff --git a/command/alloc_exec.go b/command/alloc_exec.go index af53b3bfa..6802fa718 100644 --- a/command/alloc_exec.go +++ b/command/alloc_exec.go @@ -53,6 +53,9 @@ Exec Specific Options: -job Use a random allocation from the specified job ID or prefix. + -group + Specifies the task group with the task when a random allocation is selected. + -i Pass stdin to the container, defaults to true. Pass -i=false to disable. @@ -78,6 +81,7 @@ func (l *AllocExecCommand) AutocompleteFlags() complete.Flags { complete.Flags{ "--task": complete.PredictAnything, "-job": complete.PredictAnything, + "-group": complete.PredictAnything, "-i": complete.PredictNothing, "-t": complete.PredictNothing, "-e": complete.PredictSet("none", "~"), @@ -103,7 +107,7 @@ func (l *AllocExecCommand) Name() string { return "alloc exec" } func (l *AllocExecCommand) Run(args []string) int { var job, stdinOpt, ttyOpt bool - var task, escapeChar string + var task, group, escapeChar string flags := l.Meta.FlagSet(l.Name(), FlagSetClient) flags.Usage = func() { l.Ui.Output(l.Help()) } @@ -112,6 +116,7 @@ func (l *AllocExecCommand) Run(args []string) int { flags.BoolVar(&ttyOpt, "t", isTty(), "") flags.StringVar(&escapeChar, "e", "~", "") flags.StringVar(&task, "task", "", "") + flags.StringVar(&group, "group", "", "") if err := flags.Parse(args); err != nil { return 1 @@ -168,7 +173,7 @@ func (l *AllocExecCommand) Run(args []string) int { return 1 } - allocStub, err = getRandomJobAlloc(client, jobID, "", ns) + allocStub, err = getRandomJobAlloc(client, jobID, group, ns) if err != nil { l.Ui.Error(fmt.Sprintf("Error fetching allocations: %v", err)) return 1 diff --git a/command/alloc_fs.go b/command/alloc_fs.go index 60d99e1da..8d01bd2e8 100644 --- a/command/alloc_fs.go +++ b/command/alloc_fs.go @@ -61,6 +61,9 @@ FS Specific Options: -job Use a random allocation from the specified job ID or prefix. + -group + Specifies the task group with the task when a random allocation is selected. + -stat Show file stat information instead of displaying the file, or listing the directory. @@ -92,6 +95,7 @@ func (f *AllocFSCommand) AutocompleteFlags() complete.Flags { "-H": complete.PredictNothing, "-verbose": complete.PredictNothing, "-job": complete.PredictAnything, + "-group": complete.PredictAnything, "-stat": complete.PredictNothing, "-f": complete.PredictNothing, "-tail": complete.PredictNothing, @@ -120,12 +124,14 @@ func (f *AllocFSCommand) Name() string { return "alloc fs" } func (f *AllocFSCommand) Run(args []string) int { var verbose, machine, job, stat, tail, follow bool var numLines, numBytes int64 + var group string flags := f.Meta.FlagSet(f.Name(), FlagSetClient) flags.Usage = func() { f.Ui.Output(f.Help()) } flags.BoolVar(&verbose, "verbose", false, "") flags.BoolVar(&machine, "H", false, "") flags.BoolVar(&job, "job", false, "") + flags.StringVar(&group, "group", "", "") flags.BoolVar(&stat, "stat", false, "") flags.BoolVar(&follow, "f", false, "") flags.BoolVar(&tail, "tail", false, "") @@ -173,7 +179,7 @@ func (f *AllocFSCommand) Run(args []string) int { return 1 } - allocID, err = getRandomJobAllocID(client, jobID, "", ns) + allocID, err = getRandomJobAllocID(client, jobID, group, ns) if err != nil { f.Ui.Error(fmt.Sprintf("Error fetching allocations: %v", err)) return 1 diff --git a/command/alloc_logs.go b/command/alloc_logs.go index 3d9c2fc69..7720e87c5 100644 --- a/command/alloc_logs.go +++ b/command/alloc_logs.go @@ -26,7 +26,7 @@ type AllocLogsCommand struct { verbose, job, tail, stderr, stdout, follow bool numLines int64 numBytes int64 - task string + task, group string } func (l *AllocLogsCommand) Help() string { @@ -60,6 +60,9 @@ Logs Specific Options: Sets the task to view the logs. If task name is given with both an argument and the '-task' option, preference is given to the '-task' option. + -group + Specifies the task group with the task when a random allocation is selected. + -job Use a random allocation from the specified job ID or prefix. @@ -100,6 +103,7 @@ func (l *AllocLogsCommand) AutocompleteFlags() complete.Flags { "-verbose": complete.PredictNothing, "-task": complete.PredictAnything, "-job": complete.PredictAnything, + "-group": complete.PredictAnything, "-f": complete.PredictNothing, "-tail": complete.PredictAnything, "-n": complete.PredictAnything, @@ -137,6 +141,7 @@ func (l *AllocLogsCommand) Run(args []string) int { flags.Int64Var(&l.numLines, "n", -1, "") flags.Int64Var(&l.numBytes, "c", -1, "") flags.StringVar(&l.task, "task", "", "") + flags.StringVar(&l.group, "group", "", "") if err := flags.Parse(args); err != nil { return 1 @@ -173,7 +178,7 @@ func (l *AllocLogsCommand) Run(args []string) int { return 1 } - allocID, err = getRandomJobAllocID(client, jobID, "", ns) + allocID, err = getRandomJobAllocID(client, jobID, l.group, ns) if err != nil { l.Ui.Error(fmt.Sprintf("Error fetching allocations: %v", err)) return 1 diff --git a/website/content/docs/commands/alloc/exec.mdx b/website/content/docs/commands/alloc/exec.mdx index 2e3d502ab..3e04d27a0 100644 --- a/website/content/docs/commands/alloc/exec.mdx +++ b/website/content/docs/commands/alloc/exec.mdx @@ -39,10 +39,13 @@ capabilities for the allocation's namespace. ## Exec options -- `-task`: Sets the task to exec command in. +- `-task=`: Sets the task to exec command in. -- `-job`: Use a random allocation from the specified job or job ID prefix, - preferring a running allocation. +- `-job=`: Use a random allocation from the specified job or + job ID prefix, preferring a running allocation. + +- `-group=`: Specifies the task group where the task is located + when a random allocation is selected - `-i`: Pass stdin to the container, defaults to true. Pass `-i=false` to disable explicitly. diff --git a/website/content/docs/commands/alloc/fs.mdx b/website/content/docs/commands/alloc/fs.mdx index c5e39f98f..f44f774a2 100644 --- a/website/content/docs/commands/alloc/fs.mdx +++ b/website/content/docs/commands/alloc/fs.mdx @@ -48,8 +48,11 @@ When ACLs are enabled, this command requires a token with the `read-fs`, - `-verbose`: Display verbose output. -- `-job`: Use a random allocation from the specified job or job ID prefix, - preferring a running allocation. +- `-job=`: Use a random allocation from the specified job or + job ID prefix, preferring a running allocation. + +- `-group=`: Specifies the task group where the task is located + when a random allocation is selected - `-stat`: Show stat information instead of displaying the file, or listing the directory. diff --git a/website/content/docs/commands/alloc/logs.mdx b/website/content/docs/commands/alloc/logs.mdx index 588380196..5ed0b4be3 100644 --- a/website/content/docs/commands/alloc/logs.mdx +++ b/website/content/docs/commands/alloc/logs.mdx @@ -43,10 +43,13 @@ When ACLs are enabled, this command requires a token with the `read-logs`, - `-verbose`: Display verbose output. -- `-job`: Use a random allocation from the specified job or job ID prefix, - preferring a running allocation. +- `-job=`: Use a random allocation from the specified job or + job ID prefix, preferring a running allocation. -- `-task`: Specify the task to view the logs. +- `-task=`: Specify the task to view the logs. + +- `-group=`: Specifies the task group where the task is located + when a random allocation is selected - `-f`: Causes the output to not stop when the end of the logs are reached, but rather to wait for additional output. When supplied with no other flags except