Skip to content

Commit c0a5bab

Browse files
authored
🐛 Envtest should try to allocate a port for etcd listenPeerURL (#1612)
Signed-off-by: Vince Prignano <[email protected]>
1 parent 9fe547c commit c0a5bab

File tree

1 file changed

+18
-1
lines changed
  • pkg/internal/testing/controlplane

1 file changed

+18
-1
lines changed

pkg/internal/testing/controlplane/etcd.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ type Etcd struct {
8484
// args contains the structured arguments to use for running etcd.
8585
// Lazily initialized by .Configure(), Defaulted eventually with .defaultArgs()
8686
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
8791
}
8892

8993
// 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 {
111115
return err
112116
}
113117

118+
// Set the listen url.
114119
if e.URL == nil {
115120
port, host, err := addr.Suggest("")
116121
if err != nil {
@@ -122,6 +127,18 @@ func (e *Etcd) setProcessState() error {
122127
}
123128
}
124129

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+
125142
// can use /health as of etcd 3.3.0
126143
e.processState.HealthCheck.URL = *e.URL
127144
e.processState.HealthCheck.Path = "/health"
@@ -150,7 +167,7 @@ func (e *Etcd) Stop() error {
150167

151168
func (e *Etcd) defaultArgs() map[string][]string {
152169
args := map[string][]string{
153-
"listen-peer-urls": {"http://localhost:0"},
170+
"listen-peer-urls": {e.listenPeerURL.String()},
154171
"data-dir": {e.DataDir},
155172
}
156173
if e.URL != nil {

0 commit comments

Comments
 (0)