Cleanup some of the tarball producing code

pull/6/head
Michael Taufen 2017-02-22 14:07:10 -08:00
parent 2e12711160
commit e6321c7440
1 changed files with 30 additions and 14 deletions

View File

@ -29,6 +29,8 @@ import (
"k8s.io/kubernetes/test/e2e_node/builder" "k8s.io/kubernetes/test/e2e_node/builder"
) )
const localCOSMounterPath = "cluster/gce/gci/mounter/mounter"
// NodeE2ERemote contains the specific functions in the node e2e test suite. // NodeE2ERemote contains the specific functions in the node e2e test suite.
type NodeE2ERemote struct{} type NodeE2ERemote struct{}
@ -37,8 +39,6 @@ func InitNodeE2ERemote() TestSuite {
return &NodeE2ERemote{} return &NodeE2ERemote{}
} }
const localCOSMounterPath = "cluster/gce/gci/mounter/mounter"
// SetupTestPackage sets up the test package with binaries k8s required for node e2e tests // SetupTestPackage sets up the test package with binaries k8s required for node e2e tests
func (n *NodeE2ERemote) SetupTestPackage(tardir string) error { func (n *NodeE2ERemote) SetupTestPackage(tardir string) error {
// Build the executables // Build the executables
@ -66,10 +66,37 @@ func (n *NodeE2ERemote) SetupTestPackage(tardir string) error {
} }
// Include the GCI/COS mounter artifacts in the deployed tarball // Include the GCI/COS mounter artifacts in the deployed tarball
err = tarAddCOSMounter(tardir)
if err != nil {
return err
}
return nil
}
// dest is relative to the root of the tar
func tarAddFile(tar, source, dest string) error {
dir := filepath.Dir(dest)
tardir := filepath.Join(tar, dir)
tardest := filepath.Join(tar, dest)
out, err := exec.Command("mkdir", "-p", tardir).CombinedOutput()
if err != nil {
return fmt.Errorf("failed to create archive bin subdir %q, was dest for file %q. Err: %v. Output:\n%s", tardir, source, err, out)
}
out, err = exec.Command("cp", source, tardest).CombinedOutput()
if err != nil {
return fmt.Errorf("failed to copy file %q to the archive bin subdir %q. Err: %v. Output:\n%s", source, tardir, err, out)
}
return nil
}
// Includes the GCI/COS mounter artifacts in the deployed tarball
func tarAddCOSMounter(tar string) error {
k8sDir, err := builder.GetK8sRootDir() k8sDir, err := builder.GetK8sRootDir()
if err != nil { if err != nil {
return fmt.Errorf("Could not find K8s root dir! Err: %v", err) return fmt.Errorf("Could not find K8s root dir! Err: %v", err)
} }
source := filepath.Join(k8sDir, localCOSMounterPath) source := filepath.Join(k8sDir, localCOSMounterPath)
// Require the GCI/COS mounter script, we want to make sure the remote test runner stays up to date if the mounter file moves // Require the GCI/COS mounter script, we want to make sure the remote test runner stays up to date if the mounter file moves
@ -77,18 +104,7 @@ func (n *NodeE2ERemote) SetupTestPackage(tardir string) error {
return fmt.Errorf("Could not find GCI/COS mounter script at %q! If this script has been (re)moved, please update the e2e node remote test runner accordingly! Err: %v", source, err) return fmt.Errorf("Could not find GCI/COS mounter script at %q! If this script has been (re)moved, please update the e2e node remote test runner accordingly! Err: %v", source, err)
} }
bindir := "cluster/gce/gci/mounter" tarAddFile(tar, source, localCOSMounterPath)
bin := "mounter"
destdir := filepath.Join(tardir, bindir)
dest := filepath.Join(destdir, bin)
out, err := exec.Command("mkdir", "-p", filepath.Join(tardir, bindir)).CombinedOutput()
if err != nil {
return fmt.Errorf("failed to create directory %q for GCI/COS mounter script. Err: %v. Output:\n%s", destdir, err, out)
}
out, err = exec.Command("cp", source, dest).CombinedOutput()
if err != nil {
return fmt.Errorf("failed to copy GCI/COS mounter script to the archive bin. Err: %v. Output:\n%s", err, out)
}
return nil return nil
} }