Skip to content

Commit dc633c5

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

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

pkg/envtest/server.go

Lines changed: 32 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,20 @@ func (te *Environment) Start() (*rest.Config, error) {
132147
})
133148
return te.Config, err
134149
}
150+
151+
func getTimeouts() (startTimeout, stopTimeout time.Duration, err error) {
152+
var converted int
153+
if envVal := os.Getenv(envStartTimeout); envVal != "" {
154+
if converted, err = strconv.Atoi(envVal); err != nil {
155+
return
156+
}
157+
startTimeout = time.Duration(converted)
158+
}
159+
if envVal := os.Getenv(envStopTimeout); envVal != "" {
160+
if converted, err = strconv.Atoi(envVal); err != nil {
161+
return
162+
}
163+
stopTimeout = time.Duration(converted)
164+
}
165+
return
166+
}

0 commit comments

Comments
 (0)