Skip to content

Commit

Permalink
Merge pull request #99 from fanzhangio/issue50
Browse files Browse the repository at this point in the history
Add binary path in testEnvironment for kubebuilder integration test
  • Loading branch information
droot authored May 2, 2018
2 parents 73fb5b2 + 239d771 commit fd34223
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 fd34223

Please sign in to comment.