Fabric8 it part 6 (#1471)
This commit is contained in:
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.fabric8.reload;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Map;
|
||||
|
||||
import io.fabric8.kubernetes.api.model.ConfigMap;
|
||||
import io.fabric8.kubernetes.api.model.ConfigMapBuilder;
|
||||
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder;
|
||||
import io.fabric8.kubernetes.client.KubernetesClient;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.web.client.HttpServerErrorException;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
import static org.awaitility.Awaitility.await;
|
||||
|
||||
/**
|
||||
* @author wind57
|
||||
*/
|
||||
final class ConfigMapPollingReloadDelegate {
|
||||
|
||||
static void testConfigMapPollingReload(KubernetesClient client) {
|
||||
WebClient webClient = TestUtil.builder().baseUrl("http://localhost/key").build();
|
||||
String result = webClient.method(HttpMethod.GET).retrieve().bodyToMono(String.class)
|
||||
.retryWhen(TestUtil.retrySpec()).block();
|
||||
|
||||
// we first read the initial value from the configmap
|
||||
Assertions.assertEquals("as-mount-initial", result);
|
||||
|
||||
// then deploy a new version of configmap
|
||||
// since we poll and have reload in place, the new property must be visible
|
||||
ConfigMap map = new ConfigMapBuilder()
|
||||
.withMetadata(new ObjectMetaBuilder().withNamespace("default").withName("poll-reload").build())
|
||||
.withData(Map.of("application.properties", "from.properties.key=after-change")).build();
|
||||
|
||||
client.configMaps().inNamespace("default").resource(map).createOrReplace();
|
||||
|
||||
await().ignoreException(HttpServerErrorException.BadGateway.class).timeout(Duration.ofSeconds(120))
|
||||
.until(() -> webClient.method(HttpMethod.GET).retrieve().bodyToMono(String.class)
|
||||
.retryWhen(TestUtil.retrySpec()).block().equals("after-change"));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -136,7 +136,6 @@ class Fabric8EventReloadIT {
|
||||
testInform();
|
||||
testInformFromOneNamespaceEventTriggeredSecretsDisabled();
|
||||
testDataChangesInConfigMap();
|
||||
testConfigMapPollingReload();
|
||||
testConfigMapMountPollingReload();
|
||||
testPollingReloadConfigMapWithBootstrap();
|
||||
testSecretReload();
|
||||
@@ -303,26 +302,21 @@ class Fabric8EventReloadIT {
|
||||
DataChangesInConfigMapReloadDelegate.testDataChangesInConfigMap(client, K3S, IMAGE_NAME);
|
||||
}
|
||||
|
||||
void testConfigMapPollingReload() {
|
||||
TestUtil.patchFive(util, DOCKER_IMAGE, IMAGE_NAME, NAMESPACE);
|
||||
ConfigMapPollingReloadDelegate.testConfigMapPollingReload(client);
|
||||
}
|
||||
|
||||
void testConfigMapMountPollingReload() {
|
||||
TestUtil.reCreateSources(util, client);
|
||||
TestUtil.patchSix(util, DOCKER_IMAGE, IMAGE_NAME, NAMESPACE);
|
||||
TestUtil.patchFive(util, DOCKER_IMAGE, IMAGE_NAME, NAMESPACE);
|
||||
ConfigMapMountPollingReloadDelegate.testConfigMapMountPollingReload(client, util, K3S, IMAGE_NAME);
|
||||
}
|
||||
|
||||
void testPollingReloadConfigMapWithBootstrap() {
|
||||
TestUtil.reCreateSources(util, client);
|
||||
TestUtil.patchSeven(util, DOCKER_IMAGE, IMAGE_NAME, NAMESPACE);
|
||||
TestUtil.patchSix(util, DOCKER_IMAGE, IMAGE_NAME, NAMESPACE);
|
||||
BootstrapEnabledPollingReloadConfigMapMountDelegate.testPollingReloadConfigMapWithBootstrap(client, util, K3S,
|
||||
IMAGE_NAME);
|
||||
}
|
||||
|
||||
void testSecretReload() {
|
||||
TestUtil.patchEight(util, DOCKER_IMAGE, IMAGE_NAME, NAMESPACE);
|
||||
TestUtil.patchSeven(util, DOCKER_IMAGE, IMAGE_NAME, NAMESPACE);
|
||||
SecretsEventsReloadDelegate.testSecretReload(client, K3S, IMAGE_NAME);
|
||||
}
|
||||
|
||||
|
||||
@@ -171,31 +171,6 @@ final class TestUtil {
|
||||
""";
|
||||
|
||||
private static final String BODY_FIVE = """
|
||||
{
|
||||
"spec": {
|
||||
"template": {
|
||||
"spec": {
|
||||
"containers": [{
|
||||
"name": "spring-cloud-kubernetes-fabric8-client-configmap-event-reload",
|
||||
"image": "image_name_here",
|
||||
"env": [
|
||||
{
|
||||
"name": "SPRING_PROFILES_ACTIVE",
|
||||
"value": "no-mount"
|
||||
},
|
||||
{
|
||||
"name": "SPRING_CLOUD_BOOTSTRAP_ENABLED",
|
||||
"value": "FALSE"
|
||||
}
|
||||
]
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
private static final String BODY_SIX = """
|
||||
{
|
||||
"spec": {
|
||||
"template": {
|
||||
@@ -247,7 +222,7 @@ final class TestUtil {
|
||||
}
|
||||
""";
|
||||
|
||||
private static final String BODY_SEVEN = """
|
||||
private static final String BODY_SIX = """
|
||||
{
|
||||
"spec": {
|
||||
"template": {
|
||||
@@ -299,7 +274,7 @@ final class TestUtil {
|
||||
}
|
||||
""";
|
||||
|
||||
private static final String BODY_EIGHT = """
|
||||
private static final String BODY_SEVEN = """
|
||||
{
|
||||
"spec": {
|
||||
"template": {
|
||||
@@ -370,10 +345,6 @@ final class TestUtil {
|
||||
util.patchWithReplace(dockerImage, deploymentName, namespace, BODY_SEVEN, POD_LABELS);
|
||||
}
|
||||
|
||||
static void patchEight(Util util, String dockerImage, String deploymentName, String namespace) {
|
||||
util.patchWithReplace(dockerImage, deploymentName, namespace, BODY_EIGHT, POD_LABELS);
|
||||
}
|
||||
|
||||
static WebClient.Builder builder() {
|
||||
return WebClient.builder().clientConnector(new ReactorClientHttpConnector(HttpClient.create()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user