Skip to content

Commit 23ec656

Browse files
committed
Make start and stop timeouts for test controlplane configurable
1 parent ddf0390 commit 23ec656

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

pkg/envtest/server.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ limitations under the License.
1717
package envtest
1818

1919
import (
20+
"fmt"
2021
"os"
2122
"path/filepath"
23+
"strconv"
24+
"time"
2225

2326
apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
2427
"k8s.io/client-go/rest"
@@ -32,6 +35,8 @@ const (
3235
envEtcdBin = "TEST_ASSET_ETCD"
3336
envKubectlBin = "TEST_ASSET_KUBECTL"
3437
envKubebuilderPath = "KUBEBUILDER_ASSETS"
38+
envStartTimeout = "KUBEBUILDER_CONTROLPLANE_START_TIMEOUT"
39+
envStopTimeout = "KUBEBUILDER_CONTROLPLANE_STOP_TIMEOUT"
3540
defaultKubebuilderPath = "/usr/local/kubebuilder/bin"
3641
StartTimeout = 60
3742
StopTimeout = 60
@@ -102,6 +107,7 @@ func (te *Environment) Start() (*rest.Config, error) {
102107
} else {
103108
te.ControlPlane = integration.ControlPlane{}
104109
te.ControlPlane.APIServer = &integration.APIServer{Args: defaultKubeAPIServerFlags}
110+
105111
if os.Getenv(envKubeAPIServerBin) == "" {
106112
te.ControlPlane.APIServer.Path = defaultAssetPath("kube-apiserver")
107113
}
@@ -115,6 +121,15 @@ func (te *Environment) Start() (*rest.Config, error) {
115121
}
116122
}
117123

124+
startTimeout, stopTimeout, err := getTimeouts()
125+
if err != nil {
126+
return nil, fmt.Errorf("failed to get timeouts: %v", err)
127+
}
128+
te.ControlPlane.Etcd.StartTimeout = startTimeout
129+
te.ControlPlane.Etcd.StopTimeout = stopTimeout
130+
te.ControlPlane.APIServer.StartTimeout = startTimeout
131+
te.ControlPlane.APIServer.StopTimeout = stopTimeout
132+
118133
// Start the control plane - retry if it fails
119134
if err := te.ControlPlane.Start(); err != nil {
120135
return nil, err
@@ -132,3 +147,22 @@ func (te *Environment) Start() (*rest.Config, error) {
132147
})
133148
return te.Config, err
134149
}
150+
151+
func getTimeouts() (time.Duration, time.Duration, error) {
152+
var startTimeout, stopTimeout time.Duration
153+
if envVal := os.Getenv(envStartTimeout); envVal != "" {
154+
converted, err := strconv.Atoi(envVal)
155+
if err != nil {
156+
return startTimeout, stopTimeout, err
157+
}
158+
startTimeout = time.Duration(converted)
159+
}
160+
if envVal := os.Getenv(envStopTimeout); envVal != "" {
161+
converted, err := strconv.Atoi(envVal)
162+
if err != nil {
163+
return startTimeout, stopTimeout, err
164+
}
165+
stopTimeout = time.Duration(converted)
166+
}
167+
return startTimeout, stopTimeout, nil
168+
}

0 commit comments

Comments
 (0)