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
+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
}
+41
View File
@@ -0,0 +1,41 @@
package service
import (
"github.com/spf13/cobra"
"uncloud/internal/cli"
)
func NewRunCommand() *cobra.Command {
var (
cluster string
opts cli.ServiceOptions
)
cmd := &cobra.Command{
Use: "run IMAGE",
Short: "Run a service.",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
uncli := cmd.Context().Value("cli").(*cli.CLI)
opts.Image = args[0]
return uncli.RunService(cmd.Context(), cluster, &opts)
},
}
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]")
cmd.Flags().StringVarP(
&cluster, "cluster", "c", "",
"Name of the cluster to run the service in. (default is the current cluster)",
)
return cmd
}