diff --git a/pkg/envtest/server.go b/pkg/envtest/server.go index 86527f4198..2cfedd1e06 100644 --- a/pkg/envtest/server.go +++ b/pkg/envtest/server.go @@ -42,6 +42,7 @@ const ( envKubebuilderPath = "KUBEBUILDER_ASSETS" envStartTimeout = "KUBEBUILDER_CONTROLPLANE_START_TIMEOUT" envStopTimeout = "KUBEBUILDER_CONTROLPLANE_STOP_TIMEOUT" + envAttachOutput = "KUBEBUILDER_ATTACH_CONTROL_PLANE_OUTPUT" defaultKubebuilderPath = "/usr/local/kubebuilder/bin" StartTimeout = 60 StopTimeout = 60 @@ -103,6 +104,11 @@ type Environment struct { // KubeAPIServerFlags is the set of flags passed while starting the api server. KubeAPIServerFlags []string + + // AttachControlPlaneOutput indicates if control plane output will be attached to os.Stdout and os.Stderr. + // Enable this to get more visibility of the testing control plane. + // It respect KUBEBUILDER_ATTACH_CONTROL_PLANE_OUTPUT environment variable. + AttachControlPlaneOutput bool } // Stop stops a running server @@ -142,9 +148,28 @@ func (te *Environment) Start() (*rest.Config, error) { } } } else { - te.ControlPlane = integration.ControlPlane{} - te.ControlPlane.APIServer = &integration.APIServer{Args: te.getAPIServerFlags()} - te.ControlPlane.Etcd = &integration.Etcd{} + if te.ControlPlane.APIServer == nil { + te.ControlPlane.APIServer = &integration.APIServer{Args: te.getAPIServerFlags()} + } + if te.ControlPlane.Etcd == nil { + te.ControlPlane.Etcd = &integration.Etcd{} + } + + if os.Getenv(envAttachOutput) == "true" { + te.AttachControlPlaneOutput = true + } + if te.ControlPlane.APIServer.Out == nil && te.AttachControlPlaneOutput { + te.ControlPlane.APIServer.Out = os.Stdout + } + if te.ControlPlane.APIServer.Err == nil && te.AttachControlPlaneOutput { + te.ControlPlane.APIServer.Err = os.Stderr + } + if te.ControlPlane.Etcd.Out == nil && te.AttachControlPlaneOutput { + te.ControlPlane.Etcd.Out = os.Stdout + } + if te.ControlPlane.Etcd.Err == nil && te.AttachControlPlaneOutput { + te.ControlPlane.Etcd.Err = os.Stderr + } if os.Getenv(envKubeAPIServerBin) == "" { te.ControlPlane.APIServer.Path = defaultAssetPath("kube-apiserver")