Skip to content

Commit 413bbd3

Browse files
authored
env_kind.go: load image into kind cluster (#73)
* env_kind.go: load image into kind cluster This commit load the image into the kind cluster with ``` kind load docker-image <image-name> ``` We need to do this if the image is not in a public registry. Honestly, the purpose of the `preLoadImage()` function is not clear to me. Signed-off-by: leonnicolas <leonloechner@gmx.de> * pull and load image Pull only the image if it isn't present on the machine and always load it into the cluster. * Apply suggestion from code review Signed-off-by: leonnicolas <leonloechner@gmx.de> --------- Signed-off-by: leonnicolas <leonloechner@gmx.de>
1 parent 97db25a commit 413bbd3

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

env_kind.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ func validateKindName(name string) error {
5555
}
5656
if !kindNamePattern.MatchString(name) {
5757
return errors.Newf("name can have only %v characters due to kind cluster name constraints, got: %v", kindNamePattern.String(), name)
58-
5958
}
6059
return nil
6160
}
@@ -767,20 +766,25 @@ func (r *kindRunnable) prePullImage(ctx context.Context) (err error) {
767766
return errors.Newf("service %q is running; expected stopped", r.Name())
768767
}
769768

770-
if _, err = r.env.execContext(ctx, "docker", "image", "inspect", r.opts.Image).CombinedOutput(); err == nil {
771-
return nil
769+
if _, err = r.env.execContext(ctx, "docker", "image", "inspect", r.opts.Image).CombinedOutput(); err != nil {
770+
cmd := r.env.execContext(ctx, "docker", "pull", r.opts.Image)
771+
l := &LinePrefixLogger{prefix: r.Name() + ": ", logger: r.logger}
772+
cmd.Stdout = l
773+
cmd.Stderr = l
774+
if err = cmd.Run(); err != nil {
775+
return errors.Wrapf(err, "docker image %q failed to download", r.opts.Image)
776+
}
772777
}
773778

774-
// Assuming Error: No such image: <image>.
775-
cmd := r.env.execContext(ctx, "docker", "pull", r.opts.Image)
779+
return r.loadImageIntoKindCluster(ctx)
780+
}
781+
782+
func (r *kindRunnable) loadImageIntoKindCluster(ctx context.Context) error {
783+
cmd := r.env.execContext(ctx, "kind", "load", "docker-image", "--name", r.env.clusterName, r.opts.Image)
776784
l := &LinePrefixLogger{prefix: r.Name() + ": ", logger: r.logger}
777785
cmd.Stdout = l
778786
cmd.Stderr = l
779-
if err = cmd.Run(); err != nil {
780-
return errors.Wrapf(err, "docker image %q failed to download", r.opts.Image)
781-
}
782-
783-
return nil
787+
return cmd.Run()
784788
}
785789

786790
func (r *kindRunnable) WaitReady() (err error) {

0 commit comments

Comments
 (0)