Skip to content

Commit

Permalink
Merge pull request k0sproject#5181 from ncopa/ipv6-etcd-peer
Browse files Browse the repository at this point in the history
Fix etcd peer URL to support ipv6
  • Loading branch information
ncopa authored Nov 8, 2024
2 parents 994f4cc + 1469e0c commit 09ac812
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
10 changes: 10 additions & 0 deletions pkg/apis/k0s/v1beta1/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package v1beta1
import (
"encoding/json"
"fmt"
"net"
"net/url"
"os"
"path/filepath"
Expand Down Expand Up @@ -179,6 +180,15 @@ func (e *EtcdConfig) GetNodeName() (string, error) {
return os.Hostname()
}

// GetPeerURL returns the URL of PeerAddress
func (e *EtcdConfig) GetPeerURL() string {
u := &url.URL{
Scheme: "https",
Host: net.JoinHostPort(e.PeerAddress, "2380"),
}
return u.String()
}

// DefaultKineConfig creates KineConfig with sane defaults
func DefaultKineConfig(dataDir string) *KineConfig {
return &KineConfig{
Expand Down
8 changes: 7 additions & 1 deletion pkg/backup/etcd_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ package backup
import (
"context"
"fmt"
"net"
"net/url"
"os"
"path/filepath"

Expand Down Expand Up @@ -84,7 +86,11 @@ func (e etcdStep) Restore(restoreFrom, _ string) error {
if err != nil {
return err
}
peerURL := fmt.Sprintf("https://%s:2380", e.peerAddress)
u := &url.URL{
Scheme: "https",
Host: net.JoinHostPort(e.peerAddress, "2380"),
}
peerURL := u.String()
restoreConfig := utilsnapshot.RestoreConfig{
SnapshotPath: snapshotPath,
OutputDataDir: e.etcdDataDir,
Expand Down
2 changes: 1 addition & 1 deletion pkg/component/controller/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (e *Etcd) Start(ctx context.Context) error {
name = hostName
}

peerURL := fmt.Sprintf("https://%s:2380", e.Config.PeerAddress)
peerURL := e.Config.GetPeerURL()

args := stringmap.StringMap{
"--data-dir": e.K0sVars.EtcdDataDir,
Expand Down
5 changes: 1 addition & 4 deletions pkg/component/controller/etcd_member_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"errors"
"fmt"
"net"
"strconv"
"time"

Expand Down Expand Up @@ -177,9 +176,7 @@ func (e *EtcdMemberReconciler) createMemberObject(ctx context.Context) error {
return err
}

peerURL := fmt.Sprintf("https://%s", net.JoinHostPort(e.etcdConfig.PeerAddress, "2380"))

memberID, err := etcdClient.GetPeerIDByAddress(ctx, peerURL)
memberID, err := etcdClient.GetPeerIDByAddress(ctx, e.etcdConfig.GetPeerURL())
if err != nil {
return err
}
Expand Down

0 comments on commit 09ac812

Please sign in to comment.