Skip to content

Commit bce1e17

Browse files
authored
Merge pull request #459 from mengqiy/controlplanevisibility
✨ more visibility of the testing control plane
2 parents 228ca93 + 267523b commit bce1e17

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

pkg/envtest/server.go

Lines changed: 28 additions & 3 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
@@ -142,9 +148,28 @@ func (te *Environment) Start() (*rest.Config, error) {
142148
}
143149
}
144150
} else {
145-
te.ControlPlane = integration.ControlPlane{}
146-
te.ControlPlane.APIServer = &integration.APIServer{Args: te.getAPIServerFlags()}
147-
te.ControlPlane.Etcd = &integration.Etcd{}
151+
if te.ControlPlane.APIServer == nil {
152+
te.ControlPlane.APIServer = &integration.APIServer{Args: te.getAPIServerFlags()}
153+
}
154+
if te.ControlPlane.Etcd == nil {
155+
te.ControlPlane.Etcd = &integration.Etcd{}
156+
}
157+
158+
if os.Getenv(envAttachOutput) == "true" {
159+
te.AttachControlPlaneOutput = true
160+
}
161+
if te.ControlPlane.APIServer.Out == nil && te.AttachControlPlaneOutput {
162+
te.ControlPlane.APIServer.Out = os.Stdout
163+
}
164+
if te.ControlPlane.APIServer.Err == nil && te.AttachControlPlaneOutput {
165+
te.ControlPlane.APIServer.Err = os.Stderr
166+
}
167+
if te.ControlPlane.Etcd.Out == nil && te.AttachControlPlaneOutput {
168+
te.ControlPlane.Etcd.Out = os.Stdout
169+
}
170+
if te.ControlPlane.Etcd.Err == nil && te.AttachControlPlaneOutput {
171+
te.ControlPlane.Etcd.Err = os.Stderr
172+
}
148173

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

0 commit comments

Comments
 (0)