From 213228583214000f278161ad8b04c89eea8e51a2 Mon Sep 17 00:00:00 2001 From: Nick Mitchell Date: Wed, 25 Sep 2024 14:07:03 -0400 Subject: [PATCH] refactor: move minio/worker/workstealer subcommands to be under a components/ command subtree Signed-off-by: Nick Mitchell --- cmd/subcommands/component.go | 19 ++++++++++++++++ cmd/subcommands/{ => component}/minio.go | 14 +++++------- .../{ => component}/minio/server.go | 0 cmd/subcommands/component/worker.go | 20 +++++++++++++++++ .../{ => component}/worker/prestop.go | 2 +- cmd/subcommands/{ => component}/worker/run.go | 2 +- .../{ => component}/workstealer.go | 8 ++----- cmd/subcommands/worker.go | 22 ------------------- pkg/fe/transformer/api/minio/transpile.go | 2 +- pkg/fe/transformer/api/workerpool/lower.go | 4 ++-- .../transformer/api/workstealer/transpile.go | 2 +- 11 files changed, 53 insertions(+), 42 deletions(-) create mode 100644 cmd/subcommands/component.go rename cmd/subcommands/{ => component}/minio.go (51%) rename cmd/subcommands/{ => component}/minio/server.go (100%) create mode 100644 cmd/subcommands/component/worker.go rename cmd/subcommands/{ => component}/worker/prestop.go (90%) rename cmd/subcommands/{ => component}/worker/run.go (95%) rename cmd/subcommands/{ => component}/workstealer.go (75%) delete mode 100644 cmd/subcommands/worker.go diff --git a/cmd/subcommands/component.go b/cmd/subcommands/component.go new file mode 100644 index 000000000..d1480ab73 --- /dev/null +++ b/cmd/subcommands/component.go @@ -0,0 +1,19 @@ +package subcommands + +import ( + "github.com/spf13/cobra" + + "lunchpail.io/cmd/subcommands/component" +) + +func init() { + cmd := &cobra.Command{ + Use: "component", + Short: "Commands related to specific components", + } + rootCmd.AddCommand(cmd) + + cmd.AddCommand(component.Minio()) + cmd.AddCommand(component.Worker()) + cmd.AddCommand(component.WorkStealer()) +} diff --git a/cmd/subcommands/minio.go b/cmd/subcommands/component/minio.go similarity index 51% rename from cmd/subcommands/minio.go rename to cmd/subcommands/component/minio.go index 4fe01f7c6..06ff19313 100644 --- a/cmd/subcommands/minio.go +++ b/cmd/subcommands/component/minio.go @@ -1,21 +1,19 @@ -package subcommands +package component import ( "github.com/spf13/cobra" - "lunchpail.io/cmd/subcommands/minio" + "lunchpail.io/cmd/subcommands/component/minio" ) -func newMinioCmd() *cobra.Command { - return &cobra.Command{ +func Minio() *cobra.Command { + cmd := &cobra.Command{ Use: "minio", Short: "Commands for running minio components", Long: "Commands for running minio components", } -} -func init() { - cmd := newMinioCmd() - rootCmd.AddCommand(cmd) cmd.AddCommand(minio.Server()) + + return cmd } diff --git a/cmd/subcommands/minio/server.go b/cmd/subcommands/component/minio/server.go similarity index 100% rename from cmd/subcommands/minio/server.go rename to cmd/subcommands/component/minio/server.go diff --git a/cmd/subcommands/component/worker.go b/cmd/subcommands/component/worker.go new file mode 100644 index 000000000..2f10fffd8 --- /dev/null +++ b/cmd/subcommands/component/worker.go @@ -0,0 +1,20 @@ +package component + +import ( + "github.com/spf13/cobra" + + "lunchpail.io/cmd/subcommands/component/worker" +) + +func Worker() *cobra.Command { + cmd := &cobra.Command{ + Use: "worker", + Short: "Commands that act as an application worker", + Long: "Commands that act as an application worker", + } + + cmd.AddCommand(worker.Run()) + cmd.AddCommand(worker.PreStop()) + + return cmd +} diff --git a/cmd/subcommands/worker/prestop.go b/cmd/subcommands/component/worker/prestop.go similarity index 90% rename from cmd/subcommands/worker/prestop.go rename to cmd/subcommands/component/worker/prestop.go index 756ac8f10..6bd1f7505 100644 --- a/cmd/subcommands/worker/prestop.go +++ b/cmd/subcommands/component/worker/prestop.go @@ -8,7 +8,7 @@ import ( "lunchpail.io/pkg/runtime/worker" ) -func NewPreStopCmd() *cobra.Command { +func PreStop() *cobra.Command { var cmd = &cobra.Command{ Use: "prestop", Short: "Mark this worker as dead", diff --git a/cmd/subcommands/worker/run.go b/cmd/subcommands/component/worker/run.go similarity index 95% rename from cmd/subcommands/worker/run.go rename to cmd/subcommands/component/worker/run.go index 4e54fac0a..261767f02 100644 --- a/cmd/subcommands/worker/run.go +++ b/cmd/subcommands/component/worker/run.go @@ -10,7 +10,7 @@ import ( "lunchpail.io/pkg/runtime/worker" ) -func NewRunCmd() *cobra.Command { +func Run() *cobra.Command { var cmd = &cobra.Command{ Use: "run [-- workerCommand workerCommandArg1 workerCommandArg2 ...]", Short: "Run as an application worker", diff --git a/cmd/subcommands/workstealer.go b/cmd/subcommands/component/workstealer.go similarity index 75% rename from cmd/subcommands/workstealer.go rename to cmd/subcommands/component/workstealer.go index 6cf46dc4a..f8a928b93 100644 --- a/cmd/subcommands/workstealer.go +++ b/cmd/subcommands/component/workstealer.go @@ -1,4 +1,4 @@ -package subcommands +package component import ( "context" @@ -7,7 +7,7 @@ import ( "lunchpail.io/pkg/runtime/workstealer" ) -func newWorkstealerCmd() *cobra.Command { +func WorkStealer() *cobra.Command { var cmd = &cobra.Command{ Use: "workstealer", Short: "Run a work stealer", @@ -21,7 +21,3 @@ func newWorkstealerCmd() *cobra.Command { return cmd } - -func init() { - rootCmd.AddCommand(newWorkstealerCmd()) -} diff --git a/cmd/subcommands/worker.go b/cmd/subcommands/worker.go deleted file mode 100644 index 729dac242..000000000 --- a/cmd/subcommands/worker.go +++ /dev/null @@ -1,22 +0,0 @@ -package subcommands - -import ( - "github.com/spf13/cobra" - - "lunchpail.io/cmd/subcommands/worker" -) - -func newWorkerCmd() *cobra.Command { - return &cobra.Command{ - Use: "worker", - Short: "Commands that act as an application worker", - Long: "Commands that act as an application worker", - } -} - -func init() { - workerCmd := newWorkerCmd() - rootCmd.AddCommand(workerCmd) - workerCmd.AddCommand(worker.NewRunCmd()) - workerCmd.AddCommand(worker.NewPreStopCmd()) -} diff --git a/pkg/fe/transformer/api/minio/transpile.go b/pkg/fe/transformer/api/minio/transpile.go index 3af09106f..c1cc40dd3 100644 --- a/pkg/fe/transformer/api/minio/transpile.go +++ b/pkg/fe/transformer/api/minio/transpile.go @@ -18,7 +18,7 @@ func transpile(runname string, ir llir.LLIR) (hlir.Application, error) { app.Spec.Image = "docker.io/minio/minio:RELEASE.2024-07-04T14-25-45Z" app.Spec.Role = "queue" app.Spec.Expose = []string{fmt.Sprintf("%d:%d", ir.Queue.Port, ir.Queue.Port)} - app.Spec.Command = fmt.Sprintf("$LUNCHPAIL_EXE minio server --port %d", ir.Queue.Port) + app.Spec.Command = fmt.Sprintf("$LUNCHPAIL_EXE component minio server --port %d", ir.Queue.Port) prefixIncludingBucket := api.QueuePrefixPath(ir.Queue, runname) A := strings.Split(prefixIncludingBucket, "/") diff --git a/pkg/fe/transformer/api/workerpool/lower.go b/pkg/fe/transformer/api/workerpool/lower.go index c44b12058..c6c2d437a 100644 --- a/pkg/fe/transformer/api/workerpool/lower.go +++ b/pkg/fe/transformer/api/workerpool/lower.go @@ -30,8 +30,8 @@ func Lower(compilationName, runname string, app hlir.Application, pool hlir.Work } app.Spec.Env["LUNCHPAIL_STARTUP_DELAY"] = strconv.Itoa(startupDelay) - app.Spec.Command = fmt.Sprintf(`trap "$LUNCHPAIL_EXE worker prestop" EXIT -$LUNCHPAIL_EXE worker run --debug=%v -- %s`, opts.Log.Debug, app.Spec.Command) + app.Spec.Command = fmt.Sprintf(`trap "$LUNCHPAIL_EXE component worker prestop" EXIT +$LUNCHPAIL_EXE component worker run --debug=%v -- %s`, opts.Log.Debug, app.Spec.Command) return shell.LowerAsComponent( compilationName, diff --git a/pkg/fe/transformer/api/workstealer/transpile.go b/pkg/fe/transformer/api/workstealer/transpile.go index f5ef416ae..c28dddb8c 100644 --- a/pkg/fe/transformer/api/workstealer/transpile.go +++ b/pkg/fe/transformer/api/workstealer/transpile.go @@ -14,7 +14,7 @@ func transpile(runname string) (hlir.Application, error) { app.Spec.Image = fmt.Sprintf("%s/%s/lunchpail:%s", lunchpail.ImageRegistry, lunchpail.ImageRepo, lunchpail.Version()) app.Spec.Role = "workstealer" - app.Spec.Command = "$LUNCHPAIL_EXE workstealer" + app.Spec.Command = "$LUNCHPAIL_EXE component workstealer" app.Spec.Env = hlir.Env{} app.Spec.Env["LUNCHPAIL_RUN_NAME"] = runname