Skip to content

Commit d90ab12

Browse files
author
Mengqi Yu
committed
✨ more visibility of the testing control plane
Support bridging the control plane output to the stdout and stderr
1 parent b56d269 commit d90ab12

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

pkg/envtest/server.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const (
4242
envKubebuilderPath = "KUBEBUILDER_ASSETS"
4343
envStartTimeout = "KUBEBUILDER_CONTROLPLANE_START_TIMEOUT"
4444
envStopTimeout = "KUBEBUILDER_CONTROLPLANE_STOP_TIMEOUT"
45+
envAttachOutput = "KUBEBUILDER_ATTACH_CONTROL_PLANE_OUTPUT"
4546
defaultKubebuilderPath = "/usr/local/kubebuilder/bin"
4647
StartTimeout = 60
4748
StopTimeout = 60
@@ -103,6 +104,11 @@ type Environment struct {
103104

104105
// KubeAPIServerFlags is the set of flags passed while starting the api server.
105106
KubeAPIServerFlags []string
107+
108+
// AttachControlPlaneOutput indicates if control plane output will be attached to os.Stdout and os.Stderr.
109+
// Enable this to get more visibility of the testing control plane.
110+
// It respect KUBEBUILDER_ATTACH_CONTROL_PLANE_OUTPUT environment variable.
111+
AttachControlPlaneOutput bool
106112
}
107113

108114
// Stop stops a running server
@@ -143,8 +149,28 @@ func (te *Environment) Start() (*rest.Config, error) {
143149
}
144150
} else {
145151
te.ControlPlane = integration.ControlPlane{}
146-
te.ControlPlane.APIServer = &integration.APIServer{Args: te.getAPIServerFlags()}
147-
te.ControlPlane.Etcd = &integration.Etcd{}
152+
if te.ControlPlane.APIServer == nil {
153+
te.ControlPlane.APIServer = &integration.APIServer{Args: te.getAPIServerFlags()}
154+
}
155+
if te.ControlPlane.Etcd == nil {
156+
te.ControlPlane.Etcd = &integration.Etcd{}
157+
}
158+
159+
if os.Getenv(envAttachOutput) == "true" {
160+
te.AttachControlPlaneOutput = true
161+
}
162+
if te.ControlPlane.APIServer.Out == nil && te.AttachControlPlaneOutput {
163+
te.ControlPlane.APIServer.Out = os.Stdout
164+
}
165+
if te.ControlPlane.APIServer.Err == nil && te.AttachControlPlaneOutput {
166+
te.ControlPlane.APIServer.Err = os.Stderr
167+
}
168+
if te.ControlPlane.Etcd.Out == nil && te.AttachControlPlaneOutput {
169+
te.ControlPlane.Etcd.Out = os.Stdout
170+
}
171+
if te.ControlPlane.Etcd.Err == nil && te.AttachControlPlaneOutput {
172+
te.ControlPlane.Etcd.Err = os.Stderr
173+
}
148174

149175
if os.Getenv(envKubeAPIServerBin) == "" {
150176
te.ControlPlane.APIServer.Path = defaultAssetPath("kube-apiserver")

0 commit comments

Comments
 (0)