@@ -109,7 +109,11 @@ var (
109109// Environment creates a Kubernetes test environment that will start / stop the Kubernetes control plane and
110110// install extension APIs.
111111type Environment struct {
112- // ControlPlane is the ControlPlane including the apiserver and etcd
112+ // ControlPlane is the ControlPlane including the apiserver and etcd.
113+ // Binary paths (APIServer.Path, Etcd.Path, KubectlPath) can be pre-configured in ControlPlane.
114+ // If DownloadBinaryAssets is true, the downloaded paths will always be used.
115+ // If DownloadBinaryAssets is false and paths are not pre-configured (default is empty), they will be
116+ // automatically resolved using BinaryAssetsDirectory.
113117 ControlPlane controlplane.ControlPlane
114118
115119 // Scheme is used to determine if conversion webhooks should be enabled
@@ -211,6 +215,40 @@ func (te *Environment) Stop() error {
211215 return te .ControlPlane .Stop ()
212216}
213217
218+ // configureBinaryPaths configures the binary paths for the API server, etcd, and kubectl.
219+ // If DownloadBinaryAssets is true, it downloads and uses those paths.
220+ // If DownloadBinaryAssets is false, it only sets paths that are not already configured (empty).
221+ func (te * Environment ) configureBinaryPaths () error {
222+ apiServer := te .ControlPlane .GetAPIServer ()
223+
224+ if te .ControlPlane .Etcd == nil {
225+ te .ControlPlane .Etcd = & controlplane.Etcd {}
226+ }
227+
228+ if te .DownloadBinaryAssets {
229+ apiServerPath , etcdPath , kubectlPath , err := downloadBinaryAssets (context .TODO (),
230+ te .BinaryAssetsDirectory , te .DownloadBinaryAssetsVersion , te .DownloadBinaryAssetsIndexURL )
231+ if err != nil {
232+ return err
233+ }
234+
235+ apiServer .Path = apiServerPath
236+ te .ControlPlane .Etcd .Path = etcdPath
237+ te .ControlPlane .KubectlPath = kubectlPath
238+ } else {
239+ if apiServer .Path == "" {
240+ apiServer .Path = process .BinPathFinder ("kube-apiserver" , te .BinaryAssetsDirectory )
241+ }
242+ if te .ControlPlane .Etcd .Path == "" {
243+ te .ControlPlane .Etcd .Path = process .BinPathFinder ("etcd" , te .BinaryAssetsDirectory )
244+ }
245+ if te .ControlPlane .KubectlPath == "" {
246+ te .ControlPlane .KubectlPath = process .BinPathFinder ("kubectl" , te .BinaryAssetsDirectory )
247+ }
248+ }
249+ return nil
250+ }
251+
214252// Start starts a local Kubernetes server and updates te.ApiserverPort with the port it is listening on.
215253func (te * Environment ) Start () (* rest.Config , error ) {
216254 if te .useExistingCluster () {
@@ -229,10 +267,6 @@ func (te *Environment) Start() (*rest.Config, error) {
229267 } else {
230268 apiServer := te .ControlPlane .GetAPIServer ()
231269
232- if te .ControlPlane .Etcd == nil {
233- te .ControlPlane .Etcd = & controlplane.Etcd {}
234- }
235-
236270 if os .Getenv (envAttachOutput ) == "true" {
237271 te .AttachControlPlaneOutput = true
238272 }
@@ -243,6 +277,9 @@ func (te *Environment) Start() (*rest.Config, error) {
243277 if apiServer .Err == nil {
244278 apiServer .Err = os .Stderr
245279 }
280+ if te .ControlPlane .Etcd == nil {
281+ te .ControlPlane .Etcd = & controlplane.Etcd {}
282+ }
246283 if te .ControlPlane .Etcd .Out == nil {
247284 te .ControlPlane .Etcd .Out = os .Stdout
248285 }
@@ -251,20 +288,8 @@ func (te *Environment) Start() (*rest.Config, error) {
251288 }
252289 }
253290
254- if te .DownloadBinaryAssets {
255- apiServerPath , etcdPath , kubectlPath , err := downloadBinaryAssets (context .TODO (),
256- te .BinaryAssetsDirectory , te .DownloadBinaryAssetsVersion , te .DownloadBinaryAssetsIndexURL )
257- if err != nil {
258- return nil , err
259- }
260-
261- apiServer .Path = apiServerPath
262- te .ControlPlane .Etcd .Path = etcdPath
263- te .ControlPlane .KubectlPath = kubectlPath
264- } else {
265- apiServer .Path = process .BinPathFinder ("kube-apiserver" , te .BinaryAssetsDirectory )
266- te .ControlPlane .Etcd .Path = process .BinPathFinder ("etcd" , te .BinaryAssetsDirectory )
267- te .ControlPlane .KubectlPath = process .BinPathFinder ("kubectl" , te .BinaryAssetsDirectory )
291+ if err := te .configureBinaryPaths (); err != nil {
292+ return nil , fmt .Errorf ("failed to configure binary paths: %w" , err )
268293 }
269294
270295 if err := te .defaultTimeouts (); err != nil {
0 commit comments