fix build by waiting for the reload logs to be present (#1201)
This commit is contained in:
@@ -46,9 +46,9 @@ public class KubernetesConfigTestBase {
|
||||
protected void setup(Class<?> mockClientConfiguration, String... env) {
|
||||
String[] properties = Stream.concat(Arrays.stream(commonProperties), Arrays.stream(env)).toArray(String[]::new);
|
||||
context = new SpringApplicationBuilder(PropertyPlaceholderAutoConfiguration.class, mockClientConfiguration,
|
||||
BootstrapConfiguration.class, Fabric8ConfigReloadAutoConfiguration.class, ConfigReloadPropertiesAutoConfiguration.class,
|
||||
RefreshAutoConfiguration.class).web(WebApplicationType.NONE)
|
||||
.properties(properties).run();
|
||||
BootstrapConfiguration.class, Fabric8ConfigReloadAutoConfiguration.class,
|
||||
ConfigReloadPropertiesAutoConfiguration.class, RefreshAutoConfiguration.class)
|
||||
.web(WebApplicationType.NONE).properties(properties).run();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
|
||||
@@ -94,8 +94,8 @@ class ConfigMapEventReloadIT {
|
||||
@Test
|
||||
void testInformFromOneNamespaceEventNotTriggered() throws Exception {
|
||||
manifests("one", Phase.CREATE);
|
||||
assertLogStatement(true, "added configmap informer for namespace");
|
||||
assertLogStatement(false, "added secret informer for namespace");
|
||||
Commons.assertReloadLogStatements("added configmap informer for namespace",
|
||||
"added secret informer for namespace", IMAGE_NAME);
|
||||
|
||||
WebClient webClient = builder().baseUrl("localhost/left").build();
|
||||
String result = webClient.method(HttpMethod.GET).retrieve().bodyToMono(String.class).retryWhen(retrySpec())
|
||||
@@ -138,8 +138,8 @@ class ConfigMapEventReloadIT {
|
||||
@Test
|
||||
void testInformFromOneNamespaceEventTriggered() throws Exception {
|
||||
manifests("two", Phase.CREATE);
|
||||
assertLogStatement(true, "added configmap informer for namespace");
|
||||
assertLogStatement(false, "added secret informer for namespace");
|
||||
Commons.assertReloadLogStatements("added configmap informer for namespace",
|
||||
"added secret informer for namespace", IMAGE_NAME);
|
||||
|
||||
// read the value from the right-configmap
|
||||
WebClient webClient = builder().baseUrl("localhost/right").build();
|
||||
@@ -180,10 +180,8 @@ class ConfigMapEventReloadIT {
|
||||
@Test
|
||||
void testInform() throws Exception {
|
||||
manifests("three", Phase.CREATE);
|
||||
// wait a little for the logs to be available
|
||||
LockSupport.parkNanos(TimeUnit.SECONDS.toNanos(10));
|
||||
assertLogStatement(true, "added configmap informer for namespace");
|
||||
assertLogStatement(false, "added secret informer for namespace");
|
||||
Commons.assertReloadLogStatements("added configmap informer for namespace",
|
||||
"added secret informer for namespace", IMAGE_NAME);
|
||||
|
||||
// read the initial value from the right-configmap
|
||||
WebClient rightWebClient = builder().baseUrl("localhost/right").build();
|
||||
@@ -278,23 +276,6 @@ class ConfigMapEventReloadIT {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* assert that only config map logs are present, not secrets.
|
||||
*/
|
||||
private void assertLogStatement(boolean contains, String log) throws Exception {
|
||||
String appPodName = K3S
|
||||
.execInContainer("kubectl", "get", "pods", "-l",
|
||||
"app=spring-cloud-kubernetes-client-configmap-event-reload", "-o=name", "--no-headers")
|
||||
.getStdout();
|
||||
String allLogs = K3S.execInContainer("kubectl", "logs", appPodName.trim()).getStdout();
|
||||
if (contains) {
|
||||
Assertions.assertTrue(allLogs.contains(log));
|
||||
}
|
||||
else {
|
||||
Assertions.assertFalse(allLogs.contains(log));
|
||||
}
|
||||
}
|
||||
|
||||
private WebClient.Builder builder() {
|
||||
return WebClient.builder().clientConnector(new ReactorClientHttpConnector(HttpClient.create()));
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ import io.kubernetes.client.openapi.models.V1Secret;
|
||||
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;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.k3s.K3sContainer;
|
||||
@@ -51,7 +50,7 @@ class SecretsEventReloadIT {
|
||||
|
||||
private static final String PROPERTY_URL = "localhost:80/key";
|
||||
|
||||
private static final String K8S_CONFIG_CLIENT_IT_SERVICE_NAME = "spring-cloud-kubernetes-client-secrets-event-reload";
|
||||
private static final String IMAGE_NAME = "spring-cloud-kubernetes-client-secrets-event-reload";
|
||||
|
||||
private static final String NAMESPACE = "default";
|
||||
|
||||
@@ -64,8 +63,8 @@ class SecretsEventReloadIT {
|
||||
@BeforeAll
|
||||
static void setup() throws Exception {
|
||||
K3S.start();
|
||||
Commons.validateImage(K8S_CONFIG_CLIENT_IT_SERVICE_NAME, K3S);
|
||||
Commons.loadSpringCloudKubernetesImage(K8S_CONFIG_CLIENT_IT_SERVICE_NAME, K3S);
|
||||
Commons.validateImage(IMAGE_NAME, K3S);
|
||||
Commons.loadSpringCloudKubernetesImage(IMAGE_NAME, K3S);
|
||||
util = new Util(K3S);
|
||||
coreV1Api = new CoreV1Api();
|
||||
util.setUp(NAMESPACE);
|
||||
@@ -73,7 +72,7 @@ class SecretsEventReloadIT {
|
||||
|
||||
@AfterAll
|
||||
static void afterAll() throws Exception {
|
||||
Commons.cleanUp(K8S_CONFIG_CLIENT_IT_SERVICE_NAME, K3S);
|
||||
Commons.cleanUp(IMAGE_NAME, K3S);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
@@ -84,8 +83,8 @@ class SecretsEventReloadIT {
|
||||
@Test
|
||||
void testSecretReload() throws Exception {
|
||||
configK8sClientIt(Phase.CREATE);
|
||||
assertLogStatement(false, "added configmap informer for namespace");
|
||||
assertLogStatement(true, "added secret informer for namespace");
|
||||
Commons.assertReloadLogStatements("added secret informer for namespace",
|
||||
"added configmap informer for namespace", IMAGE_NAME);
|
||||
testSecretEventReload();
|
||||
}
|
||||
|
||||
@@ -125,23 +124,6 @@ class SecretsEventReloadIT {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* assert that only config map logs are present, not secrets.
|
||||
*/
|
||||
private void assertLogStatement(boolean contains, String log) throws Exception {
|
||||
String appPodName = K3S
|
||||
.execInContainer("kubectl", "get", "pods", "-l",
|
||||
"app=spring-cloud-kubernetes-client-secrets-event-reload", "-o=name", "--no-headers")
|
||||
.getStdout();
|
||||
String allLogs = K3S.execInContainer("kubectl", "logs", appPodName.trim()).getStdout();
|
||||
if (contains) {
|
||||
Assertions.assertTrue(allLogs.contains(log));
|
||||
}
|
||||
else {
|
||||
Assertions.assertFalse(allLogs.contains(log));
|
||||
}
|
||||
}
|
||||
|
||||
private WebClient.Builder builder() {
|
||||
return WebClient.builder().clientConnector(new ReactorClientHttpConnector(HttpClient.create()));
|
||||
}
|
||||
|
||||
@@ -100,8 +100,8 @@ class ConfigMapEventReloadIT {
|
||||
@Test
|
||||
void testInformFromOneNamespaceEventNotTriggered() {
|
||||
manifests("one", Phase.CREATE);
|
||||
assertLogStatement(true, "added configmap informer for namespace");
|
||||
assertLogStatement(false, "added secret informer for namespace");
|
||||
Commons.assertReloadLogStatements("added configmap informer for namespace",
|
||||
"added secret informer for namespace", IMAGE_NAME);
|
||||
|
||||
WebClient webClient = builder().baseUrl("localhost/left").build();
|
||||
String result = webClient.method(HttpMethod.GET).retrieve().bodyToMono(String.class).retryWhen(retrySpec())
|
||||
@@ -144,8 +144,8 @@ class ConfigMapEventReloadIT {
|
||||
@Test
|
||||
void testInformFromOneNamespaceEventTriggered() {
|
||||
manifests("two", Phase.CREATE);
|
||||
assertLogStatement(true, "added configmap informer for namespace");
|
||||
assertLogStatement(false, "added secret informer for namespace");
|
||||
Commons.assertReloadLogStatements("added configmap informer for namespace",
|
||||
"added secret informer for namespace", IMAGE_NAME);
|
||||
|
||||
// read the value from the right-configmap
|
||||
WebClient webClient = builder().baseUrl("localhost/right").build();
|
||||
@@ -185,8 +185,8 @@ class ConfigMapEventReloadIT {
|
||||
@Test
|
||||
void testInform() {
|
||||
manifests("three", Phase.CREATE);
|
||||
assertLogStatement(true, "added configmap informer for namespace");
|
||||
assertLogStatement(false, "added secret informer for namespace");
|
||||
Commons.assertReloadLogStatements("added configmap informer for namespace",
|
||||
"added secret informer for namespace", IMAGE_NAME);
|
||||
|
||||
// read the initial value from the right-configmap
|
||||
WebClient rightWebClient = builder().baseUrl("localhost/right").build();
|
||||
@@ -288,24 +288,6 @@ class ConfigMapEventReloadIT {
|
||||
|
||||
}
|
||||
|
||||
private void assertLogStatement(boolean contains, String log) {
|
||||
try {
|
||||
String appPodName = K3S.execInContainer("kubectl", "get", "pods", "-l",
|
||||
"app=spring-cloud-kubernetes-fabric8-client-configmap-event-reload", "-o=name", "--no-headers")
|
||||
.getStdout();
|
||||
String allLogs = K3S.execInContainer("kubectl", "logs", appPodName.trim()).getStdout();
|
||||
if (contains) {
|
||||
Assertions.assertTrue(allLogs.contains(log));
|
||||
}
|
||||
else {
|
||||
Assertions.assertFalse(allLogs.contains(log));
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private WebClient.Builder builder() {
|
||||
return WebClient.builder().clientConnector(new ReactorClientHttpConnector(HttpClient.create()));
|
||||
}
|
||||
|
||||
@@ -82,8 +82,8 @@ class SecretsEventsReloadIT {
|
||||
|
||||
@Test
|
||||
void test() {
|
||||
assertLogStatement(false, "added configmap informer for namespace");
|
||||
assertLogStatement(true, "added secret informer for namespace");
|
||||
Commons.assertReloadLogStatements("added secret informer for namespace",
|
||||
"added configmap informer for namespace", IMAGE_NAME);
|
||||
WebClient webClient = builder().baseUrl("localhost/key").build();
|
||||
String result = webClient.method(HttpMethod.GET).retrieve().bodyToMono(String.class).retryWhen(retrySpec())
|
||||
.block();
|
||||
@@ -129,27 +129,6 @@ class SecretsEventsReloadIT {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* assert that only config map logs are present, not secrets.
|
||||
*/
|
||||
private void assertLogStatement(boolean contains, String log) {
|
||||
try {
|
||||
String appPodName = K3S.execInContainer("kubectl", "get", "pods", "-l",
|
||||
"app=spring-cloud-kubernetes-fabric8-client-secrets-event-reload", "-o=name", "--no-headers")
|
||||
.getStdout();
|
||||
String allLogs = K3S.execInContainer("kubectl", "logs", appPodName.trim()).getStdout();
|
||||
if (contains) {
|
||||
Assertions.assertTrue(allLogs.contains(log));
|
||||
}
|
||||
else {
|
||||
Assertions.assertFalse(allLogs.contains(log));
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private WebClient.Builder builder() {
|
||||
return WebClient.builder().clientConnector(new ReactorClientHttpConnector(HttpClient.create()));
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.Duration;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@@ -30,6 +31,9 @@ import com.github.dockerjava.api.command.ListImagesCmd;
|
||||
import com.github.dockerjava.api.command.PullImageCmd;
|
||||
import com.github.dockerjava.api.command.SaveImageCmd;
|
||||
import com.github.dockerjava.api.model.Image;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.testcontainers.containers.Container;
|
||||
import org.testcontainers.k3s.K3sContainer;
|
||||
import org.testcontainers.utility.DockerImageName;
|
||||
@@ -39,6 +43,8 @@ import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static org.awaitility.Awaitility.await;
|
||||
|
||||
/**
|
||||
* A few commons things that can be re-used across clients. This is meant to be used for
|
||||
* testing purposes only.
|
||||
@@ -47,6 +53,8 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
public final class Commons {
|
||||
|
||||
private static final Log LOG = LogFactory.getLog(Commons.class);
|
||||
|
||||
private Commons() {
|
||||
throw new AssertionError("No instance provided");
|
||||
}
|
||||
@@ -86,6 +94,35 @@ public final class Commons {
|
||||
loadImage("springcloud/" + project, pomVersion(), project, container);
|
||||
}
|
||||
|
||||
/**
|
||||
* assert that "left" is present and if so, "right" is not.
|
||||
*/
|
||||
public static void assertReloadLogStatements(String left, String right, String appLabel) {
|
||||
|
||||
try {
|
||||
String appPodName = CONTAINER
|
||||
.execInContainer("kubectl", "get", "pods", "-l", "app=" + appLabel, "-o=name", "--no-headers")
|
||||
.getStdout();
|
||||
await().pollInterval(Duration.ofSeconds(5)).atMost(Duration.ofSeconds(180)).until(() -> {
|
||||
|
||||
String allLogs = CONTAINER.execInContainer("kubectl", "logs", appPodName.trim()).getStdout();
|
||||
LOG.info("==========================================================================================");
|
||||
LOG.info(allLogs);
|
||||
LOG.info("==========================================================================================");
|
||||
if (allLogs.contains(left)) {
|
||||
Assertions.assertFalse(allLogs.contains(right));
|
||||
return true;
|
||||
}
|
||||
LOG.info("log statement not yet present");
|
||||
return false;
|
||||
});
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void loadImage(String image, String tag, String tarName, K3sContainer container) throws Exception {
|
||||
// save image
|
||||
try (SaveImageCmd saveImageCmd = container.getDockerClient().saveImageCmd(image)) {
|
||||
|
||||
Reference in New Issue
Block a user