Move path management from e2e_node to common test/utils directory
enables reuse of these methods for other e2e tests
This commit is contained in:
@@ -22,10 +22,10 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/kubernetes/test/utils"
|
||||
)
|
||||
|
||||
var k8sBinDir = flag.String("k8s-bin-dir", "", "Directory containing k8s kubelet binaries.")
|
||||
@@ -39,7 +39,7 @@ var buildTargets = []string{
|
||||
|
||||
func BuildGo() error {
|
||||
glog.Infof("Building k8s binaries...")
|
||||
k8sRoot, err := GetK8sRootDir()
|
||||
k8sRoot, err := utils.GetK8sRootDir()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to locate kubernetes root directory %v.", err)
|
||||
}
|
||||
@@ -75,7 +75,7 @@ func getK8sBin(bin string) (string, error) {
|
||||
return filepath.Join(path, bin), nil
|
||||
}
|
||||
|
||||
buildOutputDir, err := GetK8sBuildOutputDir()
|
||||
buildOutputDir, err := utils.GetK8sBuildOutputDir()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -84,53 +84,7 @@ func getK8sBin(bin string) (string, error) {
|
||||
}
|
||||
|
||||
// Give up with error
|
||||
return "", fmt.Errorf("Unable to locate %s. Can be defined using --k8s-path.", bin)
|
||||
}
|
||||
|
||||
// GetK8sRootDir returns the root directory for kubernetes, if present in the gopath.
|
||||
func GetK8sRootDir() (string, error) {
|
||||
dir, err := RootDir()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return filepath.Join(dir, fmt.Sprintf("%s/", "k8s.io/kubernetes")), nil
|
||||
}
|
||||
|
||||
// GetCAdvisorRootDir returns the root directory for cAdvisor, if present in the gopath.
|
||||
func GetCAdvisorRootDir() (string, error) {
|
||||
dir, err := RootDir()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return filepath.Join(dir, fmt.Sprintf("%s/", "github.com/google/cadvisor")), nil
|
||||
}
|
||||
|
||||
// TODO: Dedup / merge this with comparable utilities in e2e/util.go
|
||||
// RootDir returns the path to the directory containing the k8s.io directory
|
||||
func RootDir() (string, error) {
|
||||
// Get the directory of the current executable
|
||||
_, testExec, _, _ := runtime.Caller(0)
|
||||
path := filepath.Dir(testExec)
|
||||
|
||||
// Look for the kubernetes source root directory
|
||||
if strings.Contains(path, "k8s.io/kubernetes") {
|
||||
splitPath := strings.Split(path, "k8s.io/kubernetes")
|
||||
return splitPath[0], nil
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("Could not find kubernetes source root directory.")
|
||||
}
|
||||
|
||||
func GetK8sBuildOutputDir() (string, error) {
|
||||
k8sRoot, err := GetK8sRootDir()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
buildOutputDir := filepath.Join(k8sRoot, "_output/local/go/bin")
|
||||
if _, err := os.Stat(buildOutputDir); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return buildOutputDir, nil
|
||||
return "", fmt.Errorf("unable to locate %s, Can be defined using --k8s-path", bin)
|
||||
}
|
||||
|
||||
func GetKubeletServerBin() string {
|
||||
|
Reference in New Issue
Block a user