Merge branch '3.1.x'
This commit is contained in:
@@ -85,7 +85,7 @@ class K8sClientConfigMapReloadIT {
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void afterAll() throws Exception {
|
||||
static void afterAll() {
|
||||
util.deleteClusterWide(NAMESPACE, Set.of("left", "right"));
|
||||
manifests(Phase.DELETE);
|
||||
util.deleteNamespace("left");
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.cloud.kubernetes.integration.tests.commons;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
@@ -41,7 +40,6 @@ import org.testcontainers.containers.Container;
|
||||
import org.testcontainers.k3s.K3sContainer;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -59,6 +57,8 @@ import static org.springframework.cloud.kubernetes.integration.tests.commons.Fix
|
||||
*/
|
||||
public final class Commons {
|
||||
|
||||
private static String POM_VERSION;
|
||||
|
||||
private static final Log LOG = LogFactory.getLog(Commons.class);
|
||||
|
||||
private Commons() {
|
||||
@@ -149,6 +149,11 @@ public final class Commons {
|
||||
* either get the tar from '/tmp/docker/images', or pull the image.
|
||||
*/
|
||||
public static void load(K3sContainer container, String tarName, String imageNameForDownload, String imageVersion) {
|
||||
|
||||
if (imageAlreadyInK3s(container, tarName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
File dockerImagesRootDir = Paths.get(TMP_IMAGES).toFile();
|
||||
if (dockerImagesRootDir.exists() && dockerImagesRootDir.isDirectory()) {
|
||||
File[] tars = dockerImagesRootDir.listFiles();
|
||||
@@ -204,22 +209,22 @@ public final class Commons {
|
||||
try (PullImageCmd pullImageCmd = container.getDockerClient().pullImageCmd(image)) {
|
||||
pullImageCmd.withTag(tag).start().awaitCompletion();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static String pomVersion() {
|
||||
try (InputStream in = new ClassPathResource(KUBERNETES_VERSION_FILE).getInputStream()) {
|
||||
String version = StreamUtils.copyToString(in, StandardCharsets.UTF_8);
|
||||
if (StringUtils.hasText(version)) {
|
||||
version = version.trim();
|
||||
if (POM_VERSION == null) {
|
||||
try (InputStream in = new ClassPathResource(KUBERNETES_VERSION_FILE).getInputStream()) {
|
||||
String version = StreamUtils.copyToString(in, StandardCharsets.UTF_8);
|
||||
if (StringUtils.hasText(version)) {
|
||||
POM_VERSION = version.trim();
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return version;
|
||||
}
|
||||
catch (IOException e) {
|
||||
ReflectionUtils.rethrowRuntimeException(e);
|
||||
}
|
||||
// not reachable since exception rethrown at runtime
|
||||
return null;
|
||||
|
||||
return POM_VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -259,4 +264,23 @@ public final class Commons {
|
||||
});
|
||||
}
|
||||
|
||||
private static boolean imageAlreadyInK3s(K3sContainer container, String tarName) {
|
||||
try {
|
||||
boolean present = container.execInContainer("sh", "-c", "ctr images list | grep " + tarName)
|
||||
.getStdout()
|
||||
.contains(tarName);
|
||||
if (present) {
|
||||
System.out.println("image : " + tarName + " already in k3s, skipping");
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
System.out.println("image : " + tarName + " not in k3s");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -79,9 +79,7 @@ public final class Images {
|
||||
}
|
||||
|
||||
public static void loadBusybox(K3sContainer container) {
|
||||
if (!imageAlreadyInK3s(container, BUSYBOX_TAR)) {
|
||||
Commons.load(container, BUSYBOX_TAR, BUSYBOX, busyboxVersion());
|
||||
}
|
||||
Commons.load(container, BUSYBOX_TAR, BUSYBOX, busyboxVersion());
|
||||
}
|
||||
|
||||
public static void loadWiremock(K3sContainer container) {
|
||||
@@ -108,25 +106,6 @@ public final class Images {
|
||||
Commons.load(container, RABBITMQ_TAR, RABBITMQ, rabbitMqVersion());
|
||||
}
|
||||
|
||||
private static boolean imageAlreadyInK3s(K3sContainer container, String tarName) {
|
||||
try {
|
||||
boolean present = container.execInContainer("sh", "-c", "ctr images list | grep " + tarName)
|
||||
.getStdout()
|
||||
.contains(tarName);
|
||||
if (present) {
|
||||
System.out.println("image : " + tarName + " already in k3s, skipping");
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
System.out.println("image : " + tarName + " not in k3s");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
// find the image version from current-images.txt
|
||||
private static String imageVersion(String imageNameForDownload) {
|
||||
BufferedReader reader = new BufferedReader(
|
||||
|
||||
Reference in New Issue
Block a user