add --mode flag to run command

This commit is contained in:
Pavel Sviderski
2024-11-23 15:56:03 +10:00
parent 5c1a3dd694
commit df25b0d098
2 changed files with 15 additions and 0 deletions
+5
View File
@@ -6,6 +6,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"uncloud/internal/cli" "uncloud/internal/cli"
"uncloud/internal/cli/client" "uncloud/internal/cli/client"
"uncloud/internal/docker"
) )
func NewRunCommand() *cobra.Command { func NewRunCommand() *cobra.Command {
@@ -31,6 +32,10 @@ func NewRunCommand() *cobra.Command {
&opts.Machine, "machine", "m", "", &opts.Machine, "machine", "m", "",
"Name or ID of the machine to run the service on. (default is first available)", "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, cmd.Flags().StringSliceVarP(&opts.Publish, "publish", "p", nil,
"Publish a service port to make it accessible outside the cluster. Can be specified multiple times. "+ "Publish a service port to make it accessible outside the cluster. Can be specified multiple times. "+
"Format: [load_balancer_port:]container_port[/protocol]") "Format: [load_balancer_port:]container_port[/protocol]")
+10
View File
@@ -22,6 +22,8 @@ type ServiceOptions struct {
Image string Image string
Name string Name string
Machine string Machine string
// Mode is the replication mode of the service.
Mode string
Publish []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) 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. // Find a machine to run the service on.
listResp, err := c.ListMachines(ctx, &emptypb.Empty{}) listResp, err := c.ListMachines(ctx, &emptypb.Empty{})
if err != nil { if err != nil {