File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,7 @@ import (
4747 "sigs.k8s.io/controller-runtime/pkg/cache"
4848 "sigs.k8s.io/controller-runtime/pkg/client"
4949 "sigs.k8s.io/controller-runtime/pkg/envtest"
50+ metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
5051 "sigs.k8s.io/controller-runtime/pkg/webhook"
5152
5253 infrav1 "github.com/syself/cluster-api-provider-hetzner/api/v1beta1"
@@ -145,6 +146,10 @@ func NewTestEnvironment() *TestEnvironment {
145146 Host : "localhost" ,
146147 },
147148 ),
149+ Metrics : metricsserver.Options {
150+ // Disable MetricsServer, so that two tests processes can run concurrently
151+ BindAddress : "0" ,
152+ },
148153 })
149154 if err != nil {
150155 klog .Fatalf ("unable to create manager: %s" , err )
Original file line number Diff line number Diff line change @@ -95,8 +95,14 @@ func initializeWebhookInEnvironment() {
9595 klog .Fatalf ("Failed to append core controller webhook config: %v" , err )
9696 }
9797
98+ // Two tests processes should be able ro run concurrently. Each needs an own port:
99+ port , err := getFreePort ()
100+ if err != nil {
101+ klog .Fatalf ("Failed to get a free port for webhook: %v" , err )
102+ }
103+
98104 env .WebhookInstallOptions = envtest.WebhookInstallOptions {
99- LocalServingPort : 9443 ,
105+ LocalServingPort : port ,
100106 LocalServingHost : "localhost" ,
101107 MaxTime : 20 * time .Second ,
102108 PollInterval : time .Second ,
@@ -126,3 +132,13 @@ func (t *TestEnvironment) WaitForWebhooks() {
126132 return
127133 }
128134}
135+
136+ func getFreePort () (port int , err error ) {
137+ ln , err := net .Listen ("tcp" , "[::]:0" )
138+ if err != nil {
139+ return 0 , err
140+ }
141+ port = ln .Addr ().(* net.TCPAddr ).Port
142+ err = ln .Close ()
143+ return
144+ }
You can’t perform that action at this time.
0 commit comments