add support for tcp cluster connections in uncloud config

This commit is contained in:
Pavel Sviderski
2024-11-28 18:53:47 +10:00
parent 6d1c3aa5b2
commit 3d5fe0a824
2 changed files with 16 additions and 9 deletions
+14 -9
View File
@@ -88,16 +88,21 @@ func (cli *CLI) ConnectCluster(ctx context.Context, clusterName string) (*client
// TODO: iterate over all connections and try to connect to the cluster using the first successful connection. // TODO: iterate over all connections and try to connect to the cluster using the first successful connection.
conn := cfg.Connections[0] conn := cfg.Connections[0]
user, host, port, err := conn.SSH.Parse() if conn.SSH != "" {
if err != nil { user, host, port, err := conn.SSH.Parse()
return nil, fmt.Errorf("parse SSH connection %q: %w", conn.SSH, err) if err != nil {
return nil, fmt.Errorf("parse SSH connection %q: %w", conn.SSH, err)
}
sshConfig := &connector.SSHConnectorConfig{
User: user,
Host: host,
Port: port,
}
return client.New(ctx, connector.NewSSHConnector(sshConfig))
} else if conn.TCP.IsValid() {
return client.New(ctx, connector.NewTCPConnector(conn.TCP))
} }
sshConfig := &connector.SSHConnectorConfig{ return nil, errors.New("no valid connection configuration found for the cluster")
User: user,
Host: host,
Port: port,
}
return client.New(ctx, connector.NewSSHConnector(sshConfig))
} }
func (cli *CLI) InitCluster( func (cli *CLI) InitCluster(
+2
View File
@@ -2,6 +2,7 @@ package config
import ( import (
"net" "net"
"net/netip"
"strconv" "strconv"
"strings" "strings"
"uncloud/internal/secret" "uncloud/internal/secret"
@@ -14,6 +15,7 @@ const (
type MachineConnection struct { type MachineConnection struct {
SSH SSHDestination `toml:"ssh,omitempty"` SSH SSHDestination `toml:"ssh,omitempty"`
TCP netip.AddrPort `toml:"tcp,omitempty"`
Host string `toml:"host,omitempty"` Host string `toml:"host,omitempty"`
PublicKey secret.Secret `toml:"public_key,omitempty"` PublicKey secret.Secret `toml:"public_key,omitempty"`
} }