From 103650c06578c13cdd4c7db1bc9a603651c7a1c0 Mon Sep 17 00:00:00 2001 From: Peter Rifel Date: Thu, 22 Apr 2021 21:35:17 -0500 Subject: [PATCH] Copy the kops binary from --kops-binary-path into RunDir for tester's PATH --- tests/e2e/kubetest2-kops/deployer/build.go | 4 ++- tests/e2e/kubetest2-kops/deployer/common.go | 11 ++---- tests/e2e/pkg/util/copy.go | 38 +++++++++++++++++++++ 3 files changed, 44 insertions(+), 9 deletions(-) create mode 100644 tests/e2e/pkg/util/copy.go diff --git a/tests/e2e/kubetest2-kops/deployer/build.go b/tests/e2e/kubetest2-kops/deployer/build.go index e73f22bb126c2..6eb5df69b43bd 100644 --- a/tests/e2e/kubetest2-kops/deployer/build.go +++ b/tests/e2e/kubetest2-kops/deployer/build.go @@ -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 { diff --git a/tests/e2e/kubetest2-kops/deployer/common.go b/tests/e2e/kubetest2-kops/deployer/common.go index 3e26bd3de204b..098b24e92f8d7 100644 --- a/tests/e2e/kubetest2-kops/deployer/common.go +++ b/tests/e2e/kubetest2-kops/deployer/common.go @@ -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 { diff --git a/tests/e2e/pkg/util/copy.go b/tests/e2e/pkg/util/copy.go new file mode 100644 index 0000000000000..75714b1a864d5 --- /dev/null +++ b/tests/e2e/pkg/util/copy.go @@ -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 +}