Skip to content

Commit

Permalink
Allow setting UseExistingCluster via environment
Browse files Browse the repository at this point in the history
  • Loading branch information
ichekrygin committed Nov 24, 2018
1 parent 85a065f commit 3daf63b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/envtest/envtest_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var env *Environment

var _ = BeforeSuite(func(done Done) {
logf.SetLogger(logf.ZapLoggerTo(GinkgoWriter, true))
env = &Environment{}
env = NewEnvironment()
_, err := env.Start()
Expect(err).NotTo(HaveOccurred())

Expand Down
22 changes: 22 additions & 0 deletions pkg/envtest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"time"

apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
Expand All @@ -30,6 +31,7 @@ import (

// Default binary path for test framework
const (
envUseExistingCluster = "USE_EXISTING_CLUSTER"
envKubeAPIServerBin = "TEST_ASSET_KUBE_APISERVER"
envEtcdBin = "TEST_ASSET_ETCD"
envKubectlBin = "TEST_ASSET_KUBECTL"
Expand Down Expand Up @@ -97,6 +99,26 @@ type Environment struct {
KubeAPIServerFlags []string
}

// NewEnvironment creates a new instance of the Kubernetes test environment, and configures it
// to use the existing cluster as defined in the current `~/.kube/config` profile if
// the environment variable flag is set to `true`
func NewEnvironment(crds ...string) *Environment {
useExisting := strings.ToLower(os.Getenv(envUseExistingCluster)) == "true"

e := &Environment{
UseExistingCluster: useExisting,
}

// we do not load CRD's when using existing cluster
if useExisting {
return e
}

// set CRD's paths
e.CRDDirectoryPaths = crds
return e
}

// Stop stops a running server
func (te *Environment) Stop() error {
if te.UseExistingCluster {
Expand Down

0 comments on commit 3daf63b

Please sign in to comment.