Cleanup in it utilities 4 (#1768)

* clean

* clean

* clean

* clean

* clean

* clean

* clean
This commit is contained in:
erabii
2024-10-16 22:52:58 +03:00
committed by GitHub
parent 0900b73ee6
commit 4466d78a4c
13 changed files with 31 additions and 63 deletions

View File

@@ -117,7 +117,7 @@ class Fabric8DiscoveryPodMetadataIT {
}
@AfterAll
static void after() throws Exception {
static void after() {
util.wiremock(NAMESPACE, "/wiremock", Phase.DELETE, false);
util.busybox(NAMESPACE, Phase.DELETE);
@@ -132,7 +132,6 @@ class Fabric8DiscoveryPodMetadataIT {
util.deleteNamespace(NAMESPACE_RIGHT);
manifests(Phase.DELETE);
Commons.cleanUp(IMAGE_NAME, K3S);
}
@Test

View File

@@ -29,6 +29,7 @@ import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.Container;
import org.testcontainers.k3s.K3sContainer;
import reactor.netty.http.client.HttpClient;
import reactor.util.retry.Retry;
@@ -42,8 +43,6 @@ import org.springframework.http.HttpMethod;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.web.reactive.function.client.WebClient;
import static org.springframework.cloud.kubernetes.integration.tests.commons.Commons.processExecResult;
/**
* @author wind57
*/
@@ -89,9 +88,8 @@ class Fabric8IstioIT {
}
@AfterAll
static void afterAll() throws Exception {
static void afterAll() {
util.deleteNamespace("istio-system");
Commons.cleanUp(IMAGE_NAME, K3S);
}
@AfterAll
@@ -156,4 +154,12 @@ class Fabric8IstioIT {
}
}
private static String processExecResult(Container.ExecResult execResult) {
if (execResult.getExitCode() != 0) {
throw new RuntimeException("stdout=" + execResult.getStdout() + "\n" + "stderr=" + execResult.getStderr());
}
return execResult.getStdout();
}
}

View File

@@ -80,10 +80,9 @@ class Fabric8EventReloadIT {
}
@AfterAll
static void afterAll() throws Exception {
static void afterAll() {
util.deleteNamespace("left");
util.deleteNamespace("right");
Commons.cleanUp(IMAGE_NAME, K3S);
manifests(Phase.DELETE);
}

View File

@@ -77,9 +77,8 @@ class ActuatorRefreshIT {
}
@AfterAll
static void afterAll() throws Exception {
static void afterAll() {
configWatcher(Phase.DELETE);
Commons.cleanUp(SPRING_CLOUD_K8S_CONFIG_WATCHER_APP_NAME, K3S);
}
@BeforeEach

View File

@@ -77,13 +77,12 @@ class ActuatorRefreshMultipleNamespacesIT {
}
@AfterAll
static void afterAll() throws Exception {
static void afterAll() {
configWatcher(Phase.DELETE);
util.wiremock(DEFAULT_NAMESPACE, "/", Phase.DELETE);
util.deleteClusterWide(DEFAULT_NAMESPACE, Set.of(DEFAULT_NAMESPACE, LEFT_NAMESPACE, RIGHT_NAMESPACE));
util.deleteNamespace(LEFT_NAMESPACE);
util.deleteNamespace(RIGHT_NAMESPACE);
Commons.cleanUp(SPRING_CLOUD_K8S_CONFIG_WATCHER_APP_NAME, K3S);
}
/**

View File

@@ -178,9 +178,6 @@ class DiscoveryClientIT {
static void afterAll() throws Exception {
rbacApi.deleteClusterRoleBinding(clusterRoleBinding.getMetadata().getName(), null, null, null, null, null,
null);
Commons.cleanUp(DISCOVERY_SERVER_APP_NAME, K3S);
Commons.cleanUp(SPRING_CLOUD_K8S_DISCOVERY_CLIENT_APP_NAME, K3S);
util.wiremock(NAMESPACE_LEFT, "/wiremock-" + NAMESPACE_LEFT, Phase.DELETE, false);
util.wiremock(NAMESPACE_RIGHT, "/wiremock-" + NAMESPACE_RIGHT, Phase.DELETE, false);

View File

@@ -90,9 +90,8 @@ class KubernetesClientDiscoveryClientIT {
}
@AfterAll
static void afterAll() throws Exception {
static void afterAll() {
manifests(Phase.DELETE);
Commons.cleanUp(IMAGE_NAME, K3S);
}
/**

View File

@@ -94,9 +94,7 @@ class KubernetesClientDiscoverySelectiveNamespacesIT {
}
@AfterAll
static void afterAll() throws Exception {
Commons.cleanUp(IMAGE_NAME, K3S);
static void afterAll() {
util.wiremock(NAMESPACE, "/wiremock", Phase.DELETE, false);
util.wiremock(NAMESPACE_A, "/wiremock", Phase.DELETE, false);
util.wiremock(NAMESPACE_B, "/wiremock", Phase.DELETE, false);

View File

@@ -24,7 +24,6 @@ import io.kubernetes.client.openapi.models.V1ConfigMapBuilder;
import io.kubernetes.client.openapi.models.V1Deployment;
import io.kubernetes.client.openapi.models.V1Ingress;
import io.kubernetes.client.openapi.models.V1Service;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
@@ -84,13 +83,6 @@ class ConfigurationWatcherMultipleAppsIT {
util.setUp(NAMESPACE);
}
@AfterAll
static void afterAll() throws Exception {
Commons.cleanUp(SPRING_CLOUD_K8S_CONFIG_WATCHER_APP_NAME, K3S);
Commons.cleanUp(CONFIG_WATCHER_APP_A_IMAGE, K3S);
Commons.cleanUp(CONFIG_WATCHER_APP_B_IMAGE, K3S);
}
@BeforeEach
void setup() {
util.kafka(NAMESPACE, Phase.CREATE);

View File

@@ -24,7 +24,6 @@ import io.kubernetes.client.openapi.models.V1Ingress;
import io.kubernetes.client.openapi.models.V1Secret;
import io.kubernetes.client.openapi.models.V1SecretBuilder;
import io.kubernetes.client.openapi.models.V1Service;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
@@ -83,13 +82,6 @@ class ConfigurationWatcherMultipleAppIT {
util.setUp(NAMESPACE);
}
@AfterAll
static void afterAll() throws Exception {
Commons.cleanUp(SPRING_CLOUD_K8S_CONFIG_WATCHER_APP_NAME, K3S);
Commons.cleanUp(CONFIG_WATCHER_APP_A_IMAGE, K3S);
Commons.cleanUp(CONFIG_WATCHER_APP_B_IMAGE, K3S);
}
@BeforeEach
void setup() {
util.rabbitMq(NAMESPACE, Phase.CREATE);

View File

@@ -90,7 +90,6 @@ class K8sClientConfigMapReloadIT {
manifests(Phase.DELETE);
util.deleteNamespace("left");
util.deleteNamespace("right");
Commons.cleanUp(IMAGE_NAME, K3S);
}
/**

View File

@@ -75,9 +75,8 @@ class K8sClientSecretsReloadIT {
}
@AfterAll
static void afterAll() throws Exception {
static void afterAll() {
configK8sClientIt(Phase.DELETE);
Commons.cleanUp(IMAGE_NAME, K3S);
}
@Test

View File

@@ -120,6 +120,9 @@ public final class Commons {
}
/**
* 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 {
// save image
try (SaveImageCmd saveImageCmd = container.getDockerClient().saveImageCmd(image)) {
@@ -182,22 +185,6 @@ public final class Commons {
}
}
private static void loadImageFromPath(String tarName, K3sContainer container) {
await().atMost(Duration.ofMinutes(2)).pollInterval(Duration.ofSeconds(1)).until(() -> {
Container.ExecResult result = container.execInContainer("ctr", "i", "import", TMP_IMAGES + "/" + tarName);
boolean noErrors = result.getStderr() == null || result.getStderr().isEmpty();
if (!noErrors) {
LOG.info("error is : " + result.getStderr());
}
return noErrors;
});
}
public static void cleanUp(String image, K3sContainer container) throws Exception {
container.execInContainer("crictl", "rmi", "docker.io/springcloud/" + image + ":" + pomVersion());
container.execInContainer("rm", TEMP_FOLDER + "/" + image + ".tar");
}
/**
* validates that the provided image does exist in the local docker registry.
*/
@@ -220,14 +207,6 @@ public final class Commons {
}
public static String processExecResult(Container.ExecResult execResult) {
if (execResult.getExitCode() != 0) {
throw new RuntimeException("stdout=" + execResult.getStdout() + "\n" + "stderr=" + execResult.getStderr());
}
return execResult.getStdout();
}
public static String pomVersion() {
try (InputStream in = new ClassPathResource(KUBERNETES_VERSION_FILE).getInputStream()) {
String version = StreamUtils.copyToString(in, StandardCharsets.UTF_8);
@@ -269,4 +248,15 @@ public final class Commons {
}
private static void loadImageFromPath(String tarName, K3sContainer container) {
await().atMost(Duration.ofMinutes(2)).pollInterval(Duration.ofSeconds(1)).until(() -> {
Container.ExecResult result = container.execInContainer("ctr", "i", "import", TMP_IMAGES + "/" + tarName);
boolean noErrors = result.getStderr() == null || result.getStderr().isEmpty();
if (!noErrors) {
LOG.info("error is : " + result.getStderr());
}
return noErrors;
});
}
}