allow running a service on a specified machine

This commit is contained in:
Pavel Sviderski
2024-11-10 19:38:19 +10:00
parent 1316dd3ffc
commit 5c74b09f45
4 changed files with 47 additions and 3 deletions
+3 -1
View File
@@ -7,6 +7,7 @@ import (
"os"
"strings"
"uncloud/cmd/uncloud/machine"
"uncloud/cmd/uncloud/service"
"uncloud/internal/cli"
)
@@ -41,7 +42,8 @@ func main() {
cmd.AddCommand(
machine.NewRootCommand(),
NewRunCommand(),
service.NewRootCommand(),
service.NewRunCommand(),
)
cobra.CheckErr(cmd.Execute())
}
+16
View File
@@ -0,0 +1,16 @@
package service
import (
"github.com/spf13/cobra"
)
func NewRootCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "service",
Short: "Manage services in an Uncloud cluster.",
}
cmd.AddCommand(
NewRunCommand(),
)
return cmd
}
@@ -1,4 +1,4 @@
package main
package service
import (
"github.com/spf13/cobra"
@@ -13,7 +13,7 @@ func NewRunCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "run IMAGE",
Short: "Run a service in a cluster.",
Short: "Run a service.",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
uncli := cmd.Context().Value("cli").(*cli.CLI)
@@ -25,6 +25,10 @@ func NewRunCommand() *cobra.Command {
cmd.Flags().StringVarP(&opts.Name, "name", "n", "",
"Assign a name to the service. A random name is generated if not specified.")
cmd.Flags().StringVarP(
&opts.Machine, "machine", "m", "",
"Name or ID of the machine to run the service on. (default is first available)",
)
cmd.Flags().StringSliceVarP(&opts.Publish, "publish", "p", nil,
"Publish a service port to make it accessible outside the cluster. Can be specified multiple times. "+
"Format: [load_balancer_port:]container_port[/protocol]")