File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ var env *Environment
33
33
34
34
var _ = BeforeSuite (func (done Done ) {
35
35
logf .SetLogger (logf .ZapLoggerTo (GinkgoWriter , true ))
36
- env = & Environment {}
36
+ env = NewEnvironment ()
37
37
_ , err := env .Start ()
38
38
Expect (err ).NotTo (HaveOccurred ())
39
39
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import (
20
20
"fmt"
21
21
"os"
22
22
"path/filepath"
23
+ "strings"
23
24
"time"
24
25
25
26
apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
@@ -30,6 +31,7 @@ import (
30
31
31
32
// Default binary path for test framework
32
33
const (
34
+ envUseExistingCluster = "USE_EXISTING_CLUSTER"
33
35
envKubeAPIServerBin = "TEST_ASSET_KUBE_APISERVER"
34
36
envEtcdBin = "TEST_ASSET_ETCD"
35
37
envKubectlBin = "TEST_ASSET_KUBECTL"
@@ -97,6 +99,26 @@ type Environment struct {
97
99
KubeAPIServerFlags []string
98
100
}
99
101
102
+ // NewEnvironment creates a new instance of the Kubernetes test environment, and configures it
103
+ // to use the existing cluster as defined in the current `~/.kube/config` profile if
104
+ // the environment variable flag is set to `true`
105
+ func NewEnvironment (crds ... string ) * Environment {
106
+ useExisting := strings .ToLower (os .Getenv (envUseExistingCluster )) == "true"
107
+
108
+ e := & Environment {
109
+ UseExistingCluster : useExisting ,
110
+ }
111
+
112
+ // we do not load CRD's when using existing cluster
113
+ if useExisting {
114
+ return e
115
+ }
116
+
117
+ // set CRD's paths
118
+ e .CRDDirectoryPaths = crds
119
+ return e
120
+ }
121
+
100
122
// Stop stops a running server
101
123
func (te * Environment ) Stop () error {
102
124
if te .UseExistingCluster {
You can’t perform that action at this time.
0 commit comments