Skip to content

Commit

Permalink
Copy the kops binary from --kops-binary-path into RunDir for tester's…
Browse files Browse the repository at this point in the history
… PATH
  • Loading branch information
rifelpet committed Apr 23, 2021
1 parent 53c646e commit 103650c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
4 changes: 3 additions & 1 deletion tests/e2e/kubetest2-kops/deployer/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"path"
"strings"

"k8s.io/kops/tests/e2e/pkg/util"
"sigs.k8s.io/kubetest2/pkg/exec"
)

Expand All @@ -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 {
Expand Down
11 changes: 3 additions & 8 deletions tests/e2e/kubetest2-kops/deployer/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
38 changes: 38 additions & 0 deletions tests/e2e/pkg/util/copy.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 103650c

Please sign in to comment.