Skip to content

Commit 9cf79c5

Browse files
committed
Configure tests to listen on localhost
Signed-off-by: Nelo-T. Wallus <[email protected]>
1 parent eff92dd commit 9cf79c5

File tree

10 files changed

+41
-28
lines changed

10 files changed

+41
-28
lines changed

cmd/sharded-test-server/cache.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import (
3939
kcptestingserver "github.com/kcp-dev/kcp/sdk/testing/server"
4040
)
4141

42-
func startCacheServer(ctx context.Context, logDirPath, workingDir string, syntheticDelay time.Duration) (<-chan error, string, error) {
42+
func startCacheServer(ctx context.Context, logDirPath, workingDir, hostIP string, syntheticDelay time.Duration) (<-chan error, string, error) {
4343
cyan := color.New(color.BgHiCyan, color.FgHiWhite).SprintFunc()
4444
inverse := color.New(color.BgHiWhite, color.FgHiCyan).SprintFunc()
4545
out := lineprefix.New(
@@ -56,6 +56,7 @@ func startCacheServer(ctx context.Context, logDirPath, workingDir string, synthe
5656
commandLine = append(
5757
commandLine,
5858
fmt.Sprintf("--root-directory=%s", cacheWorkingDir),
59+
"--bind-address="+hostIP,
5960
"--embedded-etcd-client-port=8010",
6061
"--embedded-etcd-peer-port=8011",
6162
fmt.Sprintf("--secure-port=%d", cachePort),

cmd/sharded-test-server/frontproxy.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ func startFrontProxy(
132132

133133
// run front-proxy command
134134
commandLine := append(kcptestingserver.Command("kcp-front-proxy", "front-proxy"),
135+
"--bind-address="+hostIP,
135136
fmt.Sprintf("--mapping-file=%s", filepath.Join(workDirPath, ".kcp-front-proxy/mapping.yaml")),
136137
fmt.Sprintf("--root-directory=%s", filepath.Join(workDirPath, ".kcp-front-proxy")),
137138
fmt.Sprintf("--root-kubeconfig=%s", filepath.Join(workDirPath, ".kcp/root.kubeconfig")),

cmd/sharded-test-server/main.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828

2929
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3030
"k8s.io/apimachinery/pkg/types"
31-
machineryutilnet "k8s.io/apimachinery/pkg/util/net"
3231
"k8s.io/apimachinery/pkg/util/sets"
3332
"k8s.io/apimachinery/pkg/util/wait"
3433
kuser "k8s.io/apiserver/pkg/authentication/user"
@@ -192,17 +191,13 @@ func start(proxyFlags, shardFlags []string, logDirPath, workDirPath string, numb
192191
return fmt.Errorf("failed to create service-account-signing-ca: %w", err)
193192
}
194193

195-
// find external IP to put into certs as valid IPs
196-
hostIP, err := machineryutilnet.ResolveBindAddress(net.IPv4(0, 0, 0, 0))
197-
if err != nil {
198-
return err
199-
}
194+
hostIP := net.IPv4(127, 0, 0, 1)
200195

201196
standaloneVW := sets.New[string](shardFlags...).Has("--run-virtual-workspaces=false")
202197

203198
cacheServerErrCh := make(chan indexErrTuple)
204199
cacheServerConfigPath := ""
205-
cacheServerCh, configPath, err := startCacheServer(ctx, logDirPath, workDirPath, cacheSyntheticDelay)
200+
cacheServerCh, configPath, err := startCacheServer(ctx, logDirPath, workDirPath, hostIP.String(), cacheSyntheticDelay)
206201
if err != nil {
207202
return fmt.Errorf("error starting the cache server: %w", err)
208203
}

cmd/sharded-test-server/virtual.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,15 @@ func newVirtualWorkspace(ctx context.Context, index int, servingCA *crypto.CA, h
142142
return nil, err
143143
}
144144

145-
var args []string
146-
args = append(args,
145+
args := []string{
147146
fmt.Sprintf("--kubeconfig=%s", kubeconfigPath),
148147
fmt.Sprintf("--shard-external-url=https://%s:%d", hostIP, 6443),
149148
fmt.Sprintf("--cache-kubeconfig=%s", cacheServerConfigPath),
150149
fmt.Sprintf("--authentication-kubeconfig=%s", authenticationKubeconfigPath),
151150
fmt.Sprintf("--client-ca-file=%s", clientCAFilePath),
152151
fmt.Sprintf("--tls-private-key-file=%s", servingKeyFile),
153152
fmt.Sprintf("--tls-cert-file=%s", servingCertFile),
153+
fmt.Sprintf("--bind-address=%s", hostIP),
154154
fmt.Sprintf("--secure-port=%s", virtualWorkspacePort(index)),
155155
"--audit-log-maxsize=1024",
156156
"--audit-log-mode=batch",
@@ -161,7 +161,7 @@ func newVirtualWorkspace(ctx context.Context, index int, servingCA *crypto.CA, h
161161
"--audit-log-batch-throttle-enable=true",
162162
"--audit-log-batch-throttle-qps=10",
163163
fmt.Sprintf("--audit-policy-file=%s", auditPolicyFile),
164-
)
164+
}
165165

166166
return &VirtualWorkspace{
167167
index: index,

cmd/test-server/kcp/shard.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ func (s *Shard) Start(ctx context.Context, quiet bool) error {
9999
commandLine = append(commandLine, s.args...)
100100
commandLine = append(commandLine,
101101
"--root-directory", s.runtimeDir,
102+
"--bind-address=127.0.0.1",
102103
"--token-auth-file", framework.DefaultTokenAuthFile,
103104
"--audit-log-maxsize", "1024",
104105
"--audit-log-mode=batch",

sdk/testing/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ type SharedKcpOption func()
2828

2929
var (
3030
sharedConfig = kcptestingserver.Config{
31-
Name: "shared",
31+
Name: "shared",
32+
BindAddress: "127.0.0.1",
3233
}
3334
externalConfig = struct {
3435
kubeconfigPath string

sdk/testing/kcp.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ var fs embed.FS
3535
func PrivateKcpServer(t TestingT, options ...kcptestingserver.Option) kcptestingserver.RunningServer {
3636
t.Helper()
3737

38-
cfg := &kcptestingserver.Config{Name: "main"}
38+
cfg := &kcptestingserver.Config{
39+
Name: "main",
40+
BindAddress: "127.0.0.1",
41+
}
3942
for _, opt := range options {
4043
opt(cfg)
4144
}

sdk/testing/server/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type Config struct {
2727
ArtifactDir string
2828
DataDir string
2929
ClientCADir string
30+
BindAddress string
3031

3132
LogToConsole bool
3233
RunInProcess bool
@@ -84,3 +85,10 @@ func WithLogToConsole() Option {
8485
cfg.LogToConsole = true
8586
}
8687
}
88+
89+
// WithBindAddress sets the kcp server to log to console.
90+
func WithBindAddress(addr string) Option {
91+
return func(cfg *Config) {
92+
cfg.BindAddress = addr
93+
}
94+
}

sdk/testing/server/fixture.go

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -203,21 +203,23 @@ func newKcpServer(t TestingT, cfg Config) (*kcpServer, error) {
203203
return nil, err
204204
}
205205

206-
s.cfg.Args = append(
207-
[]string{
208-
"--root-directory",
209-
s.cfg.DataDir,
210-
"--secure-port=" + kcpListenPort,
211-
"--embedded-etcd-client-port=" + etcdClientPort,
212-
"--embedded-etcd-peer-port=" + etcdPeerPort,
213-
"--embedded-etcd-wal-size-bytes=" + strconv.Itoa(5*1000), // 5KB
214-
"--kubeconfig-path=" + s.KubeconfigPath(),
215-
"--feature-gates=" + fmt.Sprintf("%s", utilfeature.DefaultFeatureGate),
216-
"--audit-log-path", filepath.Join(s.cfg.ArtifactDir, "kcp.audit"),
217-
"--v=4",
218-
},
219-
s.cfg.Args...,
220-
)
206+
args := []string{
207+
"--root-directory", s.cfg.DataDir,
208+
"--secure-port=" + kcpListenPort,
209+
"--embedded-etcd-client-port=" + etcdClientPort,
210+
"--embedded-etcd-peer-port=" + etcdPeerPort,
211+
"--embedded-etcd-wal-size-bytes=" + strconv.Itoa(5*1000), // 5KB
212+
"--kubeconfig-path=" + s.KubeconfigPath(),
213+
"--feature-gates=" + fmt.Sprintf("%s", utilfeature.DefaultFeatureGate),
214+
"--audit-log-path", filepath.Join(s.cfg.ArtifactDir, "kcp.audit"),
215+
"--v=4",
216+
}
217+
218+
if cfg.BindAddress != "" {
219+
args = append(args, "--bind-address="+cfg.BindAddress)
220+
}
221+
222+
s.cfg.Args = append(args, s.cfg.Args...)
221223

222224
return s, nil
223225
}

test/integration/framework/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func StartTestServer(tb testing.TB, opts ...kcptestingserver.Option) (kcptesting
4444
[]kcptestingserver.Option{
4545
kcptestingserver.WithDefaultsFrom(tb),
4646
kcptestingserver.WithRunInProcess(),
47+
kcptestingserver.WithBindAddress("127.0.0.1"),
4748
},
4849
opts...,
4950
)...,

0 commit comments

Comments
 (0)