Skip to content

Commit

Permalink
Merge branch '3.0.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanjbaxter committed Sep 11, 2023
2 parents b96f224 + 24760a5 commit f946329
Showing 1 changed file with 51 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,17 @@
package org.springframework.cloud.kubernetes.client.config.it;

import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import io.kubernetes.client.openapi.ApiException;
import io.kubernetes.client.openapi.apis.CoreV1Api;
import io.kubernetes.client.openapi.models.V1ConfigMap;
import io.kubernetes.client.openapi.models.V1Deployment;
import io.kubernetes.client.openapi.models.V1EnvVar;
import io.kubernetes.client.openapi.models.V1EnvVarBuilder;
import io.kubernetes.client.openapi.models.V1Ingress;
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;
Expand All @@ -49,12 +44,34 @@
import org.springframework.web.reactive.function.client.WebClient;

import static org.awaitility.Awaitility.await;
import static org.springframework.cloud.kubernetes.integration.tests.commons.native_client.Util.patchWithReplace;

/**
* @author Ryan Baxter
*/
class ConfigMapAndSecretIT {

private static final String BODY = """
{
"spec": {
"template": {
"spec": {
"containers": [{
"name": "spring-cloud-kubernetes-client-config-it-deployment",
"image": "image_name_here",
"env": [
{
"name": "SPRING_CLOUD_KUBERNETES_RELOAD_MODE",
"value": "POLLING"
}
]
}]
}
}
}
}
""";

private static final String PROPERTY_URL = "http://localhost:80/myProperty";

private static final String SECRET_URL = "http://localhost:80/mySecret";
Expand All @@ -65,6 +82,8 @@ class ConfigMapAndSecretIT {

private static final String APP_NAME = "spring-cloud-kubernetes-client-config-it";

private static final String DOCKER_IMAGE = "docker.io/springcloud/" + APP_NAME + ":" + Commons.pomVersion();

private static final K3sContainer K3S = Commons.container();

private static Util util;
Expand All @@ -83,24 +102,22 @@ static void setup() throws Exception {

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

@AfterEach
void after() {
configK8sClientIt(false, Phase.DELETE);
}

@Test
void testConfigMapAndSecretWatchRefresh() {
configK8sClientIt(false, Phase.CREATE);
configK8sClientIt(Phase.CREATE);
testConfigMapAndSecretRefresh();

testConfigMapAndSecretPollingRefresh();
}

@Test
void testConfigMapAndSecretPollingRefresh() {
configK8sClientIt(true, Phase.CREATE);
recreateConfigMapAndSecret();
patchForPollingReload();
testConfigMapAndSecretRefresh();
}

Expand Down Expand Up @@ -149,18 +166,25 @@ void testConfigMapAndSecretRefresh() {
.method(HttpMethod.GET).retrieve().bodyToMono(String.class).block().equals("p455w1rd"));
}

private static void configK8sClientIt(boolean pooling, Phase phase) {
V1Deployment deployment = (V1Deployment) util.yaml("spring-cloud-kubernetes-client-config-it-deployment.yaml");
void recreateConfigMapAndSecret() {
try {
coreV1Api.deleteNamespacedConfigMap("spring-cloud-kubernetes-client-config-it", NAMESPACE,
null, null, null, null, null, null);
coreV1Api.deleteNamespacedSecret("spring-cloud-kubernetes-client-config-it", NAMESPACE,
null, null, null, null, null, null);

if (pooling) {
V1EnvVar one = new V1EnvVarBuilder().withName("SPRING_CLOUD_KUBERNETES_RELOAD_MODE").withValue("polling")
.build();
List<V1EnvVar> existing = new ArrayList<>(
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getEnv());
existing.add(one);
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).setEnv(existing);
V1ConfigMap configMap = (V1ConfigMap) util.yaml("spring-cloud-kubernetes-client-config-it-configmap.yaml");
V1Secret secret = (V1Secret) util.yaml("spring-cloud-kubernetes-client-config-it-secret.yaml");
util.createAndWait(NAMESPACE, configMap, secret);
}
catch (ApiException e) {
throw new RuntimeException(e);
}
}

private static void configK8sClientIt(Phase phase) {

V1Deployment deployment = (V1Deployment) util.yaml("spring-cloud-kubernetes-client-config-it-deployment.yaml");
V1Service service = (V1Service) util.yaml("spring-cloud-kubernetes-client-config-it-service.yaml");
V1Ingress ingress = (V1Ingress) util.yaml("spring-cloud-kubernetes-client-config-it-ingress.yaml");

Expand All @@ -185,4 +209,9 @@ private RetryBackoffSpec retrySpec() {
return Retry.fixedDelay(15, Duration.ofSeconds(1)).filter(Objects::nonNull);
}

private static void patchForPollingReload() {
patchWithReplace(ConfigMapAndSecretIT.DOCKER_IMAGE, ConfigMapAndSecretIT.APP_NAME + "-deployment",
ConfigMapAndSecretIT.NAMESPACE, BODY);
}

}

1 comment on commit f946329

@wind57
Copy link
Contributor

@wind57 wind57 commented on f946329 Sep 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a fix coming for the failure ..

Please sign in to comment.