From e5f68947f9ac545f532384c89044e324a294de37 Mon Sep 17 00:00:00 2001 From: Pavel Sviderski Date: Tue, 25 Feb 2025 21:22:32 +1000 Subject: [PATCH] feat(dns): missed CLI changes --- internal/cli/cli.go | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/internal/cli/cli.go b/internal/cli/cli.go index 5d6174f5..fa1768b8 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -112,17 +112,27 @@ func (cli *CLI) ConnectCluster(ctx context.Context, clusterName string) (*client // InitCluster initialises a new cluster on a remote machine and returns a client to interact with the cluster. // The client should be closed after use by the caller. func (cli *CLI) InitCluster( - ctx context.Context, remoteMachine *RemoteMachine, clusterName, machineName string, netPrefix netip.Prefix, + ctx context.Context, + remoteMachine *RemoteMachine, + clusterName, + machineName string, + netPrefix netip.Prefix, + publicIP *netip.Addr, ) (*client.Client, error) { if remoteMachine != nil { - return cli.initRemoteMachine(ctx, *remoteMachine, clusterName, machineName, netPrefix) + return cli.initRemoteMachine(ctx, *remoteMachine, clusterName, machineName, netPrefix, publicIP) } // TODO: implement local machine initialisation return nil, fmt.Errorf("local machine initialisation is not implemented yet") } func (cli *CLI) initRemoteMachine( - ctx context.Context, remoteMachine RemoteMachine, clusterName, machineName string, netPrefix netip.Prefix, + ctx context.Context, + remoteMachine RemoteMachine, + clusterName, + machineName string, + netPrefix netip.Prefix, + publicIP *netip.Addr, ) (*client.Client, error) { if clusterName == "" { clusterName = defaultClusterName @@ -157,6 +167,15 @@ func (cli *CLI) initRemoteMachine( MachineName: machineName, Network: pb.NewIPPrefix(netPrefix), } + if publicIP != nil { + if publicIP.IsValid() { + req.PublicIpConfig = &pb.InitClusterRequest_PublicIp{PublicIp: pb.NewIP(*publicIP)} + } else { + // Invalid or in other words zero IP means to automatically detect the public IP. + req.PublicIpConfig = &pb.InitClusterRequest_PublicIpAuto{PublicIpAuto: true} + } + } + resp, err := machineClient.InitCluster(ctx, req) if err != nil { return nil, fmt.Errorf("init cluster: %w", err)