@@ -17,8 +17,11 @@ limitations under the License.
17
17
package envtest
18
18
19
19
import (
20
+ "fmt"
20
21
"os"
21
22
"path/filepath"
23
+ "strconv"
24
+ "time"
22
25
23
26
apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
24
27
"k8s.io/client-go/rest"
@@ -32,6 +35,8 @@ const (
32
35
envEtcdBin = "TEST_ASSET_ETCD"
33
36
envKubectlBin = "TEST_ASSET_KUBECTL"
34
37
envKubebuilderPath = "KUBEBUILDER_ASSETS"
38
+ envStartTimeout = "KUBEBUILDER_CONTROLPLANE_START_TIMEOUT"
39
+ envStopTimeout = "KUBEBUILDER_CONTROLPLANE_STOP_TIMEOUT"
35
40
defaultKubebuilderPath = "/usr/local/kubebuilder/bin"
36
41
StartTimeout = 60
37
42
StopTimeout = 60
@@ -102,6 +107,7 @@ func (te *Environment) Start() (*rest.Config, error) {
102
107
} else {
103
108
te .ControlPlane = integration.ControlPlane {}
104
109
te .ControlPlane .APIServer = & integration.APIServer {Args : defaultKubeAPIServerFlags }
110
+
105
111
if os .Getenv (envKubeAPIServerBin ) == "" {
106
112
te .ControlPlane .APIServer .Path = defaultAssetPath ("kube-apiserver" )
107
113
}
@@ -115,6 +121,15 @@ func (te *Environment) Start() (*rest.Config, error) {
115
121
}
116
122
}
117
123
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
+
118
133
// Start the control plane - retry if it fails
119
134
if err := te .ControlPlane .Start (); err != nil {
120
135
return nil , err
@@ -132,3 +147,22 @@ func (te *Environment) Start() (*rest.Config, error) {
132
147
})
133
148
return te .Config , err
134
149
}
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