Skip to content

Commit

Permalink
Disable metrics server in unit tests
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
RafalKorepta committed Sep 5, 2024
1 parent 45ea4d9 commit a98263e
Showing 1 changed file with 2 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/manager"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
)

func TestPVCUnbinderShouldRemediate(t *testing.T) {
Expand Down Expand Up @@ -220,6 +221,7 @@ func TestPVCUnbinder(t *testing.T) {

// Start up our manager
mgr, err := manager.New(cluster.RESTConfig(), manager.Options{
Metrics: metricsserver.Options{BindAddress: "0"},
BaseContext: func() context.Context {
return log.IntoContext(ctx, logger)
},
Expand Down

0 comments on commit a98263e

Please sign in to comment.