@@ -62,14 +62,22 @@ 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 returns a path for binary from the following list of locations,
66
+ // ordered by precedence:
67
+ // 0. KUBEBUILDER_ASSETS
68
+ // 1. Environment.BinaryAssetsDirectory
69
+ // 2. The default path, "/usr/local/kubebuilder/bin"
70
+ func (te * Environment ) getBinAssetPath (binary string ) string {
71
+ valueFromEnvVar := os .Getenv (envKubebuilderPath )
72
+ if valueFromEnvVar != "" {
73
+ return filepath .Join (valueFromEnvVar , binary )
70
74
}
71
- return filepath .Join (assetPath , binary )
72
75
76
+ if te .BinaryAssetsDirectory != "" {
77
+ return filepath .Join (te .BinaryAssetsDirectory , binary )
78
+ }
79
+
80
+ return filepath .Join (defaultKubebuilderPath , binary )
73
81
}
74
82
75
83
// ControlPlane is the re-exported ControlPlane type from the internal integration package
@@ -113,6 +121,10 @@ type Environment struct {
113
121
// values are merged.
114
122
CRDDirectoryPaths []string
115
123
124
+ // BinaryAssetsDirectory is the path where the binaries required for the envtest are
125
+ // located in the local environment. This field can be overridden by setting KUBEBUILDER_ASSETS.
126
+ BinaryAssetsDirectory string
127
+
116
128
// UseExisting indicates that this environments should use an
117
129
// existing kubeconfig, instead of trying to stand up a new control plane.
118
130
// This is useful in cases that need aggregated API servers and the like.
@@ -217,14 +229,14 @@ func (te *Environment) Start() (*rest.Config, error) {
217
229
}
218
230
219
231
if os .Getenv (envKubeAPIServerBin ) == "" {
220
- te .ControlPlane .APIServer .Path = defaultAssetPath ("kube-apiserver" )
232
+ te .ControlPlane .APIServer .Path = te . getBinAssetPath ("kube-apiserver" )
221
233
}
222
234
if os .Getenv (envEtcdBin ) == "" {
223
- te .ControlPlane .Etcd .Path = defaultAssetPath ("etcd" )
235
+ te .ControlPlane .Etcd .Path = te . getBinAssetPath ("etcd" )
224
236
}
225
237
if os .Getenv (envKubectlBin ) == "" {
226
238
// 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 {
239
+ if err := os .Setenv (envKubectlBin , te . getBinAssetPath ("kubectl" )); err != nil {
228
240
return nil , err
229
241
}
230
242
}
0 commit comments