Skip to content

Commit

Permalink
Make start and stop timeouts for test controlplane configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
alvaroaleman committed Oct 6, 2018
1 parent ddf0390 commit 23ec656
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions pkg/envtest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ limitations under the License.
package envtest

import (
"fmt"
"os"
"path/filepath"
"strconv"
"time"

apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
"k8s.io/client-go/rest"
Expand All @@ -32,6 +35,8 @@ const (
envEtcdBin = "TEST_ASSET_ETCD"
envKubectlBin = "TEST_ASSET_KUBECTL"
envKubebuilderPath = "KUBEBUILDER_ASSETS"
envStartTimeout = "KUBEBUILDER_CONTROLPLANE_START_TIMEOUT"
envStopTimeout = "KUBEBUILDER_CONTROLPLANE_STOP_TIMEOUT"
defaultKubebuilderPath = "/usr/local/kubebuilder/bin"
StartTimeout = 60
StopTimeout = 60
Expand Down Expand Up @@ -102,6 +107,7 @@ func (te *Environment) Start() (*rest.Config, error) {
} else {
te.ControlPlane = integration.ControlPlane{}
te.ControlPlane.APIServer = &integration.APIServer{Args: defaultKubeAPIServerFlags}

if os.Getenv(envKubeAPIServerBin) == "" {
te.ControlPlane.APIServer.Path = defaultAssetPath("kube-apiserver")
}
Expand All @@ -115,6 +121,15 @@ func (te *Environment) Start() (*rest.Config, error) {
}
}

startTimeout, stopTimeout, err := getTimeouts()
if err != nil {
return nil, fmt.Errorf("failed to get timeouts: %v", err)
}
te.ControlPlane.Etcd.StartTimeout = startTimeout
te.ControlPlane.Etcd.StopTimeout = stopTimeout
te.ControlPlane.APIServer.StartTimeout = startTimeout
te.ControlPlane.APIServer.StopTimeout = stopTimeout

// Start the control plane - retry if it fails
if err := te.ControlPlane.Start(); err != nil {
return nil, err
Expand All @@ -132,3 +147,22 @@ func (te *Environment) Start() (*rest.Config, error) {
})
return te.Config, err
}

func getTimeouts() (time.Duration, time.Duration, error) {
var startTimeout, stopTimeout time.Duration
if envVal := os.Getenv(envStartTimeout); envVal != "" {
converted, err := strconv.Atoi(envVal)
if err != nil {
return startTimeout, stopTimeout, err
}
startTimeout = time.Duration(converted)
}
if envVal := os.Getenv(envStopTimeout); envVal != "" {
converted, err := strconv.Atoi(envVal)
if err != nil {
return startTimeout, stopTimeout, err
}
stopTimeout = time.Duration(converted)
}
return startTimeout, stopTimeout, nil
}

0 comments on commit 23ec656

Please sign in to comment.