Skip to content

Commit

Permalink
Merge pull request #266 from rancher/feature/load-images-from-tar
Browse files Browse the repository at this point in the history
[Enhancement] loadImage: cleanup and enable loading from tarball/-stream
  • Loading branch information
iwilltry42 authored Jun 4, 2020
2 parents 92c1157 + dc740d5 commit 85132c1
Show file tree
Hide file tree
Showing 578 changed files with 35,342 additions and 5,591 deletions.
2 changes: 1 addition & 1 deletion cmd/get/getCluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func PrintClusters(clusters []*k3d.Cluster, flags clusterFlags) {
for _, cluster := range clusters {
masterCount := cluster.MasterCount()
workerCount := cluster.WorkerCount()

if flags.token {
fmt.Fprintf(tabwriter, "%s\t%d\t%d\t%s\n", cluster.Name, masterCount, workerCount, cluster.Token)
} else {
Expand Down
39 changes: 12 additions & 27 deletions cmd/load/loadImage.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,21 @@ import (
// NewCmdLoadImage returns a new cobra command
func NewCmdLoadImage() *cobra.Command {

loadImageOpts := k3d.LoadImageOpts{}

// create new command
cmd := &cobra.Command{
Use: "image [IMAGE [IMAGE...]]",
Short: "Load an image from docker into a k3d cluster.",
Long: `Load an image from docker into a k3d cluster.`,
Args: cobra.MinimumNArgs(1),
Use: "image [IMAGE | ARCHIVE [IMAGE | ARCHIVE...]]",
Short: "Load an image from docker into a k3d cluster.",
Long: `Load an image from docker into a k3d cluster.`,
Aliases: []string{"images"},
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
images, clusters, keepTarball := parseLoadImageCmd(cmd, args)
images, clusters := parseLoadImageCmd(cmd, args)
log.Debugf("Load images [%+v] from runtime [%s] into clusters [%+v]", images, runtimes.SelectedRuntime, clusters)
for _, cluster := range clusters {
log.Infof("Loading images into '%s'", cluster.Name)
if err := tools.LoadImagesIntoCluster(cmd.Context(), runtimes.SelectedRuntime, images, &cluster, keepTarball); err != nil {
if err := tools.LoadImagesIntoCluster(cmd.Context(), runtimes.SelectedRuntime, images, &cluster, loadImageOpts); err != nil {
log.Errorf("Failed to load images into cluster '%s'", cluster.Name)
log.Errorln(err)
}
Expand All @@ -58,11 +61,7 @@ func NewCmdLoadImage() *cobra.Command {
* Flags *
*********/
cmd.Flags().StringArrayP("cluster", "c", []string{k3d.DefaultClusterName}, "Select clusters to load the image to.")
cmd.Flags().BoolP("keep-tarball", "k", false, "Do not delete the tarball which contains the saved images from the shared volume")
cmd.Flags().StringP("tar", "t", "", "Import image from local tarball")
if err := cmd.MarkFlagFilename("tar", ".tar"); err != nil {
log.Fatalln("Failed to mark --tar flag as filename")
}
cmd.Flags().BoolVarP(&loadImageOpts.KeepTar, "keep-tarball", "k", false, "Do not delete the tarball containing the saved images from the shared volume")

/* Subcommands */

Expand All @@ -71,21 +70,7 @@ func NewCmdLoadImage() *cobra.Command {
}

// parseLoadImageCmd parses the command input into variables required to create a cluster
func parseLoadImageCmd(cmd *cobra.Command, args []string) ([]string, []k3d.Cluster, bool) {
// --tar
localTarball, err := cmd.Flags().GetString("tar")
if err != nil {
log.Fatalln(err)
}
if cmd.Flags().Changed("tar") { // TODO: loadImage: implement import from local tarball
log.Fatalf("--tar flag not supported yet '%s'", localTarball)
}

// --keep-tarball
keepTarball, err := cmd.Flags().GetBool("keep-tarball")
if err != nil {
log.Fatalln(err)
}
func parseLoadImageCmd(cmd *cobra.Command, args []string) ([]string, []k3d.Cluster) {

// --cluster
clusterNames, err := cmd.Flags().GetStringArray("cluster")
Expand All @@ -103,5 +88,5 @@ func parseLoadImageCmd(cmd *cobra.Command, args []string) ([]string, []k3d.Clust
log.Fatalln("No images specified!")
}

return images, clusters, keepTarball
return images, clusters
}
2 changes: 1 addition & 1 deletion docs/faq/v1vsv3-comparison.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@
- --overwrite -> implemented
- import-images -> `k3d load image [--cluster CLUSTERNAME] [--keep] IMAGES`
- --name -> implemented as `--cluster`
- --no-remove -> implemented as `--keep`
- --no-remove -> implemented as `--keep-tarball`
```
3 changes: 1 addition & 2 deletions docs/usage/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ k3d
-s, --switch # switch current-context in kubeconfig to the new context
-u, --update # update conflicting fields in existing kubeconfig (default: true)
load
image [IMAGE [IMAGE ...]] # Load one or more images from the local runtime environment into k3d clusters
image [IMAGE | ARCHIVE [IMAGE | ARCHIVE ...]] # Load one or more images from the local runtime environment or tar-archives into k3d clusters
-c, --cluster # clusters to load the image into
-k, --keep-tarball # do not delete the image tarball from the shared volume after completion
-t, --tar # do not export image from runtime daemon, but directly import it from a tarball
completion SHELL # Generate completion scripts
version # show k3d build version
help [COMMAND] # show help text for any command
Expand Down
31 changes: 14 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,42 @@ module github.com/rancher/k3d
go 1.14

require (
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
github.com/Microsoft/go-winio v0.4.14 // indirect
github.com/Microsoft/hcsshim v0.8.6 // indirect
github.com/Microsoft/hcsshim v0.8.9 // indirect
github.com/containerd/cgroups v0.0.0-20190923161937-abd0b19954a6 // indirect
github.com/containerd/containerd v1.3.0-rc.2.0.20190924150618-aba201344ebf
github.com/containerd/containerd v1.3.4
github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6 // indirect
github.com/containerd/fifo v0.0.0-20190816180239-bda0ff6ed73c // indirect
github.com/containerd/ttrpc v0.0.0-20190828172938-92c8520ef9f8 // indirect
github.com/containerd/typeurl v0.0.0-20190911142611-5eb25027c9fd // indirect
github.com/docker/distribution v0.0.0-20190905152932-14b96e55d84c // indirect
github.com/docker/docker v1.4.2-0.20190905191220-3b23f9033967
github.com/docker/distribution v0.0.0-20200319173657-742aab907b54 // indirect
github.com/docker/docker v17.12.0-ce-rc1.0.20200528204242-89382f2f2074+incompatible
github.com/docker/go-connections v0.4.0
github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c // indirect
github.com/go-test/deep v1.0.4
github.com/gogo/googleapis v1.3.0 // indirect
github.com/gogo/protobuf v1.3.1 // indirect
github.com/golang/protobuf v1.4.0 // indirect
github.com/golang/protobuf v1.4.2 // indirect
github.com/heroku/docker-registry-client v0.0.0-20190909225348-afc9e1acc3d5
github.com/imdario/mergo v0.3.9
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de
github.com/mitchellh/go-homedir v1.1.0
github.com/moby/sys/mount v0.1.0 // indirect
github.com/moby/term v0.0.0-20200507201656-73f35e472e8f // indirect
github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c // indirect
github.com/opencontainers/image-spec v1.0.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/runc v0.1.1 // indirect
github.com/opencontainers/runtime-spec v1.0.1 // indirect
github.com/sirupsen/logrus v1.5.0
github.com/sirupsen/logrus v1.6.0
github.com/spf13/cobra v1.0.0
github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2 // indirect
go.etcd.io/bbolt v1.3.3 // indirect
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 // indirect
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e // indirect
golang.org/x/net v0.0.0-20200602114024-627f9648deb9 // indirect
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect
golang.org/x/sync v0.0.0-20190423024810-112230192c58
golang.org/x/sys v0.0.0-20200413165638-669c56c373c4 // indirect
golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980 // indirect
golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1 // indirect
google.golang.org/grpc v1.23.0 // indirect
google.golang.org/genproto v0.0.0-20200604104852-0b0486081ffb // indirect
google.golang.org/grpc v1.29.1 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
gotest.tools v2.2.0+incompatible // indirect
gotest.tools/v3 v3.0.2 // indirect
k8s.io/client-go v0.17.0
k8s.io/utils v0.0.0-20200109141947-94aeca20bf09 // indirect
)
Loading

0 comments on commit 85132c1

Please sign in to comment.