Merge pull request #24 from BenTheElder/pull-errors

image pull fixes
This commit is contained in:
k8s-ci-robot
2018-09-20 23:40:20 -07:00
committed by GitHub
4 changed files with 22 additions and 7 deletions

View File

@@ -94,7 +94,7 @@ create_cluster() {
# mark the cluster as up for cleanup
# even if kind create fails, kind delete can clean up after it
KIND_IS_UP=true
kind create
kind create --image="kindest/node:latest"
}
# run e2es with kubetest

View File

@@ -294,6 +294,9 @@ func (c *BuildContext) buildImage(dir string) error {
}
func (c *BuildContext) createBuildContainer(buildDir string) (id string, err error) {
// attempt to explicitly pull the image if it doesn't exist locally
// we don't care if this errors, we'll still try to run
_, _ = docker.PullIfNotPresent(c.baseImage)
cmd := exec.Command("docker", "run")
cmd.Args = append(cmd.Args,
"-d", // make the client exit while the container continues to run
@@ -308,7 +311,8 @@ func (c *BuildContext) createBuildContainer(buildDir string) (id string, err err
cmd.Debug = true
lines, err := cmd.CombinedOutputLines()
if err != nil {
return "", errors.Wrap(err, "failed to create build container")
return "", errors.Wrap(err,
fmt.Sprintf("failed to create build container: %v", lines))
}
if len(lines) < 1 {
return "", fmt.Errorf("invalid container creation output, must print at least one line")

View File

@@ -19,6 +19,8 @@ package docker
import (
"strings"
"sigs.k8s.io/kind/pkg/exec"
)
// JoinNameAndTag combines a docker image name and tag
@@ -33,3 +35,15 @@ func JoinNameAndTag(name, tag string) string {
}
return name + tag
}
// PullIfNotPresent will pull an image if it is not present locally
// it returns true if it attempted to pull, and any errors from pulling
func PullIfNotPresent(image string) (pulled bool, err error) {
// if this did not return an error, then the image exists locally
cmd := exec.Command("docker", "inspect", "--type=image", image)
if err := cmd.Run(); err == nil {
return false, nil
}
// otherwise try to pull it
return true, exec.Command("docker", "pull", image).Run()
}

View File

@@ -73,7 +73,7 @@ func (cmd *Cmd) runLoggingOutputOnFail() error {
cmd.Stdout = &buff
cmd.Stderr = &buff
err := cmd.Cmd.Run()
if cmd.LogOutputOnFail {
if err != nil && cmd.LogOutputOnFail {
log.Error("failed with:")
scanner := bufio.NewScanner(&buff)
for scanner.Scan() {
@@ -95,12 +95,9 @@ func (cmd *Cmd) CombinedOutputLines() (lines []string, err error) {
cmd.Stdout = &buff
cmd.Stderr = &buff
err = cmd.Cmd.Run()
if err != nil {
return nil, err
}
scanner := bufio.NewScanner(&buff)
for scanner.Scan() {
lines = append(lines, scanner.Text())
}
return lines, nil
return lines, err
}