diff --git a/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/Commons.java b/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/Commons.java index 3282aa81fd..c6221e855f 100644 --- a/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/Commons.java +++ b/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/Commons.java @@ -124,6 +124,11 @@ public static void assertReloadLogStatements(String left, String right, String a * create a tar, copy it in the running k3s and load this tar as an image. */ public static void loadImage(String image, String tag, String tarName, K3sContainer container) throws Exception { + + if (imageAlreadyInK3s(container, tarName)) { + return; + } + // save image try (SaveImageCmd saveImageCmd = container.getDockerClient().saveImageCmd(image)) { InputStream imageStream = saveImageCmd.withTag(tag).exec(); @@ -182,7 +187,7 @@ public static void load(K3sContainer container, String tarName, String imageName try { LOG.info("no tars found, will resort to pulling the image"); LOG.info("using : " + imageVersion + " for : " + imageNameForDownload); - pullImage(imageNameForDownload, imageVersion, container); + pullImage(imageNameForDownload, imageVersion, tarName, container); loadImage(imageNameForDownload, imageVersion, tarName, container); } catch (Exception e) { @@ -205,7 +210,13 @@ public static void validateImage(String image, K3sContainer container) { } } - public static void pullImage(String image, String tag, K3sContainer container) throws InterruptedException { + public static void pullImage(String image, String tag, String tarName, K3sContainer container) + throws InterruptedException { + + if (imageAlreadyInK3s(container, tarName)) { + return; + } + try (PullImageCmd pullImageCmd = container.getDockerClient().pullImageCmd(image)) { pullImageCmd.withTag(tag).start().awaitCompletion(); } @@ -265,6 +276,11 @@ private static void loadImageFromPath(String tarName, K3sContainer container) { } private static boolean imageAlreadyInK3s(K3sContainer container, String tarName) { + + if (tarName == null) { + return false; + } + try { boolean present = container.execInContainer("sh", "-c", "ctr images list | grep " + tarName) .getStdout() diff --git a/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/fabric8_client/Util.java b/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/fabric8_client/Util.java index bc1bfa43b4..8d98a078e0 100644 --- a/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/fabric8_client/Util.java +++ b/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/fabric8_client/Util.java @@ -103,7 +103,7 @@ public void createAndWait(String namespace, String name, @Nullable Deployment de } else { String[] image = imageFromDeployment.split(":", 2); - pullImage(image[0], image[1], container); + pullImage(image[0], image[1], name, container); loadImage(image[0], image[1], name, container); } diff --git a/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/native_client/Util.java b/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/native_client/Util.java index c9de654263..bb24aa0176 100644 --- a/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/native_client/Util.java +++ b/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/native_client/Util.java @@ -136,7 +136,7 @@ public void createAndWait(String namespace, String name, V1Deployment deployment } else { String[] image = imageFromDeployment.split(":", 2); - pullImage(image[0], image[1], container); + pullImage(image[0], image[1], name, container); loadImage(image[0], image[1], name, container); }