mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 11:03:34 +00:00
add --mode flag to run command
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
"uncloud/internal/cli"
|
||||
"uncloud/internal/cli/client"
|
||||
"uncloud/internal/docker"
|
||||
)
|
||||
|
||||
func NewRunCommand() *cobra.Command {
|
||||
@@ -31,6 +32,10 @@ func NewRunCommand() *cobra.Command {
|
||||
&opts.Machine, "machine", "m", "",
|
||||
"Name or ID of the machine to run the service on. (default is first available)",
|
||||
)
|
||||
cmd.Flags().StringVar(&opts.Mode, "mode", docker.DeployModeReplicated,
|
||||
fmt.Sprintf("Replication mode of the service: either %q (a specified number of containers across "+
|
||||
"the machines) or %q (one container on every machine).",
|
||||
docker.DeployModeReplicated, docker.DeployModeGlobal))
|
||||
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]")
|
||||
|
||||
@@ -22,6 +22,8 @@ type ServiceOptions struct {
|
||||
Image string
|
||||
Name string
|
||||
Machine string
|
||||
// Mode is the replication mode of the service.
|
||||
Mode string
|
||||
Publish []string
|
||||
}
|
||||
|
||||
@@ -39,6 +41,14 @@ func (c *Client) RunService(ctx context.Context, opts *ServiceOptions) (RunServi
|
||||
return resp, fmt.Errorf("invalid image: %w", err)
|
||||
}
|
||||
|
||||
switch opts.Mode {
|
||||
case docker.DeployModeReplicated:
|
||||
case docker.DeployModeGlobal:
|
||||
return resp, errors.New("global mode is not supported yet")
|
||||
default:
|
||||
return resp, fmt.Errorf("invalid mode: %q", opts.Mode)
|
||||
}
|
||||
|
||||
// Find a machine to run the service on.
|
||||
listResp, err := c.ListMachines(ctx, &emptypb.Empty{})
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user