From 164cad13142f854dfcc968aeb0d1a4a2a79b5cbd Mon Sep 17 00:00:00 2001
From: Cole Snodgrass <cole@airbyte.io>
Date: Thu, 12 Dec 2024 07:29:48 -0800
Subject: [PATCH] fix: panic when image pull fails (#152)

---
 internal/cmd/local/k8s/load_images.go | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/internal/cmd/local/k8s/load_images.go b/internal/cmd/local/k8s/load_images.go
index c898cd5..be8cb5f 100644
--- a/internal/cmd/local/k8s/load_images.go
+++ b/internal/cmd/local/k8s/load_images.go
@@ -38,9 +38,10 @@ func loadImages(ctx context.Context, dockerClient docker.Client, nodes []nodesli
 				pterm.Debug.Printfln("error pulling image %s", err)
 				// image pull errors are intentionally dropped because we're in a goroutine,
 				// and because we don't want to interrupt other image pulls.
+			} else {
+				defer r.Close()
+				io.Copy(io.Discard, r)
 			}
-			defer r.Close()
-			io.Copy(io.Discard, r)
 		}(img)
 	}
 	wg.Wait()