@@ -62,14 +62,17 @@ const (
62
62
defaultKubebuilderControlPlaneStopTimeout = 20 * time .Second
63
63
)
64
64
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 hasBinary (binary , te .BinaryDirectoryPath ) {
68
+ return filepath .Join (te .BinaryDirectoryPath , binary )
70
69
}
71
- return filepath .Join (assetPath , binary )
72
70
71
+ valueFromEnvVar := os .Getenv (envKubebuilderPath )
72
+ if hasBinary (binary , valueFromEnvVar ) {
73
+ return filepath .Join (valueFromEnvVar , binary )
74
+ }
75
+ return filepath .Join (defaultKubebuilderPath , binary )
73
76
}
74
77
75
78
// ControlPlane is the re-exported ControlPlane type from the internal integration package
@@ -113,6 +116,10 @@ type Environment struct {
113
116
// values are merged.
114
117
CRDDirectoryPaths []string
115
118
119
+ // BinaryDirectoryPath is the path where the binaries required for the envtest are
120
+ // locate in the environment
121
+ BinaryDirectoryPath string
122
+
116
123
// UseExisting indicates that this environments should use an
117
124
// existing kubeconfig, instead of trying to stand up a new control plane.
118
125
// This is useful in cases that need aggregated API servers and the like.
@@ -217,14 +224,14 @@ func (te *Environment) Start() (*rest.Config, error) {
217
224
}
218
225
219
226
if os .Getenv (envKubeAPIServerBin ) == "" {
220
- te .ControlPlane .APIServer .Path = defaultAssetPath ("kube-apiserver" )
227
+ te .ControlPlane .APIServer .Path = te . getBinAssetPath ("kube-apiserver" )
221
228
}
222
229
if os .Getenv (envEtcdBin ) == "" {
223
- te .ControlPlane .Etcd .Path = defaultAssetPath ("etcd" )
230
+ te .ControlPlane .Etcd .Path = te . getBinAssetPath ("etcd" )
224
231
}
225
232
if os .Getenv (envKubectlBin ) == "" {
226
233
// 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 {
228
235
return nil , err
229
236
}
230
237
}
@@ -267,6 +274,14 @@ func (te *Environment) Start() (*rest.Config, error) {
267
274
return te .Config , err
268
275
}
269
276
277
+ // hasBinary will return true when the binary was found in the path
278
+ func hasBinary (bin , path string ) bool {
279
+ if _ , err := os .Stat (filepath .Join (path , bin )); os .IsNotExist (err ) {
280
+ return false
281
+ }
282
+ return true
283
+ }
284
+
270
285
func (te * Environment ) startControlPlane () error {
271
286
numTries , maxRetries := 0 , 5
272
287
var err error
0 commit comments