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

env_kind.go: load image into kind cluster #73

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
26 changes: 16 additions & 10 deletions env_kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func validateKindName(name string) error {
}
if !kindNamePattern.MatchString(name) {
return errors.Newf("name can have only %v characters due to kind cluster name constraints, got: %v", kindNamePattern.String(), name)

}
return nil
}
Expand Down Expand Up @@ -767,20 +766,27 @@ func (r *kindRunnable) prePullImage(ctx context.Context) (err error) {
return errors.Newf("service %q is running; expected stopped", r.Name())
}

if _, err = r.env.execContext(ctx, "docker", "image", "inspect", r.opts.Image).CombinedOutput(); err == nil {
return nil
if image, err := r.env.execContext(ctx, "docker", "image", "ls", r.opts.Image, "--format", "{{.Repository}}:{{.Tag}}").CombinedOutput(); err != nil {
return fmt.Errorf("error listing docker images: %w", err)
} else if strings.TrimSpace(string(image)) != r.opts.Image {
cmd := r.env.execContext(ctx, "docker", "pull", r.opts.Image)
l := &LinePrefixLogger{prefix: r.Name() + ": ", logger: r.logger}
cmd.Stdout = l
cmd.Stderr = l
if err = cmd.Run(); err != nil {
return errors.Wrapf(err, "docker image %q failed to download", r.opts.Image)
}
}

// Assuming Error: No such image: <image>.
cmd := r.env.execContext(ctx, "docker", "pull", r.opts.Image)
return r.loadImageIntoKindCluster(ctx)
}

func (r *kindRunnable) loadImageIntoKindCluster(ctx context.Context) error {
cmd := r.env.execContext(ctx, "kind", "load", "docker-image", "--name", r.env.clusterName, r.opts.Image)
l := &LinePrefixLogger{prefix: r.Name() + ": ", logger: r.logger}
cmd.Stdout = l
cmd.Stderr = l
if err = cmd.Run(); err != nil {
return errors.Wrapf(err, "docker image %q failed to download", r.opts.Image)
}

return nil
return cmd.Run()
}

func (r *kindRunnable) WaitReady() (err error) {
Expand Down