Skip to content

Commit

Permalink
General Armadactl cleanup (#147) (#3613)
Browse files Browse the repository at this point in the history
* Removing deprecated commands, making armadaUrl flag work as expected

* Converting armadactl flags to kebab-case

* Cleaning up CLI, cleaning up CLI docs, moving reporting commands, separating out reprioritize commands

* Moving resources to their own directory

* Removing capitalisation

* This is an empty commit in order to trigger PR check re-run

* This is an empty commit in order to trigger PR check re-run

* Modifying cancel, preempt to use verb-noun structure. Modified cancel jobSet to use correct Armada API endpoint.

* Making reprioritize command require queue and job-set

* Updating documentation

* Tidying go.mod file, linting

Co-authored-by: Mustafa Ilyas <Mustafa.Ilyas@gresearch.co.uk>
  • Loading branch information
MustafaI and mustafai-gr authored May 22, 2024
1 parent 7ac9527 commit e66d6d8
Show file tree
Hide file tree
Showing 30 changed files with 620 additions and 479 deletions.
4 changes: 2 additions & 2 deletions .devcontainer/demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Run this when the script completes
```bash
# If you are at the root of the repo
cd .devcontainer/demo
./armadactl create queue test --priorityFactor 1
./armadactl create queue test --priority-factor 1
./armadactl submit jobs.yaml
./armadactl watch test job-set-1
```
Expand All @@ -21,4 +21,4 @@ Forward these ports:
- 10000: Lookoutv2 API
- 8080: Armada Server API

and go to: http://localhost:8089
and go to: http://localhost:8089
74 changes: 0 additions & 74 deletions cmd/armadactl/README.md

This file was deleted.

26 changes: 0 additions & 26 deletions cmd/armadactl/cmd/analyze.go

This file was deleted.

52 changes: 38 additions & 14 deletions cmd/armadactl/cmd/cancel.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,54 @@ import (
)

func cancelCmd() *cobra.Command {
a := armadactl.New()
cmd := &cobra.Command{
Use: "cancel",
Short: "Cancels jobs in armada.",
Long: `Cancels jobs. If queue and jobset are provided then all jobs in that jobset will be cancelled. A job id may also be provided in which case only that job is cancelled`,
Long: `Cancels jobs individually using job ID or in bulk as part of a job set.`,
Args: cobra.ExactArgs(0),
}
cmd.AddCommand(
cancelJobCmd(),
cancelJobSetCmd(),
)
return cmd
}

func cancelJobCmd() *cobra.Command {
a := armadactl.New()
cmd := &cobra.Command{
Use: "job <queue> <job-set> <job-id>",
Short: "Cancels job in armada.",
Long: `Cancel job by providing queue, job-set and job-id.`,
Args: cobra.ExactArgs(3),
PreRunE: func(cmd *cobra.Command, args []string) error {
return initParams(cmd, a.Params)
},
RunE: func(cmd *cobra.Command, args []string) error {
jobId, _ := cmd.Flags().GetString("jobId")
queue, _ := cmd.Flags().GetString("queue")
jobSetId, _ := cmd.Flags().GetString("jobSet")
return a.Cancel(queue, jobSetId, jobId)
queue := args[0]
jobSetId := args[1]
jobId := args[2]
return a.CancelJob(queue, jobSetId, jobId)
},
}
cmd.Flags().String("jobId", "", "job to cancel (optional)")
cmd.Flags().String("queue", "", "queue to cancel jobs from")
cmd.Flags().String("jobSet", "", "jobSet to cancel")
if err := cmd.MarkFlagRequired("queue"); err != nil {
panic(err)
}
if err := cmd.MarkFlagRequired("jobSet"); err != nil {
panic(err)
return cmd
}

func cancelJobSetCmd() *cobra.Command {
a := armadactl.New()
cmd := &cobra.Command{
Use: "job-set <queue> <job-set>",
Short: "Cancels job-set in armada.",
Long: `Cancels job-set by providing queue, job-set.`,
Args: cobra.ExactArgs(2),
PreRunE: func(cmd *cobra.Command, args []string) error {
return initParams(cmd, a.Params)
},
RunE: func(cmd *cobra.Command, args []string) error {
queue := args[0]
jobSetId := args[1]
return a.CancelJobSet(queue, jobSetId)
},
}
return cmd
}
10 changes: 5 additions & 5 deletions cmd/armadactl/cmd/cancel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ func TestCancel(t *testing.T) {
jobSet string
}{
"default flags": {nil, "", "", ""},
"valid jobId": {[]flag{{"jobId", "jobId1"}}, "jobId1", "", ""},
"valid job-id": {[]flag{{"job-id", "jobId1"}}, "jobId1", "", ""},
"valid queue": {[]flag{{"queue", "queue1,jobSet1"}}, "", "queue1", "jobSet1"},
"valid jobSet": {[]flag{{"jobSet", "jobSet1"}}, "", "", "jobSet1"},
"valid job-set": {[]flag{{"job-set", "jobSet1"}}, "", "", "jobSet1"},
}
for name, test := range tests {
t.Run(name, func(t *testing.T) {
Expand All @@ -31,20 +31,20 @@ func TestCancel(t *testing.T) {
a.Out = io.Discard

if len(test.jobId) > 0 {
jobIdFlag, err1 := cmd.Flags().GetString("jobId")
jobIdFlag, err1 := cmd.Flags().GetString("job-id")
require.Error(t, err1)
require.Equal(t, test.jobId, jobIdFlag)
}
if len(test.queue) > 0 {
queueFlag, err1 := cmd.Flags().GetString("queue")
jobSetFlag, err2 := cmd.Flags().GetString("jobSet")
jobSetFlag, err2 := cmd.Flags().GetString("job-set")
require.Error(t, err1)
require.Error(t, err2)
require.Equal(t, test.queue, queueFlag)
require.Equal(t, test.jobSet, jobSetFlag)
}
if len(test.jobSet) > 0 {
jobSetFlag, err1 := cmd.Flags().GetString("jobSet")
jobSetFlag, err1 := cmd.Flags().GetString("job-set")
require.Error(t, err1)
require.Equal(t, test.jobSet, jobSetFlag)
}
Expand Down
20 changes: 15 additions & 5 deletions cmd/armadactl/cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
func createCmd(a *armadactl.App) *cobra.Command {
cmd := &cobra.Command{
Use: "create",
Short: "Create Armada resource. Supported: queue",
Short: "Create Armada resource",
Long: "Create Armada resource. Supported: queue",
PreRunE: func(cmd *cobra.Command, args []string) error {
return initParams(cmd, a.Params)
},
Expand All @@ -32,7 +33,8 @@ func createCmd(a *armadactl.App) *cobra.Command {
func deleteCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "delete",
Short: "Delete Armada resource. Supported: queue",
Short: "Delete Armada resource",
Long: "Delete Armada resource. Supported: queue",
}
cmd.AddCommand(queueDeleteCmd())
return cmd
Expand All @@ -41,7 +43,8 @@ func deleteCmd() *cobra.Command {
func updateCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "update",
Short: "Update Armada resource. Supported: queue",
Short: "Update Armada resource",
Long: "Update Armada resource. Supported: queue",
}
cmd.AddCommand(queueUpdateCmd())
return cmd
Expand All @@ -50,8 +53,15 @@ func updateCmd() *cobra.Command {
func getCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "get",
Short: "Retrieve information about armada resource. Supported: queue",
Short: "Retrieve information about armada resource",
Long: "Retrieve information about armada resource. Supported: queue, scheduling-report, queue-report, job-report",
}
cmd.AddCommand(queueGetCmd())
cmd.AddCommand(
queueGetCmd(),
getSchedulingReportCmd(armadactl.New()),
getQueueSchedulingReportCmd(armadactl.New()),
getJobSchedulingReportCmd(armadactl.New()),
)

return cmd
}
3 changes: 2 additions & 1 deletion cmd/armadactl/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import (
func configCmd(a *armadactl.App) *cobra.Command {
cmd := &cobra.Command{
Use: "config",
Short: "Operations on armadactl config. Supported: use-context, get-contexts, current-context",
Short: "Operations on armadactl config",
Long: "Operations on armadactl config. Supported: use-context, get-contexts, current-context",
}

cmd.AddCommand(getContextsCmd(a))
Expand Down
52 changes: 52 additions & 0 deletions cmd/armadactl/cmd/docs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package cmd

import (
"embed"
"fmt"
"io/fs"

"github.com/charmbracelet/glamour"
"github.com/spf13/cobra"
)

//go:embed resources/README.md
var ArmadactlReadMe embed.FS

//go:embed resources/glamourStyle.json
var GlamourStyle embed.FS

func docsCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "docs",
Short: "Prints comprehensive Armadactl documentation",
RunE: func(cmd *cobra.Command, args []string) error {
readmeContent, err := fs.ReadFile(ArmadactlReadMe, "resources/README.md")
if err != nil {
return fmt.Errorf("could not read content from documentation file: %s", err)
}

glamourStyleContent, err := fs.ReadFile(GlamourStyle, "resources/glamourStyle.json")
if err != nil {
return fmt.Errorf("could not read content from documentation file: %s", err)
}

renderer, err := glamour.NewTermRenderer(
glamour.WithStylesFromJSONBytes(glamourStyleContent),
glamour.WithWordWrap(120),
)
if err != nil {
return fmt.Errorf("could not create documentation renderer: %s", err)
}

out, err := renderer.Render(string(readmeContent))
if err != nil {
return fmt.Errorf("could not render content from documentation file: %s", err)
}

fmt.Println(out)
return nil
},
}

return cmd
}
Loading

0 comments on commit e66d6d8

Please sign in to comment.