Skip to content

Commit

Permalink
✨ make UseExistingCluster a pointer to support explicitly opt-out in …
Browse files Browse the repository at this point in the history
…the code
  • Loading branch information
adohe committed Jun 2, 2019
1 parent bce1e17 commit 7005c81
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions pkg/envtest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ type Environment struct {
// UseExisting indicates that this environments should use an
// existing kubeconfig, instead of trying to stand up a new control plane.
// This is useful in cases that need aggregated API servers and the like.
UseExistingCluster bool
UseExistingCluster *bool

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

// Stop stops a running server
func (te *Environment) Stop() error {
if te.UseExistingCluster {
if te.UseExistingCluster != nil && *te.UseExistingCluster {
return nil
}
return te.ControlPlane.Stop()
Expand All @@ -130,11 +130,8 @@ func (te Environment) getAPIServerFlags() []string {

// Start starts a local Kubernetes server and updates te.ApiserverPort with the port it is listening on
func (te *Environment) Start() (*rest.Config, error) {
if !te.UseExistingCluster {
// Check USE_EXISTING_CLUSTER env then
te.UseExistingCluster = strings.ToLower(os.Getenv(envUseExistingCluster)) == "true"
}
if te.UseExistingCluster {
useExistingCluster := te.useExistingCluster()
if useExistingCluster {
log.V(1).Info("using existing cluster")
if te.Config == nil {
// we want to allow people to pass in their own config, so
Expand Down Expand Up @@ -256,3 +253,11 @@ func (te *Environment) defaultTimeouts() error {
}
return nil
}

func (te *Environment) useExistingCluster() bool {
if te.UseExistingCluster == nil {
useExistingCluster := strings.ToLower(os.Getenv(envUseExistingCluster)) == "true"
te.UseExistingCluster = &useExistingCluster
}
return *te.UseExistingCluster == true
}

0 comments on commit 7005c81

Please sign in to comment.