@@ -40,6 +40,7 @@ const (
40
40
envKubebuilderPath = "KUBEBUILDER_ASSETS"
41
41
envStartTimeout = "KUBEBUILDER_CONTROLPLANE_START_TIMEOUT"
42
42
envStopTimeout = "KUBEBUILDER_CONTROLPLANE_STOP_TIMEOUT"
43
+ envAttachOutput = "KUBEBUILDER_ATTACH_CONTROL_PLANE_OUTPUT"
43
44
defaultKubebuilderPath = "/usr/local/kubebuilder/bin"
44
45
StartTimeout = 60
45
46
StopTimeout = 60
@@ -99,6 +100,11 @@ type Environment struct {
99
100
100
101
// KubeAPIServerFlags is the set of flags passed while starting the api server.
101
102
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
102
108
}
103
109
104
110
// Stop stops a running server
@@ -119,7 +125,7 @@ func (te Environment) getAPIServerFlags() []string {
119
125
}
120
126
121
127
// 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
123
129
if te .UseExistingCluster {
124
130
log .V (1 ).Info ("using existing cluster" )
125
131
if te .Config == nil {
@@ -134,9 +140,28 @@ func (te *Environment) Start() (*rest.Config, error) {
134
140
}
135
141
}
136
142
} 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
+ }
140
165
141
166
if os .Getenv (envKubeAPIServerBin ) == "" {
142
167
te .ControlPlane .APIServer .Path = defaultAssetPath ("kube-apiserver" )
0 commit comments