Skip to content

Commit

Permalink
Refactor kubebuilder integration test start
Browse files Browse the repository at this point in the history
- Check ENV and applying default binary path for apiserver, etcd under "/usr/local/kubebuilder/bin" befor starting Kubernetes server.
  So that no need to set TEST_ASSET for testing framework.
- For KubeCtl wrapper, keep TEST_ASSET set at this moment.
  • Loading branch information
fanzhangio committed May 2, 2018
1 parent 07508ce commit 239d771
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
21 changes: 18 additions & 3 deletions pkg/test/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,21 @@ limitations under the License.
package test

import (
"os"
"time"

"github.com/kubernetes-sigs/kubebuilder/pkg/install"
extensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
"k8s.io/client-go/rest"

"sigs.k8s.io/testing_frameworks/integration"
"github.com/kubernetes-sigs/kubebuilder/pkg/install"
)

// Default binary path for test framework
const (
envKubeAPIServerBin = "TEST_ASSET_KUBE_APISERVER"
envEtcdBin = "TEST_ASSET_ETCD"
defaultKubeAPIServerBin = "/usr/local/kubebuilder/bin/kube-apiserver"
defaultEtcdBin = "/usr/local/kubebuilder/bin/etcd"
)

// TestEnvironment creates a Kubernetes test environment that will start / stop the Kubernetes control plane and
Expand All @@ -41,14 +49,21 @@ func (te *TestEnvironment) Stop() {

// Start starts a local Kubernetes server and updates te.ApiserverPort with the port it is listening on
func (te *TestEnvironment) Start() (*rest.Config, error) {
te.ControlPlane = integration.ControlPlane{}
if os.Getenv(envKubeAPIServerBin) == "" {
te.ControlPlane.APIServer = &integration.APIServer{Path: defaultKubeAPIServerBin}
}
if os.Getenv(envEtcdBin) == "" {
te.ControlPlane.Etcd = &integration.Etcd{Path: defaultEtcdBin}
}

// Start the control plane - retry if it fails
var err error
for i := 0; i < 5; i++ {
err = te.ControlPlane.Start()
if err == nil {
break
}
te.ControlPlane = integration.ControlPlane{}
}
// Give up trying to start the control plane
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ function test_generated_controller {
# Verify the controller-manager builds and the tests pass
go build ./cmd/...
go build ./pkg/...
go test ./cmd/...
go test ./pkg/...
go test -v ./cmd/...
go test -v ./pkg/...
}

prepare_staging_dir
Expand Down

0 comments on commit 239d771

Please sign in to comment.