Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Podman load docker images #1766

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions pkg/cluster/internal/providers/docker/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,24 @@ func (p *Provider) CollectLogs(dir string, nodes []nodes.Node) error {
errs = append(errs, errors.AggregateConcurrent(fns))
return errors.NewAggregate(errs)
}

// SaveImage saves image to dest, as in `docker save`
func (p *Provider) SaveImage(image, dest string) error {
return exec.Command("docker", "save", "-o", dest, image).Run()
}

// ImageID return the Id of the container image
func (p *Provider) ImageID(containerNameOrID string) (string, error) {
cmd := exec.Command("docker", "image", "inspect",
"-f", "{{ .Id }}",
containerNameOrID, // ... against the container
)
lines, err := exec.CombinedOutputLines(cmd)
if err != nil {
return "", err
}
if len(lines) != 1 {
return "", errors.Errorf("Docker image ID should only be one line, got %d lines", len(lines))
}
return lines[0], nil
}
21 changes: 21 additions & 0 deletions pkg/cluster/internal/providers/podman/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,24 @@ func (p *Provider) CollectLogs(dir string, nodes []nodes.Node) error {
errs = append(errs, errors.AggregateConcurrent(fns))
return errors.NewAggregate(errs)
}

// SaveImage saves image to dest, as in `docker save`
func (p *Provider) SaveImage(image, dest string) error {
return exec.Command("podman", "save", "-o", dest, image).Run()
}

// ImageID return the Id of the container image
func (p *Provider) ImageID(containerNameOrID string) (string, error) {
cmd := exec.Command("podman", "image", "inspect",
"-f", "{{.Id}}",
containerNameOrID, // ... against the container
)
lines, err := exec.CombinedOutputLines(cmd)
if err != nil {
return "", err
}
if len(lines) != 1 {
return "", errors.Errorf("Docker image ID should only be one line, got %d lines", len(lines))
}
return lines[0], nil
}
4 changes: 4 additions & 0 deletions pkg/cluster/internal/providers/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@ type Provider interface {
GetAPIServerInternalEndpoint(cluster string) (string, error)
// CollectLogs will populate dir with cluster logs and other debug files
CollectLogs(dir string, nodes []nodes.Node) error
// SaveImage saves image to dest, as in `docker save`
SaveImage(image, dest string) error
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node providers cannot all provide this anyhow, if I have a kubectl + pods based provider, then I want the images to come from the local machine.

Instead we need to cover all the local machine when obtaining images. We can provide a unified UX for that.

// ImageID return the Id of the container image
ImageID(containerNameOrID string) (string, error)
}
10 changes: 10 additions & 0 deletions pkg/cluster/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,13 @@ func (p *Provider) CollectLogs(name, dir string) error {
}
return p.provider.CollectLogs(dir, n)
}

// SaveImage saves image to dest, as in `docker save`
func (p *Provider) SaveImage(image, dest string) error {
return p.provider.SaveImage(image, dest)
}

// ImageID return the Id of the container image
func (p *Provider) ImageID(containerNameOrID string) (string, error) {
return p.provider.ImageID(containerNameOrID)
}
26 changes: 2 additions & 24 deletions pkg/cmd/kind/load/docker-image/docker-image.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"sigs.k8s.io/kind/pkg/cluster/nodeutils"
"sigs.k8s.io/kind/pkg/cmd"
"sigs.k8s.io/kind/pkg/errors"
"sigs.k8s.io/kind/pkg/exec"
"sigs.k8s.io/kind/pkg/fs"
"sigs.k8s.io/kind/pkg/log"

Expand Down Expand Up @@ -83,7 +82,7 @@ func runE(logger log.Logger, flags *flagpole, args []string) error {

// Check that the image exists locally and gets its ID, if not return error
imageName := args[0]
imageID, err := imageID(imageName)
imageID, err := provider.ImageID(imageName)
if err != nil {
return fmt.Errorf("image: %q not present locally", imageName)
}
Expand Down Expand Up @@ -141,7 +140,7 @@ func runE(logger log.Logger, flags *flagpole, args []string) error {
defer os.RemoveAll(dir)
imageTarPath := filepath.Join(dir, "image.tar")

err = save(imageName, imageTarPath)
err = provider.SaveImage(imageName, imageTarPath)
if err != nil {
return err
}
Expand All @@ -168,24 +167,3 @@ func loadImage(imageTarName string, node nodes.Node) error {
defer f.Close()
return nodeutils.LoadImageArchive(node, f)
}

// save saves image to dest, as in `docker save`
func save(image, dest string) error {
return exec.Command("docker", "save", "-o", dest, image).Run()
}

// imageID return the Id of the container image
func imageID(containerNameOrID string) (string, error) {
cmd := exec.Command("docker", "image", "inspect",
"-f", "{{ .Id }}",
containerNameOrID, // ... against the container
)
lines, err := exec.CombinedOutputLines(cmd)
if err != nil {
return "", err
}
if len(lines) != 1 {
return "", errors.Errorf("Docker image ID should only be one line, got %d lines", len(lines))
}
return lines[0], nil
}