@@ -84,6 +84,10 @@ type Etcd struct {
84
84
// args contains the structured arguments to use for running etcd.
85
85
// Lazily initialized by .Configure(), Defaulted eventually with .defaultArgs()
86
86
args * process.Arguments
87
+
88
+ // listenPeerURL is the address the Etcd should listen on for peer connections.
89
+ // It's automatically generated and a random port is picked during execution.
90
+ listenPeerURL * url.URL
87
91
}
88
92
89
93
// Start starts the etcd, waits for it to come up, and returns an error, if one
@@ -111,6 +115,7 @@ func (e *Etcd) setProcessState() error {
111
115
return err
112
116
}
113
117
118
+ // Set the listen url.
114
119
if e .URL == nil {
115
120
port , host , err := addr .Suggest ("" )
116
121
if err != nil {
@@ -122,6 +127,18 @@ func (e *Etcd) setProcessState() error {
122
127
}
123
128
}
124
129
130
+ // Set the listen peer URL.
131
+ {
132
+ port , host , err := addr .Suggest ("" )
133
+ if err != nil {
134
+ return err
135
+ }
136
+ e .listenPeerURL = & url.URL {
137
+ Scheme : "http" ,
138
+ Host : net .JoinHostPort (host , strconv .Itoa (port )),
139
+ }
140
+ }
141
+
125
142
// can use /health as of etcd 3.3.0
126
143
e .processState .HealthCheck .URL = * e .URL
127
144
e .processState .HealthCheck .Path = "/health"
@@ -150,7 +167,7 @@ func (e *Etcd) Stop() error {
150
167
151
168
func (e * Etcd ) defaultArgs () map [string ][]string {
152
169
args := map [string ][]string {
153
- "listen-peer-urls" : {"http://localhost:0" },
170
+ "listen-peer-urls" : {e . listenPeerURL . String () },
154
171
"data-dir" : {e .DataDir },
155
172
}
156
173
if e .URL != nil {
0 commit comments