diff --git a/cmd/uncloud/service/run.go b/cmd/uncloud/service/run.go index 0f16fe10..b41d5de1 100644 --- a/cmd/uncloud/service/run.go +++ b/cmd/uncloud/service/run.go @@ -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]") diff --git a/internal/cli/client/service.go b/internal/cli/client/service.go index daabd870..1898ef86 100644 --- a/internal/cli/client/service.go +++ b/internal/cli/client/service.go @@ -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 {