Skip to content

Commit

Permalink
Cleanup in it utilities 4 (#1768)
Browse files Browse the repository at this point in the history
* clean

* clean

* clean

* clean

* clean

* clean

* clean
  • Loading branch information
wind57 authored Oct 16, 2024
1 parent 0900b73 commit 4466d78
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ static void beforeAll() throws Exception {
}

@AfterAll
static void after() throws Exception {
static void after() {
util.wiremock(NAMESPACE, "/wiremock", Phase.DELETE, false);
util.busybox(NAMESPACE, Phase.DELETE);

Expand All @@ -132,7 +132,6 @@ static void after() throws Exception {
util.deleteNamespace(NAMESPACE_RIGHT);

manifests(Phase.DELETE);
Commons.cleanUp(IMAGE_NAME, K3S);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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;
Expand All @@ -42,8 +43,6 @@
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
*/
Expand Down Expand Up @@ -89,9 +88,8 @@ static void beforeAll() throws Exception {
}

@AfterAll
static void afterAll() throws Exception {
static void afterAll() {
util.deleteNamespace("istio-system");
Commons.cleanUp(IMAGE_NAME, K3S);
}

@AfterAll
Expand Down Expand Up @@ -156,4 +154,12 @@ private static String istioctlPodName() {
}
}

private static String processExecResult(Container.ExecResult execResult) {
if (execResult.getExitCode() != 0) {
throw new RuntimeException("stdout=" + execResult.getStdout() + "\n" + "stderr=" + execResult.getStderr());
}

return execResult.getStdout();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,9 @@ static void beforeAll() throws Exception {
}

@AfterAll
static void afterAll() throws Exception {
static void afterAll() {
util.deleteNamespace("left");
util.deleteNamespace("right");
Commons.cleanUp(IMAGE_NAME, K3S);

manifests(Phase.DELETE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ static void beforeAll() throws Exception {
}

@AfterAll
static void afterAll() throws Exception {
static void afterAll() {
configWatcher(Phase.DELETE);
Commons.cleanUp(SPRING_CLOUD_K8S_CONFIG_WATCHER_APP_NAME, K3S);
}

@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,12 @@ static void beforeAll() throws Exception {
}

@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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,6 @@ static void beforeAll() throws Exception {
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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,8 @@ static void beforeAll() throws Exception {
}

@AfterAll
static void afterAll() throws Exception {
static void afterAll() {
manifests(Phase.DELETE);
Commons.cleanUp(IMAGE_NAME, K3S);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ static void beforeAll() throws Exception {
}

@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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
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;
Expand Down Expand Up @@ -84,13 +83,6 @@ static void beforeAll() throws Exception {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
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;
Expand Down Expand Up @@ -83,13 +82,6 @@ static void beforeAll() throws Exception {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ static void afterAll() throws Exception {
manifests(Phase.DELETE);
util.deleteNamespace("left");
util.deleteNamespace("right");
Commons.cleanUp(IMAGE_NAME, K3S);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,8 @@ static void setup() throws Exception {
}

@AfterAll
static void afterAll() throws Exception {
static void afterAll() {
configK8sClientIt(Phase.DELETE);
Commons.cleanUp(IMAGE_NAME, K3S);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ 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 {
// save image
try (SaveImageCmd saveImageCmd = container.getDockerClient().saveImageCmd(image)) {
Expand Down Expand Up @@ -182,22 +185,6 @@ public static void load(K3sContainer container, String tarName, String imageName
}
}

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.
*/
Expand All @@ -220,14 +207,6 @@ public static void pullImage(String image, String tag, K3sContainer container) t

}

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);
Expand Down Expand Up @@ -269,4 +248,15 @@ public static void waitForLogStatement(String message, K3sContainer k3sContainer

}

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;
});
}

}

0 comments on commit 4466d78

Please sign in to comment.