Copy the kops binary from --kops-binary-path into RunDir for tester's PATH

This commit is contained in:
Peter Rifel 2021-04-22 21:35:17 -05:00
parent 8d326656a1
commit d36f65e0fb
No known key found for this signature in database
GPG Key ID: BC6469E5B16DB2B6
3 changed files with 50 additions and 9 deletions

View File

@ -23,6 +23,7 @@ import (
"path"
"strings"
"k8s.io/kops/tests/e2e/pkg/util"
"sigs.k8s.io/kubetest2/pkg/exec"
)
@ -38,7 +39,8 @@ func (d *deployer) Build() error {
if err := d.BuildOptions.Build(); err != nil {
return err
}
return nil
// Copy the kops binary into the test's RunDir to be included in the tester's PATH
return util.Copy(d.KopsBinaryPath, path.Join(d.commonOptions.RunDir(), "kops"))
}
func (d *deployer) verifyBuildFlags() error {
@ -76,6 +78,12 @@ func (d *deployer) verifyBuildFlags() error {
d.BuildOptions.KopsRoot = d.KopsRoot
d.BuildOptions.StageLocation = d.StageLocation
for _, envvar := range d.env() {
// Set all of the env vars we use for kops in the current process
// so that the tester inherits them when shelling out to kops
i := strings.Index(envvar, "=")
os.Setenv(envvar[0:i], envvar[i+1:])
}
return nil
}

View File

@ -56,16 +56,15 @@ func (d *deployer) initialize() error {
return fmt.Errorf("init failed to check up flags: %v", err)
}
}
if d.KopsBinaryPath == "" {
d.KopsBinaryPath = path.Join(d.commonOptions.RunDir(), "kops")
}
if d.KopsVersionMarker != "" {
d.KopsBinaryPath = path.Join(d.commonOptions.RunDir(), "kops")
baseURL, err := kops.DownloadKops(d.KopsVersionMarker, d.KopsBinaryPath)
if err != nil {
return fmt.Errorf("init failed to download kops from url: %v", err)
}
d.KopsBaseURL = baseURL
}
switch d.CloudProvider {
case "aws":
// These environment variables are defined by the "preset-aws-ssh" prow preset
@ -135,11 +134,7 @@ func (d *deployer) verifyKopsFlags() error {
}
if d.KopsBinaryPath == "" && d.KopsVersionMarker == "" {
if ws := os.Getenv("WORKSPACE"); ws != "" {
d.KopsBinaryPath = path.Join(ws, "kops")
} else {
return errors.New("missing required --kops-binary-path when --kops-version-marker is not used")
}
return errors.New("missing required --kops-binary-path when --kops-version-marker is not used")
}
switch d.CloudProvider {

View File

@ -0,0 +1,38 @@
/*
Copyright 2021 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package util
import (
"strings"
"k8s.io/klog/v2"
"sigs.k8s.io/kubetest2/pkg/exec"
)
func Copy(src, dest string) error {
cpArgs := []string{
"cp", src, dest,
}
klog.Info(strings.Join(cpArgs, " "))
cmd := exec.Command(cpArgs[0], cpArgs[1:]...)
exec.InheritOutput(cmd)
err := cmd.Run()
if err != nil {
return err
}
return nil
}