Skip to content

Commit dde0076

Browse files
authored
Merge pull request #710 from Random-Liu/cherrypick-#459-release-0.1
✨ more visibility of the testing control plane
2 parents f1eaba5 + 3efda05 commit dde0076

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

pkg/envtest/server.go

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const (
4040
envKubebuilderPath = "KUBEBUILDER_ASSETS"
4141
envStartTimeout = "KUBEBUILDER_CONTROLPLANE_START_TIMEOUT"
4242
envStopTimeout = "KUBEBUILDER_CONTROLPLANE_STOP_TIMEOUT"
43+
envAttachOutput = "KUBEBUILDER_ATTACH_CONTROL_PLANE_OUTPUT"
4344
defaultKubebuilderPath = "/usr/local/kubebuilder/bin"
4445
StartTimeout = 60
4546
StopTimeout = 60
@@ -99,6 +100,11 @@ type Environment struct {
99100

100101
// KubeAPIServerFlags is the set of flags passed while starting the api server.
101102
KubeAPIServerFlags []string
103+
104+
// AttachControlPlaneOutput indicates if control plane output will be attached to os.Stdout and os.Stderr.
105+
// Enable this to get more visibility of the testing control plane.
106+
// It respect KUBEBUILDER_ATTACH_CONTROL_PLANE_OUTPUT environment variable.
107+
AttachControlPlaneOutput bool
102108
}
103109

104110
// Stop stops a running server
@@ -119,7 +125,7 @@ func (te Environment) getAPIServerFlags() []string {
119125
}
120126

121127
// Start starts a local Kubernetes server and updates te.ApiserverPort with the port it is listening on
122-
func (te *Environment) Start() (*rest.Config, error) {
128+
func (te *Environment) Start() (*rest.Config, error) { // nolint: gocyclo
123129
if te.UseExistingCluster {
124130
log.V(1).Info("using existing cluster")
125131
if te.Config == nil {
@@ -134,9 +140,28 @@ func (te *Environment) Start() (*rest.Config, error) {
134140
}
135141
}
136142
} else {
137-
te.ControlPlane = integration.ControlPlane{}
138-
te.ControlPlane.APIServer = &integration.APIServer{Args: te.getAPIServerFlags()}
139-
te.ControlPlane.Etcd = &integration.Etcd{}
143+
if te.ControlPlane.APIServer == nil {
144+
te.ControlPlane.APIServer = &integration.APIServer{Args: te.getAPIServerFlags()}
145+
}
146+
if te.ControlPlane.Etcd == nil {
147+
te.ControlPlane.Etcd = &integration.Etcd{}
148+
}
149+
150+
if os.Getenv(envAttachOutput) == "true" {
151+
te.AttachControlPlaneOutput = true
152+
}
153+
if te.ControlPlane.APIServer.Out == nil && te.AttachControlPlaneOutput {
154+
te.ControlPlane.APIServer.Out = os.Stdout
155+
}
156+
if te.ControlPlane.APIServer.Err == nil && te.AttachControlPlaneOutput {
157+
te.ControlPlane.APIServer.Err = os.Stderr
158+
}
159+
if te.ControlPlane.Etcd.Out == nil && te.AttachControlPlaneOutput {
160+
te.ControlPlane.Etcd.Out = os.Stdout
161+
}
162+
if te.ControlPlane.Etcd.Err == nil && te.AttachControlPlaneOutput {
163+
te.ControlPlane.Etcd.Err = os.Stderr
164+
}
140165

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

0 commit comments

Comments
 (0)