mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 19:13:34 +00:00
fix: adding ucind cluster with tcp connections to config
This commit is contained in:
+2
-2
@@ -137,8 +137,8 @@ func connectCluster(ctx context.Context, conn config.MachineConnection) (*client
|
||||
KeyPath: keyPath,
|
||||
}
|
||||
return client.New(ctx, connector.NewSSHConnector(sshConfig))
|
||||
} else if conn.TCP.IsValid() {
|
||||
return client.New(ctx, connector.NewTCPConnector(conn.TCP))
|
||||
} else if conn.TCP != nil && conn.TCP.IsValid() {
|
||||
return client.New(ctx, connector.NewTCPConnector(*conn.TCP))
|
||||
}
|
||||
|
||||
return nil, errors.New("connection configuration is invalid")
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
"github.com/goccy/go-yaml"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@@ -45,7 +45,7 @@ func (c *Config) Read() error {
|
||||
return fmt.Errorf("read config file '%s': %w", c.path, err)
|
||||
}
|
||||
if err = yaml.Unmarshal(data, c); err != nil {
|
||||
return fmt.Errorf("parse config file '%s': %w", c.path, err)
|
||||
return fmt.Errorf("parse config file '%s': %s", c.path, yaml.FormatError(err, true, true))
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -62,8 +62,7 @@ func (c *Config) Save() error {
|
||||
return fmt.Errorf("write config file '%s': %w", c.path, err)
|
||||
}
|
||||
|
||||
encoder := yaml.NewEncoder(f)
|
||||
encoder.SetIndent(2)
|
||||
encoder := yaml.NewEncoder(f, yaml.Indent(2), yaml.IndentSequence(true))
|
||||
if err = encoder.Encode(c); err != nil {
|
||||
_ = f.Close()
|
||||
return fmt.Errorf("encode config file '%s': %w", c.path, err)
|
||||
|
||||
@@ -17,9 +17,11 @@ const (
|
||||
type MachineConnection struct {
|
||||
SSH SSHDestination `yaml:"ssh,omitempty"`
|
||||
SSHKeyFile string `yaml:"ssh_key_file,omitempty"`
|
||||
TCP netip.AddrPort `yaml:"tcp,omitempty"`
|
||||
Host string `yaml:"host,omitempty"`
|
||||
PublicKey secret.Secret `yaml:"public_key,omitempty"`
|
||||
// TCP is the address and port of the machine's API server.
|
||||
// The pointer is used to omit the field when not set. Otherwise, yaml marshalling includes an empty object.
|
||||
TCP *netip.AddrPort `yaml:"tcp,omitempty"`
|
||||
Host string `yaml:"host,omitempty"`
|
||||
PublicKey secret.Secret `yaml:"public_key,omitempty"`
|
||||
}
|
||||
|
||||
// SSHDestination represents an SSH destination string in the canonical form of "user@host:port".
|
||||
|
||||
@@ -4,17 +4,18 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/netip"
|
||||
"time"
|
||||
|
||||
"github.com/cenkalti/backoff/v4"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/docker/docker/api/types/network"
|
||||
dockerclient "github.com/docker/docker/client"
|
||||
"google.golang.org/protobuf/types/known/emptypb"
|
||||
"net/netip"
|
||||
"time"
|
||||
"github.com/psviderski/uncloud/internal/machine"
|
||||
"github.com/psviderski/uncloud/internal/machine/api/pb"
|
||||
"github.com/psviderski/uncloud/internal/machine/cluster"
|
||||
"google.golang.org/protobuf/types/known/emptypb"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -79,7 +80,7 @@ func (p *Provisioner) CreateCluster(ctx context.Context, name string, opts Creat
|
||||
if err = p.configUpdater.AddCluster(c); err != nil {
|
||||
return c, fmt.Errorf("add cluster to Uncloud config: %w", err)
|
||||
}
|
||||
fmt.Printf("Cluster '%s' added to Uncloud config.\n", c.Name)
|
||||
fmt.Printf("Cluster '%s' added to Uncloud config as the current context.\n", name)
|
||||
}
|
||||
|
||||
return c, nil
|
||||
|
||||
@@ -30,7 +30,7 @@ func (u *ConfigUpdater) AddCluster(c Cluster) error {
|
||||
}
|
||||
for i, m := range c.Machines {
|
||||
clusterCfg.Connections[i] = config.MachineConnection{
|
||||
TCP: m.APIAddress,
|
||||
TCP: &m.APIAddress,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user