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
+22
View File
@@ -4,12 +4,15 @@ import (
"context"
"fmt"
"github.com/docker/docker/api/types/container"
"google.golang.org/grpc/metadata"
"google.golang.org/protobuf/types/known/emptypb"
)
// ServiceOptions contains all the options for creating a service.
type ServiceOptions struct {
Image string
Name string
Machine string
Publish []string
}
@@ -22,6 +25,25 @@ func (cli *CLI) RunService(ctx context.Context, clusterName string, opts *Servic
_ = c.Close()
}()
machResp, err := c.ListMachines(ctx, &emptypb.Empty{})
if err != nil {
return fmt.Errorf("list machines: %w", err)
}
// TODO: update ListMachine endpoint to return machine status based on the Corrosion member list.
machineIP, _ := machResp.Machines[0].Network.ManagementIp.ToAddr()
if opts.Machine != "" {
for _, m := range machResp.Machines {
if m.Name == opts.Machine || m.Id == opts.Machine {
machineIP, _ = m.Network.ManagementIp.ToAddr()
break
}
}
}
md := metadata.Pairs("machines", machineIP.String())
ctx = metadata.NewOutgoingContext(ctx, md)
config := &container.Config{
Image: opts.Image,
}