Skip to content

Commit c9aad37

Browse files
committed
✨ make UseExistingCluster a pointer to support explicitly opt-out in the code
1 parent bce1e17 commit c9aad37

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

pkg/envtest/server.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ type Environment struct {
9090
// UseExisting indicates that this environments should use an
9191
// existing kubeconfig, instead of trying to stand up a new control plane.
9292
// This is useful in cases that need aggregated API servers and the like.
93-
UseExistingCluster bool
93+
UseExistingCluster *bool
9494

9595
// ControlPlaneStartTimeout is the maximum duration each controlplane component
9696
// may take to start. It defaults to the KUBEBUILDER_CONTROLPLANE_START_TIMEOUT
@@ -113,7 +113,7 @@ type Environment struct {
113113

114114
// Stop stops a running server
115115
func (te *Environment) Stop() error {
116-
if te.UseExistingCluster {
116+
if te.useExistingCluster() {
117117
return nil
118118
}
119119
return te.ControlPlane.Stop()
@@ -130,11 +130,7 @@ func (te Environment) getAPIServerFlags() []string {
130130

131131
// Start starts a local Kubernetes server and updates te.ApiserverPort with the port it is listening on
132132
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+
if te.useExistingCluster() {
138134
log.V(1).Info("using existing cluster")
139135
if te.Config == nil {
140136
// we want to allow people to pass in their own config, so
@@ -256,3 +252,10 @@ func (te *Environment) defaultTimeouts() error {
256252
}
257253
return nil
258254
}
255+
256+
func (te *Environment) useExistingCluster() bool {
257+
if te.UseExistingCluster == nil {
258+
return strings.ToLower(os.Getenv(envUseExistingCluster)) == "true"
259+
}
260+
return *te.UseExistingCluster == true
261+
}

0 commit comments

Comments
 (0)