feat(dns): missed CLI changes

This commit is contained in:
Pavel Sviderski
2025-02-25 21:22:32 +10:00
parent 289d964b2a
commit e5f68947f9
+22 -3
View File
@@ -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)