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 1 commit
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
13 changes: 10 additions & 3 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 @@ -768,7 +767,7 @@ func (r *kindRunnable) prePullImage(ctx context.Context) (err error) {
}

if _, err = r.env.execContext(ctx, "docker", "image", "inspect", r.opts.Image).CombinedOutput(); err == nil {
return nil
return r.loadImageIntoKindCluster(ctx)
}
Copy link
Author

@leonnicolas leonnicolas Nov 18, 2024

Choose a reason for hiding this comment

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

Actually this won't work for a public image that is not present on the machine, yet.

I feel like we should remove the if block. The comment in line 774/773 suggests that we should pull the image if we get an "No such image" error, but pulling an image that does no have a manifest will never work.

So rather we should either
a. check if the image is present locally and if not try to pull it and finally (always) load it into docker
b. check if image is present locally. If yes do nothing more. If no check if it is present locally and load it into kind or fail.

Copy link
Author

Choose a reason for hiding this comment

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

done


// Assuming Error: No such image: <image>.
Expand All @@ -780,7 +779,15 @@ func (r *kindRunnable) prePullImage(ctx context.Context) (err error) {
return errors.Wrapf(err, "docker image %q failed to download", r.opts.Image)
}

return nil
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
return cmd.Run()
}

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