Skip to content

Commit 24a75dd

Browse files
✨ allow pass the assets path via the enviroment config
1 parent a8d801f commit 24a75dd

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

pkg/envtest/server.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,17 @@ const (
6262
defaultKubebuilderControlPlaneStopTimeout = 20 * time.Second
6363
)
6464

65-
// Default binary path for test framework
66-
func defaultAssetPath(binary string) string {
67-
assetPath := os.Getenv(envKubebuilderPath)
68-
if assetPath == "" {
69-
assetPath = defaultKubebuilderPath
65+
// getBinAssetPath will return the path for the binary informed
66+
func (te *Environment) getBinAssetPath(binary string) string {
67+
if te.AbsBinaryDirectory != "" {
68+
return filepath.Join(te.AbsBinaryDirectory, binary)
7069
}
71-
return filepath.Join(assetPath, binary)
7270

71+
valueFromEnvVar := os.Getenv(envKubebuilderPath)
72+
if valueFromEnvVar != "" {
73+
return filepath.Join(valueFromEnvVar, binary)
74+
}
75+
return filepath.Join(defaultKubebuilderPath, binary)
7376
}
7477

7578
// ControlPlane is the re-exported ControlPlane type from the internal integration package
@@ -113,6 +116,10 @@ type Environment struct {
113116
// values are merged.
114117
CRDDirectoryPaths []string
115118

119+
// AbsBinaryDirectory is the path where the binaries required for the envtest are
120+
// locate in the environment
121+
AbsBinaryDirectory string
122+
116123
// UseExisting indicates that this environments should use an
117124
// existing kubeconfig, instead of trying to stand up a new control plane.
118125
// This is useful in cases that need aggregated API servers and the like.
@@ -217,14 +224,14 @@ func (te *Environment) Start() (*rest.Config, error) {
217224
}
218225

219226
if os.Getenv(envKubeAPIServerBin) == "" {
220-
te.ControlPlane.APIServer.Path = defaultAssetPath("kube-apiserver")
227+
te.ControlPlane.APIServer.Path = te.getBinAssetPath("kube-apiserver")
221228
}
222229
if os.Getenv(envEtcdBin) == "" {
223-
te.ControlPlane.Etcd.Path = defaultAssetPath("etcd")
230+
te.ControlPlane.Etcd.Path = te.getBinAssetPath("etcd")
224231
}
225232
if os.Getenv(envKubectlBin) == "" {
226233
// we can't just set the path manually (it's behind a function), so set the environment variable instead
227-
if err := os.Setenv(envKubectlBin, defaultAssetPath("kubectl")); err != nil {
234+
if err := os.Setenv(envKubectlBin, te.getBinAssetPath("kubectl")); err != nil {
228235
return nil, err
229236
}
230237
}

0 commit comments

Comments
 (0)