Skip to content

Commit

Permalink
Merge branch '3.1.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanjbaxter committed Oct 23, 2024
2 parents c6429b3 + 0c8a398 commit abcccc8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
}
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit abcccc8

Please sign in to comment.