Skip to content

Commit 9c2ce37

Browse files
committed
fix(swarm): extract cluster leader host:port
Reconstructing an etcd URL would fail because "http://" was left in the string returned by getLeaderHost().
1 parent 5f55c86 commit 9c2ce37

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

swarm/swarm.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"io/ioutil"
88
"log"
99
"net/http"
10+
"net/url"
1011
"os"
1112
"os/exec"
1213
"strings"
@@ -75,7 +76,10 @@ func getleaderHost() string {
7576

7677
for _, node := range etcdCluster.Members {
7778
if node.ID == etcdLeaderID {
78-
return node.ClientURLs[0]
79+
u, err := url.Parse(node.ClientURLs[0])
80+
if err == nil {
81+
return u.Host
82+
}
7983
}
8084
}
8185

@@ -95,6 +99,7 @@ func setEtcd(client *etcd.Client, key, value string, ttl uint64) {
9599
log.Println(err)
96100
}
97101
}
102+
98103
func main() {
99104
etcdproto := "etcd://" + getleaderHost() + swarmpath
100105
etcdhost := os.Getenv("HOST")

0 commit comments

Comments
 (0)