@@ -90,7 +90,7 @@ type Environment struct {
90
90
// UseExisting indicates that this environments should use an
91
91
// existing kubeconfig, instead of trying to stand up a new control plane.
92
92
// This is useful in cases that need aggregated API servers and the like.
93
- UseExistingCluster bool
93
+ UseExistingCluster * bool
94
94
95
95
// ControlPlaneStartTimeout is the maximum duration each controlplane component
96
96
// may take to start. It defaults to the KUBEBUILDER_CONTROLPLANE_START_TIMEOUT
@@ -113,7 +113,7 @@ type Environment struct {
113
113
114
114
// Stop stops a running server
115
115
func (te * Environment ) Stop () error {
116
- if te .UseExistingCluster {
116
+ if te .UseExistingCluster != nil && * te . UseExistingCluster {
117
117
return nil
118
118
}
119
119
return te .ControlPlane .Stop ()
@@ -130,11 +130,8 @@ func (te Environment) getAPIServerFlags() []string {
130
130
131
131
// Start starts a local Kubernetes server and updates te.ApiserverPort with the port it is listening on
132
132
func (te * Environment ) Start () (* rest.Config , error ) {
133
- if ! te .UseExistingCluster {
134
- // Check USE_EXISTING_CLUSTER env then
135
- te .UseExistingCluster = strings .ToLower (os .Getenv (envUseExistingCluster )) == "true"
136
- }
137
- if te .UseExistingCluster {
133
+ useExistingCluster := te .useExistingCluster ()
134
+ if useExistingCluster {
138
135
log .V (1 ).Info ("using existing cluster" )
139
136
if te .Config == nil {
140
137
// we want to allow people to pass in their own config, so
@@ -256,3 +253,11 @@ func (te *Environment) defaultTimeouts() error {
256
253
}
257
254
return nil
258
255
}
256
+
257
+ func (te * Environment ) useExistingCluster () bool {
258
+ if te .UseExistingCluster == nil {
259
+ useExistingCluster := strings .ToLower (os .Getenv (envUseExistingCluster )) == "true"
260
+ te .UseExistingCluster = & useExistingCluster
261
+ }
262
+ return * te .UseExistingCluster == true
263
+ }
0 commit comments