Skip to content

Commit 096bdb7

Browse files
committed
Sample apiserver: Avoid etcd listening on DNS result for "localhost"
We've had a fun case of `Sample API Server using the current Aggregator` failing due to DNS returning a response for localhost that is not 127.0.0.1 and does not exist on the node, causing etcd trying to bind to a non-existing address and consequently failing. Trying to spare others this fun :)
1 parent 9bd2912 commit 096bdb7

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

test/e2e/apimachinery/aggregator.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"encoding/json"
2222
"fmt"
2323
"math/big"
24+
"net"
2425
"strings"
2526
"time"
2627

@@ -198,6 +199,12 @@ func TestSampleAPIServer(f *framework.Framework, aggrclient *aggregatorclient.Cl
198199
podLabels := map[string]string{"app": "sample-apiserver", "apiserver": "true"}
199200
replicas := int32(1)
200201
zero := int64(0)
202+
etcdLocalhostAddress := "127.0.0.1"
203+
if framework.TestContext.ClusterIsIPv6() {
204+
etcdLocalhostAddress = "::1"
205+
}
206+
etcdURL := fmt.Sprintf("http://%s", net.JoinHostPort(etcdLocalhostAddress, "2379"))
207+
201208
mounts := []v1.VolumeMount{
202209
{
203210
Name: "apiserver-certs",
@@ -218,7 +225,7 @@ func TestSampleAPIServer(f *framework.Framework, aggrclient *aggregatorclient.Cl
218225
Name: "sample-apiserver",
219226
VolumeMounts: mounts,
220227
Args: []string{
221-
"--etcd-servers=http://localhost:2379",
228+
fmt.Sprintf("--etcd-servers=%s", etcdURL),
222229
"--tls-cert-file=/apiserver.local.config/certificates/tls.crt",
223230
"--tls-private-key-file=/apiserver.local.config/certificates/tls.key",
224231
"--audit-log-path=-",
@@ -232,6 +239,10 @@ func TestSampleAPIServer(f *framework.Framework, aggrclient *aggregatorclient.Cl
232239
Image: etcdImage,
233240
Command: []string{
234241
"/usr/local/bin/etcd",
242+
"--listen-client-urls",
243+
etcdURL,
244+
"--advertise-client-urls",
245+
etcdURL,
235246
},
236247
},
237248
}

0 commit comments

Comments
 (0)