Skip to content
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

⚠️ make UseExistingCluster a pointer to support explicitly op… #463

Merged
Merged
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
17 changes: 10 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() {
return nil
}
return te.ControlPlane.Stop()
Expand All @@ -130,11 +130,7 @@ 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 {
if te.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 +252,10 @@ func (te *Environment) defaultTimeouts() error {
}
return nil
}

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