Skip to content

Commit

Permalink
fix image not being pulled if reader is not being used
Browse files Browse the repository at this point in the history
  • Loading branch information
iwilltry42 committed Apr 18, 2019
1 parent a26aa65 commit 7d5964c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func CreateCluster(c *cli.Context) error {
// let's go
log.Printf("Creating cluster [%s]", c.String("name"))
dockerID, err := createServer(
c.Bool("verbose"),
c.GlobalBool("verbose"),
fmt.Sprintf("docker.io/rancher/k3s:%s", c.String("version")),
c.String("port"),
k3sServerArgs,
Expand Down
8 changes: 7 additions & 1 deletion cli/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"time"
Expand All @@ -16,12 +17,12 @@ import (
)

func createServer(verbose bool, image string, port string, args []string, env []string, name string, volumes []string) (string, error) {
log.Printf("Creating server using %s...\n", image)
ctx := context.Background()
docker, err := client.NewEnvClient()
if err != nil {
return "", fmt.Errorf("ERROR: couldn't create docker client\n%+v", err)
}

reader, err := docker.ImagePull(ctx, image, types.ImagePullOptions{})
if err != nil {
return "", fmt.Errorf("ERROR: couldn't pull image %s\n%+v", image, err)
Expand All @@ -31,6 +32,11 @@ func createServer(verbose bool, image string, port string, args []string, env []
if err != nil {
log.Printf("WARNING: couldn't get docker output\n%+v", err)
}
} else {
_, err := io.Copy(ioutil.Discard, reader)
if err != nil {
log.Printf("WARNING: couldn't get docker output\n%+v", err)
}
}

containerLabels := make(map[string]string)
Expand Down

0 comments on commit 7d5964c

Please sign in to comment.