Skip to content

✨ Allow setting "UseExistingCluster" via environment #223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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