Skip to content

Commit a98263e

Browse files
committed
Disable metrics server in unit tests
Controller manager should not create metrics server in unti tests, as 8080 port might be already in use when k3d and Redpanda container is created during operator tests. ``` pvcunbinder_test.go:348: Error Trace: /work/src/go/k8s/internal/controller/pvcunbinder/pvcunbinder_test.go:348 /root/go/pkg/mod/golang.org/[email protected]/src/runtime/asm_amd64.s:1695 Error: Received unexpected error: failed to start metrics server: failed to create listener: listen tcp :8080: bind: address already in use Test: TestPVCUnbinder pvcunbinder_test.go:237: Error Trace: /work/src/go/k8s/internal/controller/pvcunbinder/pvcunbinder_test.go:237 Error: Condition never satisfied Test: TestPVCUnbinder ```
1 parent 45ea4d9 commit a98263e

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/go/k8s/internal/controller/pvcunbinder/pvcunbinder_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"sigs.k8s.io/controller-runtime/pkg/client"
3030
"sigs.k8s.io/controller-runtime/pkg/log"
3131
"sigs.k8s.io/controller-runtime/pkg/manager"
32+
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
3233
)
3334

3435
func TestPVCUnbinderShouldRemediate(t *testing.T) {
@@ -220,6 +221,7 @@ func TestPVCUnbinder(t *testing.T) {
220221

221222
// Start up our manager
222223
mgr, err := manager.New(cluster.RESTConfig(), manager.Options{
224+
Metrics: metricsserver.Options{BindAddress: "0"},
223225
BaseContext: func() context.Context {
224226
return log.IntoContext(ctx, logger)
225227
},

0 commit comments

Comments
 (0)