profiles() {
return Arrays.asList(environment.getActiveProfiles());
}
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/java/org/springframework/cloud/kubernetes/fabric8/client/reload/ConfigMapProperties.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/java/org/springframework/cloud/kubernetes/fabric8/client/reload/ConfigMapProperties.java
index bb3fb709e1..5376e65c88 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/java/org/springframework/cloud/kubernetes/fabric8/client/reload/ConfigMapProperties.java
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/java/org/springframework/cloud/kubernetes/fabric8/client/reload/ConfigMapProperties.java
@@ -22,15 +22,15 @@
* @author wind57
*/
@ConfigurationProperties("from.properties")
-public class ConfigMapProperties {
+class ConfigMapProperties {
private String key;
- public String getKey() {
+ String getKey() {
return key;
}
- public void setKey(String key1) {
+ void setKey(String key1) {
this.key = key1;
}
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/java/org/springframework/cloud/kubernetes/fabric8/client/reload/Controller.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/java/org/springframework/cloud/kubernetes/fabric8/client/reload/Controller.java
index 12469a7fff..5a190760cd 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/java/org/springframework/cloud/kubernetes/fabric8/client/reload/Controller.java
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/java/org/springframework/cloud/kubernetes/fabric8/client/reload/Controller.java
@@ -23,51 +23,17 @@
* @author wind57
*/
@RestController
-public class Controller {
-
- private final LeftProperties leftProperties;
-
- private final RightProperties rightProperties;
-
- private final RightWithLabelsProperties rightWithLabelsProperties;
+class Controller {
private final ConfigMapProperties configMapProperties;
- private final SecretProperties secretProperties;
-
- public Controller(LeftProperties leftProperties, RightProperties rightProperties,
- RightWithLabelsProperties rightWithLabelsProperties, ConfigMapProperties configMapProperties,
- SecretProperties secretProperties) {
- this.leftProperties = leftProperties;
- this.rightProperties = rightProperties;
- this.rightWithLabelsProperties = rightWithLabelsProperties;
+ Controller(ConfigMapProperties configMapProperties) {
this.configMapProperties = configMapProperties;
- this.secretProperties = secretProperties;
- }
-
- @GetMapping("/left")
- public String left() {
- return leftProperties.getValue();
- }
-
- @GetMapping("/right")
- public String right() {
- return rightProperties.getValue();
- }
-
- @GetMapping("/with-label")
- public String witLabel() {
- return rightWithLabelsProperties.getValue();
}
@GetMapping("/key")
- public String key() {
+ String key() {
return configMapProperties.getKey();
}
- @GetMapping("/key-from-secret")
- public String keyFromSecret() {
- return secretProperties.getKey();
- }
-
}
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/resources/application-mount.yaml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/resources/application-mount.yaml
index cd1765f5c8..a035e13da0 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/resources/application-mount.yaml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/resources/application-mount.yaml
@@ -14,4 +14,3 @@ spring:
- /tmp/application.properties
config:
import: "kubernetes:"
-
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/resources/application-no-mount.yaml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/resources/application-no-mount.yaml
index baf0f12d35..12bc7a05fd 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/resources/application-no-mount.yaml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/resources/application-no-mount.yaml
@@ -1,7 +1,3 @@
-logging:
- level:
- root: DEBUG
-
spring:
application:
name: poll-reload
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/resources/application-one.yaml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/resources/application-one.yaml
index 988bfb2127..041768896c 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/resources/application-one.yaml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/resources/application-one.yaml
@@ -1,16 +1,14 @@
-logging:
- level:
- root: DEBUG
-
spring:
application:
name: event-reload
cloud:
kubernetes:
+ secrets:
+ enabled: false
reload:
enabled: true
- strategy: shutdown
+ strategy: refresh
mode: event
namespaces:
- - left
+ - right
monitoring-config-maps: true
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/resources/application-two.yaml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/resources/application-two.yaml
index 43ae273796..1945840e95 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/resources/application-two.yaml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/resources/application-two.yaml
@@ -1,7 +1,3 @@
-logging:
- level:
- root: DEBUG
-
spring:
application:
name: event-reload
@@ -9,8 +5,11 @@ spring:
kubernetes:
reload:
enabled: true
- strategy: shutdown
+ strategy: refresh
mode: event
namespaces:
- right
monitoring-config-maps: true
+
+ main:
+ cloud-platform: kubernetes
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/resources/application-with-secret.yaml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/resources/application-with-secret.yaml
index bd33ead110..ffd1487b59 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/resources/application-with-secret.yaml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/resources/application-with-secret.yaml
@@ -1,7 +1,3 @@
-logging:
- level:
- root: DEBUG
-
spring:
application:
name: event-reload
@@ -12,11 +8,18 @@ spring:
reload:
enabled: true
monitoring-secrets: true
- strategy: shutdown
+ strategy: refresh
mode: event
monitoring-configMaps: false
+ config:
+ enabled: false
+ enable-api: false
secrets:
enabled: true
enable-api: true
+ # otherwise we can't refresh in the test
+ main:
+ cloud-platform: kubernetes
+
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/resources/bootstrap-one.yaml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/resources/bootstrap-one.yaml
index 9265fce12e..035e8e8410 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/resources/bootstrap-one.yaml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/resources/bootstrap-one.yaml
@@ -1,13 +1,13 @@
-logging:
- level:
- root: DEBUG
-
spring:
cloud:
kubernetes:
config:
sources:
- - namespace: left
- name: left-configmap
- namespace: right
name: right-configmap
+
+ # otherwise on context refresh we lose this property
+ # and test fails, since beans are not wired.
+ main:
+ cloud-platform: kubernetes
+
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/resources/bootstrap-three.yaml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/resources/bootstrap-three.yaml
index 5c5f360585..2463e20a97 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/resources/bootstrap-three.yaml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/resources/bootstrap-three.yaml
@@ -1,15 +1,15 @@
-logging:
- level:
- root: DEBUG
-
spring:
cloud:
kubernetes:
config:
sources:
- - namespace: left
- name: left-configmap
- namespace: right
name: right-configmap
- namespace: right
name: right-configmap-with-label
+
+
+ # otherwise on context refresh we lose this property
+ # and test fails, since beans are not wired.
+ main:
+ cloud-platform: kubernetes
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/resources/bootstrap-two.yaml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/resources/bootstrap-two.yaml
index 9265fce12e..c4c058b62e 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/resources/bootstrap-two.yaml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/main/resources/bootstrap-two.yaml
@@ -1,13 +1,16 @@
-logging:
- level:
- root: DEBUG
-
spring:
cloud:
kubernetes:
+ secrets:
+ enabled: false
config:
sources:
- namespace: left
name: left-configmap
- namespace: right
name: right-configmap
+
+ # otherwise on context refresh we lose this property
+ # and test fails, since beans are not wired.
+ main:
+ cloud-platform: kubernetes
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/BootstrapEnabledPollingReloadConfigMapMountDelegate.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/BootstrapEnabledPollingReloadConfigMapMountIT.java
similarity index 64%
rename from spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/BootstrapEnabledPollingReloadConfigMapMountDelegate.java
rename to spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/BootstrapEnabledPollingReloadConfigMapMountIT.java
index 0b6c397967..144462bb8f 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/BootstrapEnabledPollingReloadConfigMapMountDelegate.java
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/BootstrapEnabledPollingReloadConfigMapMountIT.java
@@ -23,18 +23,55 @@
import io.fabric8.kubernetes.api.model.ConfigMap;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.utils.Serialization;
-import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.testcontainers.k3s.K3sContainer;
import org.springframework.cloud.kubernetes.commons.config.Constants;
import org.springframework.cloud.kubernetes.integration.tests.commons.Commons;
+import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
import org.springframework.cloud.kubernetes.integration.tests.commons.fabric8_client.Util;
import org.springframework.http.HttpMethod;
import org.springframework.web.reactive.function.client.WebClient;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
+import static org.springframework.cloud.kubernetes.fabric8.client.reload.TestAssertions.builder;
+import static org.springframework.cloud.kubernetes.fabric8.client.reload.TestAssertions.manifests;
+import static org.springframework.cloud.kubernetes.fabric8.client.reload.TestAssertions.retrySpec;
-final class BootstrapEnabledPollingReloadConfigMapMountDelegate {
+/**
+ * @author wind57
+ */
+class BootstrapEnabledPollingReloadConfigMapMountIT {
+
+ private static final String IMAGE_NAME = "spring-cloud-kubernetes-fabric8-client-reload";
+
+ private static final String NAMESPACE = "default";
+
+ private static final K3sContainer K3S = Commons.container();
+
+ private static Util util;
+
+ private static KubernetesClient client;
+
+ @BeforeAll
+ static void beforeAll() throws Exception {
+ K3S.start();
+ Commons.validateImage(IMAGE_NAME, K3S);
+ Commons.loadSpringCloudKubernetesImage(IMAGE_NAME, K3S);
+
+ util = new Util(K3S);
+ client = util.client();
+ util.setUp(NAMESPACE);
+ manifests(Phase.CREATE, util, NAMESPACE);
+ }
+
+ @AfterAll
+ static void afterAll() {
+ manifests(Phase.DELETE, util, NAMESPACE);
+ }
/**
*
@@ -50,27 +87,27 @@ final class BootstrapEnabledPollingReloadConfigMapMountDelegate {
* - our polling will then detect that change, and trigger a reload.
*
*/
- static void testPollingReloadConfigMapWithBootstrap(KubernetesClient client, Util util, K3sContainer container,
- String appLabelValue) {
+ @Test
+ void test() {
// (1)
- Commons.waitForLogStatement("paths property sources : [/tmp/application.properties]", container, appLabelValue);
+ Commons.waitForLogStatement("paths property sources : [/tmp/application.properties]", K3S, IMAGE_NAME);
// (2)
- Commons.waitForLogStatement("will add file-based property source : /tmp/application.properties", container,
- appLabelValue);
+ Commons.waitForLogStatement("will add file-based property source : /tmp/application.properties", K3S,
+ IMAGE_NAME);
// (3)
- WebClient webClient = TestUtil.builder().baseUrl("http://localhost/key").build();
+ WebClient webClient = builder().baseUrl("http://localhost/key").build();
String result = webClient.method(HttpMethod.GET)
.retrieve()
.bodyToMono(String.class)
- .retryWhen(TestUtil.retrySpec())
+ .retryWhen(retrySpec())
.block();
// we first read the initial value from the configmap
- Assertions.assertEquals("as-mount-initial", result);
+ assertThat(result).isEqualTo("as-mount-initial");
// replace data in configmap and wait for k8s to pick it up
// our polling will detect that and restart the app
- InputStream configMapStream = util.inputStream("configmap.yaml");
+ InputStream configMapStream = util.inputStream("manifests/configmap.yaml");
ConfigMap configMap = Serialization.unmarshal(configMapStream, ConfigMap.class);
configMap.setData(Map.of(Constants.APPLICATION_PROPERTIES, "from.properties.key=as-mount-changed"));
client.configMaps().inNamespace("default").resource(configMap).createOrReplace();
@@ -79,10 +116,9 @@ static void testPollingReloadConfigMapWithBootstrap(KubernetesClient client, Uti
.until(() -> webClient.method(HttpMethod.GET)
.retrieve()
.bodyToMono(String.class)
- .retryWhen(TestUtil.retrySpec())
+ .retryWhen(retrySpec())
.block()
.equals("as-mount-changed"));
-
}
}
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/ConfigMapMountPollingReloadDelegate.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/ConfigMapMountPollingReloadDelegateIT.java
similarity index 65%
rename from spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/ConfigMapMountPollingReloadDelegate.java
rename to spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/ConfigMapMountPollingReloadDelegateIT.java
index c0f5fc5d3f..c6a21e6500 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/ConfigMapMountPollingReloadDelegate.java
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/ConfigMapMountPollingReloadDelegateIT.java
@@ -23,21 +23,55 @@
import io.fabric8.kubernetes.api.model.ConfigMap;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.utils.Serialization;
-import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.testcontainers.k3s.K3sContainer;
import org.springframework.cloud.kubernetes.commons.config.Constants;
import org.springframework.cloud.kubernetes.integration.tests.commons.Commons;
+import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
import org.springframework.cloud.kubernetes.integration.tests.commons.fabric8_client.Util;
import org.springframework.http.HttpMethod;
import org.springframework.web.reactive.function.client.WebClient;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
+import static org.springframework.cloud.kubernetes.fabric8.client.reload.TestAssertions.builder;
+import static org.springframework.cloud.kubernetes.fabric8.client.reload.TestAssertions.manifests;
+import static org.springframework.cloud.kubernetes.fabric8.client.reload.TestAssertions.retrySpec;
/**
* @author wind57
*/
-final class ConfigMapMountPollingReloadDelegate {
+class ConfigMapMountPollingReloadDelegateIT {
+
+ private static final String IMAGE_NAME = "spring-cloud-kubernetes-fabric8-client-reload";
+
+ private static final String NAMESPACE = "default";
+
+ private static final K3sContainer K3S = Commons.container();
+
+ private static Util util;
+
+ private static KubernetesClient client;
+
+ @BeforeAll
+ static void beforeAll() throws Exception {
+ K3S.start();
+ Commons.validateImage(IMAGE_NAME, K3S);
+ Commons.loadSpringCloudKubernetesImage(IMAGE_NAME, K3S);
+
+ util = new Util(K3S);
+ client = util.client();
+ util.setUp(NAMESPACE);
+ manifests(Phase.CREATE, util, NAMESPACE);
+ }
+
+ @AfterAll
+ static void afterAll() {
+ manifests(Phase.DELETE, util, NAMESPACE);
+ }
/**
*
@@ -54,27 +88,27 @@ final class ConfigMapMountPollingReloadDelegate {
* - our polling will then detect that change, and trigger a reload.
*
*/
- static void testConfigMapMountPollingReload(KubernetesClient client, Util util, K3sContainer container,
- String appLabelValue) {
+ @Test
+ void test() {
// (1)
- Commons.waitForLogStatement("paths property sources : [/tmp/application.properties]", container, appLabelValue);
+ Commons.waitForLogStatement("paths property sources : [/tmp/application.properties]", K3S, IMAGE_NAME);
// (2)
- Commons.waitForLogStatement("will add file-based property source : /tmp/application.properties", container,
- appLabelValue);
+ Commons.waitForLogStatement("will add file-based property source : /tmp/application.properties", K3S,
+ IMAGE_NAME);
// (3)
- WebClient webClient = TestUtil.builder().baseUrl("http://localhost/key").build();
+ WebClient webClient = builder().baseUrl("http://localhost/key").build();
String result = webClient.method(HttpMethod.GET)
.retrieve()
.bodyToMono(String.class)
- .retryWhen(TestUtil.retrySpec())
+ .retryWhen(retrySpec())
.block();
// we first read the initial value from the configmap
- Assertions.assertEquals("as-mount-initial", result);
+ assertThat(result).isEqualTo("as-mount-initial");
// replace data in configmap and wait for k8s to pick it up
// our polling will detect that and restart the app
- InputStream configMapStream = util.inputStream("configmap.yaml");
+ InputStream configMapStream = util.inputStream("manifests/configmap.yaml");
ConfigMap configMap = Serialization.unmarshal(configMapStream, ConfigMap.class);
configMap.setData(Map.of(Constants.APPLICATION_PROPERTIES, "from.properties.key=as-mount-changed"));
client.configMaps().inNamespace("default").resource(configMap).createOrReplace();
@@ -83,10 +117,9 @@ static void testConfigMapMountPollingReload(KubernetesClient client, Util util,
.until(() -> webClient.method(HttpMethod.GET)
.retrieve()
.bodyToMono(String.class)
- .retryWhen(TestUtil.retrySpec())
+ .retryWhen(retrySpec())
.block()
.equals("as-mount-changed"));
-
}
}
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/DataChangesInConfigMapReloadDelegate.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/DataChangesInConfigMapReloadDelegate.java
deleted file mode 100644
index 26698fe617..0000000000
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/DataChangesInConfigMapReloadDelegate.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Copyright 2013-2023 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.client.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.testcontainers.k3s.K3sContainer;
-
-import org.springframework.cloud.kubernetes.integration.tests.commons.Commons;
-import org.springframework.http.HttpMethod;
-import org.springframework.web.reactive.function.client.WebClient;
-
-import static org.awaitility.Awaitility.await;
-import static org.springframework.cloud.kubernetes.fabric8.client.reload.TestUtil.builder;
-import static org.springframework.cloud.kubernetes.fabric8.client.reload.TestUtil.logs;
-import static org.springframework.cloud.kubernetes.fabric8.client.reload.TestUtil.replaceConfigMap;
-import static org.springframework.cloud.kubernetes.fabric8.client.reload.TestUtil.retrySpec;
-
-final class DataChangesInConfigMapReloadDelegate {
-
- private static final String IMAGE_NAME = "spring-cloud-kubernetes-fabric8-client-reload";
-
- private static final String LEFT_NAMESPACE = "left";
-
- /**
- *
- * - configMap with no labels and data: left.value = left-initial exists in namespace left
- * - we assert that we can read it correctly first, by invoking localhost/left
- *
- * - then we change the configmap by adding a label, this in turn does not
- * change the result of localhost/left, because the data has not changed.
- *
- * - then we change data inside the config map, and we must see the updated value
- *
- */
- static void testDataChangesInConfigMap(KubernetesClient client, K3sContainer container, String appLabelValue) {
- Commons.assertReloadLogStatements("added configmap informer for namespace",
- "added secret informer for namespace", IMAGE_NAME);
-
- WebClient webClient = builder().baseUrl("http://localhost/" + LEFT_NAMESPACE).build();
- String result = webClient.method(HttpMethod.GET)
- .retrieve()
- .bodyToMono(String.class)
- .retryWhen(retrySpec())
- .block();
-
- // we first read the initial value from the left-configmap
- Assertions.assertEquals("left-initial", result);
-
- // then deploy a new version of left-configmap, but without changing its data,
- // only add a label
- ConfigMap configMap = new ConfigMapBuilder()
- .withMetadata(new ObjectMetaBuilder().withLabels(Map.of("new-label", "abc"))
- .withNamespace("left")
- .withName("left-configmap")
- .build())
- .withData(Map.of("left.value", "left-initial"))
- .build();
-
- replaceConfigMap(client, configMap, "left");
-
- await().pollInterval(Duration.ofSeconds(3)).atMost(Duration.ofSeconds(90)).until(() -> {
- WebClient innerWebClient = builder().baseUrl("http://localhost/" + LEFT_NAMESPACE).build();
- String innerResult = innerWebClient.method(HttpMethod.GET)
- .retrieve()
- .bodyToMono(String.class)
- .retryWhen(retrySpec())
- .block();
- return "left-initial".equals(innerResult);
- });
-
- String logs = logs(container, appLabelValue);
- Assertions.assertTrue(logs.contains("ConfigMap left-configmap was updated in namespace left"));
- Assertions.assertTrue(logs.contains("data in configmap has not changed, will not reload"));
-
- // change data
- configMap = new ConfigMapBuilder()
- .withMetadata(new ObjectMetaBuilder().withLabels(Map.of("new-label", "abc"))
- .withNamespace("left")
- .withName("left-configmap")
- .build())
- .withData(Map.of("left.value", "left-after-change"))
- .build();
-
- replaceConfigMap(client, configMap, "left");
-
- await().pollInterval(Duration.ofSeconds(3)).atMost(Duration.ofSeconds(90)).until(() -> {
- WebClient innerWebClient = builder().baseUrl("http://localhost/" + LEFT_NAMESPACE).build();
- String innerResult = innerWebClient.method(HttpMethod.GET)
- .retrieve()
- .bodyToMono(String.class)
- .retryWhen(retrySpec())
- .block();
- return "left-after-change".equals(innerResult);
- });
-
- }
-
-}
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/Fabric8EventReloadBase.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/Fabric8EventReloadBase.java
new file mode 100644
index 0000000000..4b71862666
--- /dev/null
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/Fabric8EventReloadBase.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2012-2024 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.client.reload;
+
+import io.fabric8.kubernetes.client.Config;
+import io.fabric8.kubernetes.client.KubernetesClient;
+import io.fabric8.kubernetes.client.KubernetesClientBuilder;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.testcontainers.k3s.K3sContainer;
+
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.context.TestConfiguration;
+import org.springframework.boot.test.system.OutputCaptureExtension;
+import org.springframework.cloud.kubernetes.integration.tests.commons.Commons;
+import org.springframework.cloud.kubernetes.integration.tests.commons.fabric8_client.Util;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Primary;
+
+/**
+ * @author wind57
+ */
+@SpringBootTest(classes = { App.class })
+@ExtendWith(OutputCaptureExtension.class)
+abstract class Fabric8EventReloadBase {
+
+ protected static final K3sContainer K3S = Commons.container();
+
+ protected static Util util;
+
+ @BeforeAll
+ protected static void beforeAll() {
+ K3S.start();
+ util = new Util(K3S);
+ }
+
+ @TestConfiguration
+ static class TestConfig {
+
+ @Bean
+ @Primary
+ KubernetesClient kubernetesClient() {
+ String kubeConfigYaml = K3S.getKubeConfigYaml();
+ Config config = Config.fromKubeconfig(kubeConfigYaml);
+ return new KubernetesClientBuilder().withConfig(config).build();
+ }
+
+ }
+
+}
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/Fabric8EventReloadDataChangesInConfigMapIT.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/Fabric8EventReloadDataChangesInConfigMapIT.java
new file mode 100644
index 0000000000..b39d08746a
--- /dev/null
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/Fabric8EventReloadDataChangesInConfigMapIT.java
@@ -0,0 +1,136 @@
+/*
+ * Copyright 2012-2024 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.client.reload;
+
+import java.io.InputStream;
+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 io.fabric8.kubernetes.client.utils.Serialization;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.system.CapturedOutput;
+import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.TestPropertySource;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.awaitility.Awaitility.await;
+import static org.springframework.cloud.kubernetes.fabric8.client.reload.TestAssertions.assertReloadLogStatements;
+import static org.springframework.cloud.kubernetes.fabric8.client.reload.TestAssertions.configMap;
+import static org.springframework.cloud.kubernetes.fabric8.client.reload.TestAssertions.replaceConfigMap;
+
+/**
+ * @author wind57
+ */
+@TestPropertySource(properties = { "spring.main.cloud-platform=kubernetes",
+ "logging.level.org.springframework.cloud.kubernetes.fabric8.config.reload=debug",
+ "spring.cloud.bootstrap.enabled=true" })
+@ActiveProfiles("one")
+class Fabric8EventReloadDataChangesInConfigMapIT extends Fabric8EventReloadBase {
+
+ private static final String NAMESPACE = "right";
+
+ private static ConfigMap configMap;
+
+ @Autowired
+ private RightProperties properties;
+
+ @Autowired
+ private KubernetesClient kubernetesClient;
+
+ @BeforeAll
+ static void beforeAllLocal() {
+ InputStream rightConfigMapStream = util.inputStream("manifests/right-configmap.yaml");
+ configMap = Serialization.unmarshal(rightConfigMapStream, ConfigMap.class);
+
+ util.createNamespace(NAMESPACE);
+ configMap(Phase.CREATE, util, configMap, NAMESPACE);
+ }
+
+ @AfterAll
+ static void afterAllLocal() {
+ configMap(Phase.DELETE, util, configMap, NAMESPACE);
+ util.deleteNamespace(NAMESPACE);
+ }
+
+ /**
+ *
+ * - configMap with no labels and data: right.value = right-initial exists in namespace right
+ *
+ * - then we change the configmap by adding a label, this in turn does not
+ * change the result, because the data has not changed.
+ *
+ * - then we change data inside the config map, and we must see the updated value
+ *
+ */
+ @Test
+ void test(CapturedOutput output) {
+
+ assertReloadLogStatements("added configmap informer for namespace", "added secret informer for namespace",
+ output);
+
+ // we first read the initial value from configmap
+ assertThat(properties.getValue()).isEqualTo("right-initial");
+
+ // then deploy a new version of right-configmap, but without changing its data,
+ // only add a label
+ ConfigMap configMap = new ConfigMapBuilder()
+ .withMetadata(new ObjectMetaBuilder().withLabels(Map.of("new-label", "abc"))
+ .withNamespace(NAMESPACE)
+ .withName("right-configmap")
+ .build())
+ .withData(Map.of("right.value", "right-initial"))
+ .build();
+
+ replaceConfigMap(kubernetesClient, configMap, NAMESPACE);
+
+ await().atMost(Duration.ofSeconds(60))
+ .pollDelay(Duration.ofSeconds(1))
+ .until(() -> output.getOut().contains("ConfigMap right-configmap was updated in namespace right"));
+
+ await().atMost(Duration.ofSeconds(60))
+ .pollDelay(Duration.ofSeconds(1))
+ .until(() -> output.getOut().contains("data in configmap has not changed, will not reload"));
+
+ assertThat(properties.getValue()).isEqualTo("right-initial");
+
+ // change data
+ configMap = new ConfigMapBuilder()
+ .withMetadata(new ObjectMetaBuilder().withLabels(Map.of("new-label", "abc"))
+ .withNamespace(NAMESPACE)
+ .withName("right-configmap")
+ .build())
+ .withData(Map.of("right.value", "right-after-change"))
+ .build();
+
+ replaceConfigMap(kubernetesClient, configMap, NAMESPACE);
+
+ await().atMost(Duration.ofSeconds(60)).pollDelay(Duration.ofSeconds(1)).until(() -> {
+ String afterUpdateRightValue = properties.getValue();
+ return afterUpdateRightValue.equals("right-after-change");
+ });
+ }
+
+}
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/Fabric8EventReloadIT.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/Fabric8EventReloadIT.java
deleted file mode 100644
index 13bda6d496..0000000000
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/Fabric8EventReloadIT.java
+++ /dev/null
@@ -1,399 +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.client.reload;
-
-import java.io.InputStream;
-import java.time.Duration;
-import java.util.Map;
-import java.util.Set;
-
-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.api.model.Secret;
-import io.fabric8.kubernetes.api.model.Service;
-import io.fabric8.kubernetes.api.model.apps.Deployment;
-import io.fabric8.kubernetes.api.model.networking.v1.Ingress;
-import io.fabric8.kubernetes.client.KubernetesClient;
-import io.fabric8.kubernetes.client.utils.Serialization;
-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.k3s.K3sContainer;
-
-import org.springframework.cloud.kubernetes.integration.tests.commons.Commons;
-import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
-import org.springframework.cloud.kubernetes.integration.tests.commons.fabric8_client.Util;
-import org.springframework.http.HttpMethod;
-import org.springframework.web.reactive.function.client.WebClient;
-
-import static org.awaitility.Awaitility.await;
-import static org.springframework.cloud.kubernetes.integration.tests.commons.Commons.pomVersion;
-
-/**
- * @author wind57
- */
-class Fabric8EventReloadIT {
-
- private static final String IMAGE_NAME = "spring-cloud-kubernetes-fabric8-client-reload";
-
- private static final String DOCKER_IMAGE = "docker.io/springcloud/" + IMAGE_NAME + ":" + pomVersion();
-
- private static final String NAMESPACE = "default";
-
- private static final K3sContainer K3S = Commons.container();
-
- private static Util util;
-
- private static KubernetesClient client;
-
- @BeforeAll
- static void beforeAll() throws Exception {
- K3S.start();
- Commons.validateImage(IMAGE_NAME, K3S);
- Commons.loadSpringCloudKubernetesImage(IMAGE_NAME, K3S);
-
- util = new Util(K3S);
- client = util.client();
-
- util.createNamespace("left");
- util.createNamespace("right");
- util.setUpClusterWide(NAMESPACE, Set.of("left", "right"));
- util.setUp(NAMESPACE);
-
- manifests(Phase.CREATE);
- }
-
- @AfterAll
- static void afterAll() {
- util.deleteNamespace("left");
- util.deleteNamespace("right");
-
- manifests(Phase.DELETE);
- }
-
- /**
- *
- * - there are two namespaces : left and right
- * - each of the namespaces has one configmap
- * - we watch the "left" namespace, but make a change in the configmap in the right namespace
- * - as such, no event is triggered and "left-configmap" stays as-is
- *
- */
- @Test
- void testInformFromOneNamespaceEventNotTriggered() {
- Commons.assertReloadLogStatements("added configmap informer for namespace",
- "added secret informer for namespace", IMAGE_NAME);
-
- WebClient webClient = TestUtil.builder().baseUrl("http://localhost/left").build();
- String result = webClient.method(HttpMethod.GET)
- .retrieve()
- .bodyToMono(String.class)
- .retryWhen(TestUtil.retrySpec())
- .block();
-
- // we first read the initial value from the left-configmap
- Assertions.assertEquals("left-initial", result);
-
- // then read the value from the right-configmap
- webClient = TestUtil.builder().baseUrl("http://localhost/right").build();
- result = webClient.method(HttpMethod.GET)
- .retrieve()
- .bodyToMono(String.class)
- .retryWhen(TestUtil.retrySpec())
- .block();
- Assertions.assertEquals("right-initial", result);
-
- // then deploy a new version of right-configmap
- ConfigMap rightConfigMapAfterChange = new ConfigMapBuilder()
- .withMetadata(new ObjectMetaBuilder().withNamespace("right").withName("right-configmap").build())
- .withData(Map.of("right.value", "right-after-change"))
- .build();
-
- TestUtil.replaceConfigMap(client, rightConfigMapAfterChange, "right");
-
- webClient = TestUtil.builder().baseUrl("http://localhost/left").build();
-
- WebClient finalWebClient = webClient;
- await().pollInterval(Duration.ofSeconds(1)).atMost(Duration.ofSeconds(30)).until(() -> {
- String innerResult = finalWebClient.method(HttpMethod.GET)
- .retrieve()
- .bodyToMono(String.class)
- .retryWhen(TestUtil.retrySpec())
- .block();
- // left configmap has not changed, no restart of app has happened
- return "left-initial".equals(innerResult);
- });
-
- testInformFromOneNamespaceEventTriggered();
- testInform();
- testInformFromOneNamespaceEventTriggeredSecretsDisabled();
- testDataChangesInConfigMap();
- testConfigMapMountPollingReload();
- testPollingReloadConfigMapWithBootstrap();
- testSecretReload();
- }
-
- /**
- *
- * - there are two namespaces : left and right
- * - each of the namespaces has one configmap
- * - we watch the "right" namespace and make a change in the configmap in the same
- * namespace
- * - as such, event is triggered and we see the updated value
- *
- */
- void testInformFromOneNamespaceEventTriggered() {
-
- TestUtil.reCreateSources(util, client);
- TestUtil.patchOne(util, DOCKER_IMAGE, IMAGE_NAME, NAMESPACE);
-
- Commons.assertReloadLogStatements("added configmap informer for namespace",
- "added secret informer for namespace", IMAGE_NAME);
-
- // read the value from the right-configmap
- WebClient webClient = TestUtil.builder().baseUrl("http://localhost/right").build();
- String result = webClient.method(HttpMethod.GET)
- .retrieve()
- .bodyToMono(String.class)
- .retryWhen(TestUtil.retrySpec())
- .block();
- Assertions.assertEquals("right-initial", result);
-
- // then deploy a new version of right-configmap
- ConfigMap rightConfigMapAfterChange = new ConfigMapBuilder()
- .withMetadata(new ObjectMetaBuilder().withNamespace("right").withName("right-configmap").build())
- .withData(Map.of("right.value", "right-after-change"))
- .build();
-
- TestUtil.replaceConfigMap(client, rightConfigMapAfterChange, "right");
-
- String[] resultAfterChange = new String[1];
- await().pollInterval(Duration.ofSeconds(3)).atMost(Duration.ofSeconds(90)).until(() -> {
- WebClient innerWebClient = TestUtil.builder().baseUrl("http://localhost/right").build();
- String innerResult = innerWebClient.method(HttpMethod.GET)
- .retrieve()
- .bodyToMono(String.class)
- .retryWhen(TestUtil.retrySpec())
- .block();
- resultAfterChange[0] = innerResult;
- return innerResult != null;
- });
- Assertions.assertEquals("right-after-change", resultAfterChange[0]);
- }
-
- /**
- *
- * - there are two namespaces : left and right (though we do not care about the left
- * one)
- * - left has one configmap : left-configmap
- * - right has two configmaps: right-configmap, right-configmap-with-label
- * - we watch the "right" namespace, but enable tagging; which means that only
- * right-configmap-with-label triggers changes.
- *
- */
- void testInform() {
-
- TestUtil.reCreateSources(util, client);
- TestUtil.patchTwo(util, DOCKER_IMAGE, IMAGE_NAME, 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 = TestUtil.builder().baseUrl("http://localhost/right").build();
- String rightResult = rightWebClient.method(HttpMethod.GET)
- .retrieve()
- .bodyToMono(String.class)
- .retryWhen(TestUtil.retrySpec())
- .block();
- Assertions.assertEquals("right-initial", rightResult);
-
- // then read the initial value from the right-with-label-configmap
- WebClient rightWithLabelWebClient = TestUtil.builder().baseUrl("http://localhost/with-label").build();
- String rightWithLabelResult = rightWithLabelWebClient.method(HttpMethod.GET)
- .retrieve()
- .bodyToMono(String.class)
- .retryWhen(TestUtil.retrySpec())
- .block();
- Assertions.assertEquals("right-with-label-initial", rightWithLabelResult);
-
- // then deploy a new version of right-configmap
- ConfigMap rightConfigMapAfterChange = new ConfigMapBuilder()
- .withMetadata(new ObjectMetaBuilder().withNamespace("right").withName("right-configmap").build())
- .withData(Map.of("right.value", "right-after-change"))
- .build();
-
- TestUtil.replaceConfigMap(client, rightConfigMapAfterChange, "right");
-
- // nothing changes in our app, because we are watching only labeled configmaps
- await().pollInterval(Duration.ofSeconds(1)).atMost(Duration.ofSeconds(30)).until(() -> {
- String innerRightResult = rightWebClient.method(HttpMethod.GET)
- .retrieve()
- .bodyToMono(String.class)
- .retryWhen(TestUtil.retrySpec())
- .block();
- return "right-initial".equals(innerRightResult);
- });
-
- // then deploy a new version of right-with-label-configmap
- ConfigMap rightWithLabelConfigMapAfterChange = new ConfigMapBuilder()
- .withMetadata(new ObjectMetaBuilder().withNamespace("right").withName("right-configmap-with-label").build())
- .withData(Map.of("right.with.label.value", "right-with-label-after-change"))
- .build();
-
- TestUtil.replaceConfigMap(client, rightWithLabelConfigMapAfterChange, "right");
-
- // since we have changed a labeled configmap, app will restart and pick up the new
- // value
- String[] resultAfterChange = new String[1];
- await().pollInterval(Duration.ofSeconds(3)).atMost(Duration.ofSeconds(90)).until(() -> {
- WebClient innerWebClient = TestUtil.builder().baseUrl("http://localhost/with-label").build();
- String innerResult = innerWebClient.method(HttpMethod.GET)
- .retrieve()
- .bodyToMono(String.class)
- .retryWhen(TestUtil.retrySpec())
- .block();
- resultAfterChange[0] = innerResult;
- return innerResult != null;
- });
- Assertions.assertEquals("right-with-label-after-change", resultAfterChange[0]);
-
- // right-configmap now will see the new value also, but only because the other
- // configmap has triggered the restart
- rightResult = rightWebClient.method(HttpMethod.GET)
- .retrieve()
- .bodyToMono(String.class)
- .retryWhen(TestUtil.retrySpec())
- .block();
- Assertions.assertEquals("right-after-change", rightResult);
- }
-
- /**
- *
- * - there are two namespaces : left and right
- * - each of the namespaces has one configmap
- * - secrets are disabled
- * - we watch the "right" namespace and make a change in the configmap in the same
- * namespace
- * - as such, event is triggered and we see the updated value
- *
- */
- void testInformFromOneNamespaceEventTriggeredSecretsDisabled() {
-
- TestUtil.reCreateSources(util, client);
- TestUtil.patchThree(util, DOCKER_IMAGE, IMAGE_NAME, NAMESPACE);
-
- Commons.assertReloadLogStatements("added configmap informer for namespace",
- "added secret informer for namespace", IMAGE_NAME);
-
- // read the value from the right-configmap
- WebClient webClient = TestUtil.builder().baseUrl("http://localhost/right").build();
- String result = webClient.method(HttpMethod.GET)
- .retrieve()
- .bodyToMono(String.class)
- .retryWhen(TestUtil.retrySpec())
- .block();
- Assertions.assertEquals("right-initial", result);
-
- // then deploy a new version of right-configmap
- ConfigMap rightConfigMapAfterChange = new ConfigMapBuilder()
- .withMetadata(new ObjectMetaBuilder().withNamespace("right").withName("right-configmap").build())
- .withData(Map.of("right.value", "right-after-change"))
- .build();
-
- TestUtil.replaceConfigMap(client, rightConfigMapAfterChange, "right");
-
- String[] resultAfterChange = new String[1];
- await().pollInterval(Duration.ofSeconds(3)).atMost(Duration.ofSeconds(90)).until(() -> {
- WebClient innerWebClient = TestUtil.builder().baseUrl("http://localhost/right").build();
- String innerResult = innerWebClient.method(HttpMethod.GET)
- .retrieve()
- .bodyToMono(String.class)
- .retryWhen(TestUtil.retrySpec())
- .block();
- resultAfterChange[0] = innerResult;
- return innerResult != null;
- });
- Assertions.assertEquals("right-after-change", resultAfterChange[0]);
-
- }
-
- void testDataChangesInConfigMap() {
- TestUtil.reCreateSources(util, client);
- TestUtil.patchFour(util, DOCKER_IMAGE, IMAGE_NAME, NAMESPACE);
- DataChangesInConfigMapReloadDelegate.testDataChangesInConfigMap(client, K3S, IMAGE_NAME);
- }
-
- void testConfigMapMountPollingReload() {
- TestUtil.reCreateSources(util, client);
- TestUtil.patchFive(util, DOCKER_IMAGE, IMAGE_NAME, NAMESPACE);
- ConfigMapMountPollingReloadDelegate.testConfigMapMountPollingReload(client, util, K3S, IMAGE_NAME);
- }
-
- void testPollingReloadConfigMapWithBootstrap() {
- TestUtil.reCreateSources(util, client);
- TestUtil.patchSix(util, DOCKER_IMAGE, IMAGE_NAME, NAMESPACE);
- BootstrapEnabledPollingReloadConfigMapMountDelegate.testPollingReloadConfigMapWithBootstrap(client, util, K3S,
- IMAGE_NAME);
- }
-
- void testSecretReload() {
- TestUtil.patchSeven(util, DOCKER_IMAGE, IMAGE_NAME, NAMESPACE);
- SecretsEventsReloadDelegate.testSecretReload(client, K3S, IMAGE_NAME);
- }
-
- private static void manifests(Phase phase) {
-
- InputStream deploymentStream = util.inputStream("deployment.yaml");
- InputStream serviceStream = util.inputStream("service.yaml");
- InputStream ingressStream = util.inputStream("ingress.yaml");
- InputStream leftConfigMapStream = util.inputStream("left-configmap.yaml");
- InputStream rightConfigMapStream = util.inputStream("right-configmap.yaml");
- InputStream rightWithLabelConfigMapStream = util.inputStream("right-configmap-with-label.yaml");
- InputStream configMapAsStream = util.inputStream("configmap.yaml");
- InputStream secretAsStream = util.inputStream("secret.yaml");
-
- Deployment deployment = Serialization.unmarshal(deploymentStream, Deployment.class);
-
- Service service = Serialization.unmarshal(serviceStream, Service.class);
- Ingress ingress = Serialization.unmarshal(ingressStream, Ingress.class);
- ConfigMap leftConfigMap = Serialization.unmarshal(leftConfigMapStream, ConfigMap.class);
- ConfigMap rightConfigMap = Serialization.unmarshal(rightConfigMapStream, ConfigMap.class);
- ConfigMap rightWithLabelConfigMap = Serialization.unmarshal(rightWithLabelConfigMapStream, ConfigMap.class);
- ConfigMap configMap = Serialization.unmarshal(configMapAsStream, ConfigMap.class);
- Secret secret = Serialization.unmarshal(secretAsStream, Secret.class);
-
- if (phase.equals(Phase.CREATE)) {
- util.createAndWait("left", leftConfigMap, null);
- util.createAndWait("right", rightConfigMap, null);
- util.createAndWait("right", rightWithLabelConfigMap, null);
- util.createAndWait(NAMESPACE, configMap, secret);
- util.createAndWait(NAMESPACE, null, deployment, service, ingress, true);
- }
- else {
- util.deleteAndWait("left", leftConfigMap, null);
- util.deleteAndWait("right", rightConfigMap, null);
- util.deleteAndWait("right", rightWithLabelConfigMap, null);
- util.deleteAndWait(NAMESPACE, configMap, secret);
- util.deleteAndWait(NAMESPACE, deployment, service, ingress);
- }
-
- }
-
-}
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/Fabric8EventReloadInformIT.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/Fabric8EventReloadInformIT.java
new file mode 100644
index 0000000000..ceeff4968e
--- /dev/null
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/Fabric8EventReloadInformIT.java
@@ -0,0 +1,129 @@
+/*
+ * Copyright 2012-2024 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.client.reload;
+
+import java.io.InputStream;
+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 io.fabric8.kubernetes.client.utils.Serialization;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.system.CapturedOutput;
+import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.TestPropertySource;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.awaitility.Awaitility.await;
+import static org.springframework.cloud.kubernetes.fabric8.client.reload.TestAssertions.assertReloadLogStatements;
+import static org.springframework.cloud.kubernetes.fabric8.client.reload.TestAssertions.configMap;
+import static org.springframework.cloud.kubernetes.fabric8.client.reload.TestAssertions.replaceConfigMap;
+
+/**
+ * @author wind57
+ */
+@TestPropertySource(properties = { "spring.main.cloud-platform=kubernetes",
+ "logging.level.org.springframework.cloud.kubernetes.fabric8.config.reload=debug",
+ "spring.cloud.bootstrap.enabled=true" })
+@ActiveProfiles("two")
+class Fabric8EventReloadInformIT extends Fabric8EventReloadBase {
+
+ private static final String LEFT_NAMESPACE = "left";
+
+ private static final String RIGHT_NAMESPACE = "right";
+
+ private static ConfigMap leftConfigMap;
+
+ private static ConfigMap rightConfigMap;
+
+ @Autowired
+ private LeftProperties leftProperties;
+
+ @Autowired
+ private RightProperties rightProperties;
+
+ @Autowired
+ private KubernetesClient kubernetesClient;
+
+ @BeforeAll
+ static void beforeAllLocal() {
+ InputStream leftConfigMapStream = util.inputStream("manifests/left-configmap.yaml");
+ InputStream rightConfigMapStream = util.inputStream("manifests/right-configmap.yaml");
+
+ leftConfigMap = Serialization.unmarshal(leftConfigMapStream, ConfigMap.class);
+ rightConfigMap = Serialization.unmarshal(rightConfigMapStream, ConfigMap.class);
+
+ util.createNamespace(LEFT_NAMESPACE);
+ util.createNamespace(RIGHT_NAMESPACE);
+
+ configMap(Phase.CREATE, util, leftConfigMap, LEFT_NAMESPACE);
+ configMap(Phase.CREATE, util, rightConfigMap, RIGHT_NAMESPACE);
+ }
+
+ @AfterAll
+ static void afterAllLocal() {
+ configMap(Phase.DELETE, util, leftConfigMap, LEFT_NAMESPACE);
+ configMap(Phase.DELETE, util, rightConfigMap, RIGHT_NAMESPACE);
+
+ util.deleteNamespace(LEFT_NAMESPACE);
+ util.deleteNamespace(RIGHT_NAMESPACE);
+ }
+
+ /**
+ *
+ * - there are two namespaces : left and right
+ * - each of the namespaces has one configmap
+ * - we watch the "right" namespace and make a change in the configmap in the same
+ * namespace
+ * - as such, event is triggered (refresh happens) and we see the updated value
+ *
+ */
+ @Test
+ void test(CapturedOutput output) {
+ assertReloadLogStatements("added configmap informer for namespace", "added secret informer for namespace",
+ output);
+
+ // first we read these with default values
+ assertThat(leftProperties.getValue()).isEqualTo("left-initial");
+ assertThat(rightProperties.getValue()).isEqualTo("right-initial");
+
+ // then deploy a new version of right-configmap
+ ConfigMap rightConfigMapAfterChange = new ConfigMapBuilder()
+ .withMetadata(new ObjectMetaBuilder().withNamespace(RIGHT_NAMESPACE).withName("right-configmap").build())
+ .withData(Map.of("right.value", "right-after-change"))
+ .build();
+
+ replaceConfigMap(kubernetesClient, rightConfigMapAfterChange, RIGHT_NAMESPACE);
+
+ await().atMost(Duration.ofSeconds(60)).pollDelay(Duration.ofSeconds(1)).until(() -> {
+ String afterUpdateRightValue = rightProperties.getValue();
+ return afterUpdateRightValue.equals("right-after-change");
+ });
+
+ // left does not change
+ assertThat(leftProperties.getValue()).isEqualTo("left-initial");
+ }
+
+}
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/Fabric8EventReloadInformWithLabelIT.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/Fabric8EventReloadInformWithLabelIT.java
new file mode 100644
index 0000000000..044742bbe5
--- /dev/null
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/Fabric8EventReloadInformWithLabelIT.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright 2012-2024 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.client.reload;
+
+import java.io.InputStream;
+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 io.fabric8.kubernetes.client.utils.Serialization;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.system.CapturedOutput;
+import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.TestPropertySource;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.awaitility.Awaitility.await;
+import static org.springframework.cloud.kubernetes.fabric8.client.reload.TestAssertions.assertReloadLogStatements;
+import static org.springframework.cloud.kubernetes.fabric8.client.reload.TestAssertions.configMap;
+import static org.springframework.cloud.kubernetes.fabric8.client.reload.TestAssertions.replaceConfigMap;
+
+/**
+ * @author wind57
+ */
+@TestPropertySource(properties = { "spring.main.cloud-platform=kubernetes",
+ "logging.level.org.springframework.cloud.kubernetes.fabric8.config.reload=debug",
+ "spring.cloud.bootstrap.enabled=true" })
+@ActiveProfiles("three")
+class Fabric8EventReloadInformWithLabelIT extends Fabric8EventReloadBase {
+
+ private static final String RIGHT_NAMESPACE = "right";
+
+ private static ConfigMap rightConfigMap;
+
+ private static ConfigMap rightConfigMapWithLabel;
+
+ @Autowired
+ private KubernetesClient kubernetesClient;
+
+ @Autowired
+ private RightProperties rightProperties;
+
+ @Autowired
+ private RightWithLabelsProperties rightWithLabelsProperties;
+
+ @BeforeAll
+ static void beforeAllLocal() {
+ InputStream rightConfigMapStream = util.inputStream("manifests/right-configmap.yaml");
+ InputStream rightConfigMapWithLabelStream = util.inputStream("manifests/right-configmap-with-label.yaml");
+
+ rightConfigMap = Serialization.unmarshal(rightConfigMapStream, ConfigMap.class);
+ rightConfigMapWithLabel = Serialization.unmarshal(rightConfigMapWithLabelStream, ConfigMap.class);
+
+ util.createNamespace(RIGHT_NAMESPACE);
+
+ configMap(Phase.CREATE, util, rightConfigMap, RIGHT_NAMESPACE);
+ configMap(Phase.CREATE, util, rightConfigMapWithLabel, RIGHT_NAMESPACE);
+ }
+
+ @AfterAll
+ static void afterAllLocal() {
+ configMap(Phase.DELETE, util, rightConfigMap, RIGHT_NAMESPACE);
+ configMap(Phase.DELETE, util, rightConfigMapWithLabel, RIGHT_NAMESPACE);
+ util.deleteNamespace(RIGHT_NAMESPACE);
+ }
+
+ /**
+ *
+ * - there is one namespace : right
+ * - right has two configmaps: right-configmap, right-configmap-with-label
+ * - we watch the "right" namespace, but enable tagging; which means that only
+ * right-configmap-with-label triggers changes.
+ *
+ */
+ @Test
+ void test(CapturedOutput output) {
+ assertReloadLogStatements("added configmap informer for namespace", "added secret informer for namespace",
+ output);
+
+ // read the initial value from the right-configmap
+ assertThat(rightProperties.getValue()).isEqualTo("right-initial");
+
+ // then read the initial value from the right-with-label-configmap
+ assertThat(rightWithLabelsProperties.getValue()).isEqualTo("right-with-label-initial");
+
+ // then deploy a new version of right-configmap
+ ConfigMap rightConfigMapAfterChange = new ConfigMapBuilder()
+ .withMetadata(new ObjectMetaBuilder().withNamespace("right").withName("right-configmap").build())
+ .withData(Map.of("right.value", "right-after-change"))
+ .build();
+
+ replaceConfigMap(kubernetesClient, rightConfigMapAfterChange, RIGHT_NAMESPACE);
+
+ // nothing changes in our app, because we are watching only labeled configmaps
+ assertThat(rightProperties.getValue()).isEqualTo("right-initial");
+ assertThat(rightWithLabelsProperties.getValue()).isEqualTo("right-with-label-initial");
+
+ // then deploy a new version of right-with-label-configmap
+ ConfigMap rightWithLabelConfigMapAfterChange = new ConfigMapBuilder()
+ .withMetadata(new ObjectMetaBuilder().withNamespace("right").withName("right-configmap-with-label").build())
+ .withData(Map.of("right.with.label.value", "right-with-label-after-change"))
+ .build();
+
+ replaceConfigMap(kubernetesClient, rightWithLabelConfigMapAfterChange, RIGHT_NAMESPACE);
+
+ // since we have changed a labeled configmap, app will restart and pick up the new
+ // value
+ await().atMost(Duration.ofSeconds(60)).pollDelay(Duration.ofSeconds(1)).until(() -> {
+ String afterUpdateRightValue = rightWithLabelsProperties.getValue();
+ return afterUpdateRightValue.equals("right-with-label-after-change");
+ });
+
+ // right-configmap now will see the new value also, but only because the other
+ // configmap has triggered the restart
+ await().atMost(Duration.ofSeconds(60)).pollDelay(Duration.ofSeconds(1)).until(() -> {
+ String afterUpdateRightValue = rightProperties.getValue();
+ return afterUpdateRightValue.equals("right-after-change");
+ });
+ }
+
+}
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/Fabric8EventReloadSecretIT.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/Fabric8EventReloadSecretIT.java
new file mode 100644
index 0000000000..f9d869ac58
--- /dev/null
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/Fabric8EventReloadSecretIT.java
@@ -0,0 +1,146 @@
+/*
+ * Copyright 2012-2024 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.client.reload;
+
+import java.io.InputStream;
+import java.time.Duration;
+import java.util.Base64;
+import java.util.Map;
+
+import io.fabric8.kubernetes.api.model.ObjectMetaBuilder;
+import io.fabric8.kubernetes.api.model.Secret;
+import io.fabric8.kubernetes.api.model.SecretBuilder;
+import io.fabric8.kubernetes.client.Config;
+import io.fabric8.kubernetes.client.KubernetesClient;
+import io.fabric8.kubernetes.client.KubernetesClientBuilder;
+import io.fabric8.kubernetes.client.utils.Serialization;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.system.CapturedOutput;
+import org.springframework.cloud.kubernetes.commons.config.Constants;
+import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.TestPropertySource;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.awaitility.Awaitility.await;
+import static org.springframework.cloud.kubernetes.fabric8.client.reload.TestAssertions.assertReloadLogStatements;
+import static org.springframework.cloud.kubernetes.fabric8.client.reload.TestAssertions.replaceSecret;
+import static org.springframework.cloud.kubernetes.fabric8.client.reload.TestAssertions.secret;
+
+/**
+ * @author wind57
+ */
+@TestPropertySource(properties = { "spring.main.cloud-platform=kubernetes",
+ "logging.level.org.springframework.cloud.kubernetes.fabric8.config.reload=debug",
+ "spring.cloud.kubernetes.client.namespace=default" })
+@ActiveProfiles("with-secret")
+class Fabric8EventReloadSecretIT extends Fabric8EventReloadBase {
+
+ private static final String NAMESPACE = "default";
+
+ private static Secret secret;
+
+ @Autowired
+ private KubernetesClient kubernetesClient;
+
+ @Autowired
+ private SecretProperties secretProperties;
+
+ @BeforeAll
+ static void beforeAllLocal() {
+
+ // set system properties very early, so that when
+ // 'Fabric8ConfigDataLocationResolver'
+ // loads KubernetesClient from Config, these would be already present
+ Config config = Config.fromKubeconfig(K3S.getKubeConfigYaml());
+ String caCertData = config.getCaCertData();
+ String clientCertData = config.getClientCertData();
+ String clientKeyData = config.getClientKeyData();
+ String clientKeyAlgo = config.getClientKeyAlgo();
+ String clientKeyPass = config.getClientKeyPassphrase();
+ String masterUrl = new KubernetesClientBuilder().withConfig(config).build().getConfiguration().getMasterUrl();
+
+ System.setProperty(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY, masterUrl);
+ System.setProperty(Config.KUBERNETES_CA_CERTIFICATE_DATA_SYSTEM_PROPERTY, caCertData);
+ System.setProperty(Config.KUBERNETES_CLIENT_CERTIFICATE_DATA_SYSTEM_PROPERTY, clientCertData);
+ System.setProperty(Config.KUBERNETES_CLIENT_KEY_DATA_SYSTEM_PROPERTY, clientKeyData);
+ System.setProperty(Config.KUBERNETES_CLIENT_KEY_ALGO_SYSTEM_PROPERTY, clientKeyAlgo);
+ System.setProperty(Config.KUBERNETES_CLIENT_KEY_PASSPHRASE_SYSTEM_PROPERTY, clientKeyPass);
+
+ InputStream secretStream = util.inputStream("manifests/secret.yaml");
+ secret = Serialization.unmarshal(secretStream, Secret.class);
+ secret(Phase.CREATE, util, secret, NAMESPACE);
+ }
+
+ @AfterAll
+ static void afterAllLocal() {
+ secret(Phase.DELETE, util, secret, NAMESPACE);
+ }
+
+ /**
+ *
+ * - secret with no labels and data: from.secret.properties.key = secret-initial exists in namespace default
+ *
+ * - then we change the secret by adding a label, this in turn does not
+ * change the result
+ *
+ * - then we change data inside the secret, and we must see the updated value.
+ *
+ */
+ @Test
+ void test(CapturedOutput output) {
+ assertReloadLogStatements("added secret informer for namespace", "added configmap informer for namespace",
+ output);
+ assertThat(secretProperties.getKey()).isEqualTo("secret-initial");
+
+ Secret secret = new SecretBuilder()
+ .withMetadata(new ObjectMetaBuilder().withLabels(Map.of("letter", "a"))
+ .withNamespace("default")
+ .withName("event-reload")
+ .build())
+ .withData(Map.of(Constants.APPLICATION_PROPERTIES,
+ Base64.getEncoder().encodeToString("from.secret.properties.key=secret-initial".getBytes())))
+ .build();
+ replaceSecret(kubernetesClient, secret, NAMESPACE);
+
+ await().atMost(Duration.ofSeconds(60))
+ .pollDelay(Duration.ofSeconds(1))
+ .until(() -> output.getOut().contains("Secret event-reload was updated in namespace default"));
+
+ await().atMost(Duration.ofSeconds(60))
+ .pollDelay(Duration.ofSeconds(1))
+ .until(() -> output.getOut().contains("data in secret has not changed, will not reload"));
+ assertThat(secretProperties.getKey()).isEqualTo("secret-initial");
+
+ // change data
+ secret = new SecretBuilder()
+ .withMetadata(new ObjectMetaBuilder().withNamespace("default").withName("event-reload").build())
+ .withData(Map.of(Constants.APPLICATION_PROPERTIES,
+ Base64.getEncoder().encodeToString("from.secret.properties.key=secret-initial-changed".getBytes())))
+ .build();
+ replaceSecret(kubernetesClient, secret, NAMESPACE);
+
+ await().atMost(Duration.ofSeconds(60))
+ .pollDelay(Duration.ofSeconds(1))
+ .until(() -> secretProperties.getKey().equals("secret-initial-changed"));
+ }
+
+}
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/SecretsEventsReloadDelegate.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/SecretsEventsReloadDelegate.java
deleted file mode 100644
index 281608211a..0000000000
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/SecretsEventsReloadDelegate.java
+++ /dev/null
@@ -1,111 +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.client.reload;
-
-import java.time.Duration;
-import java.util.Base64;
-import java.util.Map;
-
-import io.fabric8.kubernetes.api.model.ObjectMetaBuilder;
-import io.fabric8.kubernetes.api.model.Secret;
-import io.fabric8.kubernetes.api.model.SecretBuilder;
-import io.fabric8.kubernetes.client.KubernetesClient;
-import org.junit.jupiter.api.Assertions;
-import org.testcontainers.k3s.K3sContainer;
-
-import org.springframework.cloud.kubernetes.commons.config.Constants;
-import org.springframework.cloud.kubernetes.integration.tests.commons.Commons;
-import org.springframework.http.HttpMethod;
-import org.springframework.web.reactive.function.client.WebClient;
-
-import static org.awaitility.Awaitility.await;
-import static org.springframework.cloud.kubernetes.fabric8.client.reload.TestUtil.builder;
-import static org.springframework.cloud.kubernetes.fabric8.client.reload.TestUtil.retrySpec;
-
-/**
- * @author wind57
- */
-final class SecretsEventsReloadDelegate {
-
- /**
- *
- * - secret with no labels and data: from.secret.properties.key = secret-initial exists in namespace default
- * - we assert that we can read it correctly first, by invoking localhost/key.
- *
- * - then we change the secret by adding a label, this in turn does not
- * change the result of localhost/key, because the data has not changed.
- *
- * - then we change data inside the secret, and we must see the updated value.
- *
- */
- static void testSecretReload(KubernetesClient client, K3sContainer container, String appLabelValue) {
- Commons.assertReloadLogStatements("added secret informer for namespace",
- "added configmap informer for namespace", appLabelValue);
-
- WebClient webClient = builder().baseUrl("http://localhost/key-from-secret").build();
- String result = webClient.method(HttpMethod.GET)
- .retrieve()
- .bodyToMono(String.class)
- .retryWhen(retrySpec())
- .block();
- Assertions.assertEquals("secret-initial", result);
-
- Secret secret = new SecretBuilder()
- .withMetadata(new ObjectMetaBuilder().withLabels(Map.of("letter", "a"))
- .withNamespace("default")
- .withName("event-reload")
- .build())
- .withData(Map.of(Constants.APPLICATION_PROPERTIES,
- Base64.getEncoder().encodeToString("from.secret.properties.key=secret-initial".getBytes())))
- .build();
- client.secrets().inNamespace("default").resource(secret).createOrReplace();
-
- await().pollInterval(Duration.ofSeconds(3)).atMost(Duration.ofSeconds(90)).until(() -> {
- WebClient innerWebClient = builder().baseUrl("http://localhost/key-from-secret").build();
- String innerResult = innerWebClient.method(HttpMethod.GET)
- .retrieve()
- .bodyToMono(String.class)
- .retryWhen(retrySpec())
- .block();
- return "secret-initial".equals(innerResult);
- });
-
- Commons.waitForLogStatement("Secret event-reload was updated in namespace default", container, appLabelValue);
- Commons.waitForLogStatement("data in secret has not changed, will not reload", container, appLabelValue);
-
- // change data
- secret = new SecretBuilder()
- .withMetadata(new ObjectMetaBuilder().withNamespace("default").withName("event-reload").build())
- .withData(Map.of(Constants.APPLICATION_PROPERTIES,
- Base64.getEncoder().encodeToString("from.secret.properties.key=secret-initial-changed".getBytes())))
- .build();
-
- client.secrets().inNamespace("default").resource(secret).createOrReplace();
-
- await().pollInterval(Duration.ofSeconds(3)).atMost(Duration.ofSeconds(90)).until(() -> {
- WebClient innerWebClient = builder().baseUrl("http://localhost/key-from-secret").build();
- String innerResult = innerWebClient.method(HttpMethod.GET)
- .retrieve()
- .bodyToMono(String.class)
- .retryWhen(retrySpec())
- .block();
- return "secret-initial-changed".equals(innerResult);
- });
-
- }
-
-}
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/TestAssertions.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/TestAssertions.java
new file mode 100644
index 0000000000..fb4103eb17
--- /dev/null
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/TestAssertions.java
@@ -0,0 +1,127 @@
+/*
+ * Copyright 2012-2024 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.client.reload;
+
+import java.io.InputStream;
+import java.time.Duration;
+import java.util.Objects;
+
+import io.fabric8.kubernetes.api.model.ConfigMap;
+import io.fabric8.kubernetes.api.model.Secret;
+import io.fabric8.kubernetes.api.model.Service;
+import io.fabric8.kubernetes.api.model.apps.Deployment;
+import io.fabric8.kubernetes.api.model.networking.v1.Ingress;
+import io.fabric8.kubernetes.client.KubernetesClient;
+import io.fabric8.kubernetes.client.utils.Serialization;
+import reactor.netty.http.client.HttpClient;
+import reactor.util.retry.Retry;
+import reactor.util.retry.RetryBackoffSpec;
+
+import org.springframework.boot.test.system.CapturedOutput;
+import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
+import org.springframework.cloud.kubernetes.integration.tests.commons.fabric8_client.Util;
+import org.springframework.http.client.reactive.ReactorClientHttpConnector;
+import org.springframework.web.reactive.function.client.WebClient;
+
+import static org.testcontainers.shaded.org.awaitility.Awaitility.await;
+
+/**
+ * @author wind57
+ */
+final class TestAssertions {
+
+ private TestAssertions() {
+
+ }
+
+ /**
+ * assert that 'left' is present, and IFF it is, assert that 'right' is not
+ */
+ static void assertReloadLogStatements(String left, String right, CapturedOutput output) {
+
+ await().pollDelay(Duration.ofSeconds(5))
+ .atMost(Duration.ofSeconds(15))
+ .pollInterval(Duration.ofSeconds(1))
+ .until(() -> {
+ boolean leftIsPresent = output.getOut().contains(left);
+ if (leftIsPresent) {
+ boolean rightIsPresent = output.getOut().contains(right);
+ return !rightIsPresent;
+ }
+ return false;
+ });
+ }
+
+ static void replaceConfigMap(KubernetesClient client, ConfigMap configMap, String namespace) {
+ client.configMaps().inNamespace(namespace).resource(configMap).update();
+ }
+
+ static void replaceSecret(KubernetesClient client, Secret secret, String namespace) {
+ client.secrets().inNamespace(namespace).resource(secret).update();
+ }
+
+ static void configMap(Phase phase, Util util, ConfigMap configMap, String namespace) {
+ if (phase.equals(Phase.CREATE)) {
+ util.createAndWait(namespace, configMap, null);
+ }
+ else {
+ util.deleteAndWait(namespace, configMap, null);
+ }
+ }
+
+ static void secret(Phase phase, Util util, Secret secret, String namespace) {
+ if (phase.equals(Phase.CREATE)) {
+ util.createAndWait(namespace, null, secret);
+ }
+ else {
+ util.deleteAndWait(namespace, null, secret);
+ }
+ }
+
+ static void manifests(Phase phase, Util util, String namespace) {
+
+ InputStream deploymentStream = util.inputStream("manifests/deployment.yaml");
+ InputStream serviceStream = util.inputStream("manifests/service.yaml");
+ InputStream ingressStream = util.inputStream("manifests/ingress.yaml");
+ InputStream configMapAsStream = util.inputStream("manifests/configmap.yaml");
+
+ Deployment deployment = Serialization.unmarshal(deploymentStream, Deployment.class);
+
+ Service service = Serialization.unmarshal(serviceStream, Service.class);
+ Ingress ingress = Serialization.unmarshal(ingressStream, Ingress.class);
+ ConfigMap configMap = Serialization.unmarshal(configMapAsStream, ConfigMap.class);
+
+ if (phase.equals(Phase.CREATE)) {
+ util.createAndWait(namespace, configMap, null);
+ util.createAndWait(namespace, null, deployment, service, ingress, true);
+ }
+ else {
+ util.deleteAndWait(namespace, configMap, null);
+ util.deleteAndWait(namespace, deployment, service, ingress);
+ }
+
+ }
+
+ static WebClient.Builder builder() {
+ return WebClient.builder().clientConnector(new ReactorClientHttpConnector(HttpClient.create()));
+ }
+
+ static RetryBackoffSpec retrySpec() {
+ return Retry.fixedDelay(120, Duration.ofSeconds(2)).filter(Objects::nonNull);
+ }
+
+}
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/TestUtil.java b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/TestUtil.java
deleted file mode 100644
index 7ede854c6f..0000000000
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/reload/TestUtil.java
+++ /dev/null
@@ -1,372 +0,0 @@
-/*
- * Copyright 2013-2023 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.client.reload;
-
-import java.io.InputStream;
-import java.time.Duration;
-import java.util.Map;
-import java.util.Objects;
-
-import io.fabric8.kubernetes.api.model.ConfigMap;
-import io.fabric8.kubernetes.client.KubernetesClient;
-import io.fabric8.kubernetes.client.utils.Serialization;
-import org.testcontainers.containers.Container;
-import org.testcontainers.k3s.K3sContainer;
-import reactor.netty.http.client.HttpClient;
-import reactor.util.retry.Retry;
-import reactor.util.retry.RetryBackoffSpec;
-
-import org.springframework.cloud.kubernetes.integration.tests.commons.fabric8_client.Util;
-import org.springframework.http.client.reactive.ReactorClientHttpConnector;
-import org.springframework.web.reactive.function.client.WebClient;
-
-/**
- * @author wind57
- */
-final class TestUtil {
-
- private static final Map POD_LABELS = Map.of("app",
- "spring-cloud-kubernetes-fabric8-client-reload");
-
- private static final String BODY_ONE = """
- {
- "spec": {
- "template": {
- "spec": {
- "containers": [{
- "name": "spring-cloud-kubernetes-fabric8-client-configmap-event-reload",
- "image": "image_name_here",
- "env": [
- {
- "name": "LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_CLOUD_KUBERNETES_FABRIC8_DISCOVERY",
- "value": "DEBUG"
- },
- {
- "name": "SPRING_PROFILES_ACTIVE",
- "value": "two"
- },
- {
- "name": "SPRING_CLOUD_BOOTSTRAP_ENABLED",
- "value": "TRUE"
- }
- ]
- }]
- }
- }
- }
- }
- """;
-
- private static final String BODY_TWO = """
- {
- "spec": {
- "template": {
- "spec": {
- "containers": [{
- "name": "spring-cloud-kubernetes-fabric8-client-configmap-event-reload",
- "image": "image_name_here",
- "env": [
- {
- "name": "LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_CLOUD_KUBERNETES_FABRIC8_DISCOVERY",
- "value": "DEBUG"
- },
- {
- "name": "SPRING_PROFILES_ACTIVE",
- "value": "three"
- },
- {
- "name": "SPRING_CLOUD_BOOTSTRAP_ENABLED",
- "value": "TRUE"
- }
- ]
- }]
- }
- }
- }
- }
- """;
-
- private static final String BODY_THREE = """
- {
- "spec": {
- "template": {
- "spec": {
- "containers": [{
- "name": "spring-cloud-kubernetes-fabric8-client-configmap-event-reload",
- "image": "image_name_here",
- "env": [
- {
- "name": "LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_CLOUD_KUBERNETES_FABRIC8_DISCOVERY",
- "value": "DEBUG"
- },
- {
- "name": "SPRING_PROFILES_ACTIVE",
- "value": "two"
- },
- {
- "name": "SPRING_CLOUD_KUBERNETES_SECRETS_ENABLED",
- "value": "FALSE"
- },
- {
- "name": "SPRING_CLOUD_BOOTSTRAP_ENABLED",
- "value": "TRUE"
- }
- ]
- }]
- }
- }
- }
- }
- """;
-
- private static final String BODY_FOUR = """
- {
- "spec": {
- "template": {
- "spec": {
- "containers": [{
- "name": "spring-cloud-kubernetes-fabric8-client-configmap-event-reload",
- "image": "image_name_here",
- "env": [
- {
- "name": "LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_CLOUD_KUBERNETES_FABRIC8_CONFIG_RELOAD",
- "value": "DEBUG"
- },
- {
- "name": "SPRING_PROFILES_ACTIVE",
- "value": "one"
- },
- {
- "name": "SPRING_CLOUD_KUBERNETES_SECRETS_ENABLED",
- "value": "FALSE"
- },
- {
- "name": "LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_CLOUD_KUBERNETES_CLIENT_CONFIG_RELOAD",
- "value": "DEBUG"
- },
- {
- "name": "SPRING_CLOUD_BOOTSTRAP_ENABLED",
- "value": "TRUE"
- }
- ]
- }]
- }
- }
- }
- }
- """;
-
- private static final String BODY_FIVE = """
- {
- "spec": {
- "template": {
- "spec": {
- "volumes": [
- {
- "configMap": {
- "defaultMode": 420,
- "name": "poll-reload"
- },
- "name": "config-map-volume"
- }
- ],
- "containers": [{
- "volumeMounts": [
- {
- "mountPath": "/tmp",
- "name": "config-map-volume"
- }
- ],
- "name": "spring-cloud-kubernetes-fabric8-client-configmap-event-reload",
- "image": "image_name_here",
- "env": [
- {
- "name": "SPRING_PROFILES_ACTIVE",
- "value": "mount"
- },
- {
- "name": "SPRING_CLOUD_BOOTSTRAP_ENABLED",
- "value": "FALSE"
- },
- {
- "name": "LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_CLOUD_KUBERNETES_COMMONS_CONFIG_RELOAD",
- "value": "DEBUG"
- },
- {
- "name": "LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_CLOUD_KUBERNETES_COMMONS_CONFIG",
- "value": "DEBUG"
- },
- {
- "name": "LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_CLOUD_KUBERNETES_COMMONS",
- "value": "DEBUG"
- }
- ]
- }]
- }
- }
- }
- }
- """;
-
- private static final String BODY_SIX = """
- {
- "spec": {
- "template": {
- "spec": {
- "volumes": [
- {
- "configMap": {
- "defaultMode": 420,
- "name": "poll-reload"
- },
- "name": "config-map-volume"
- }
- ],
- "containers": [{
- "volumeMounts": [
- {
- "mountPath": "/tmp",
- "name": "config-map-volume"
- }
- ],
- "name": "spring-cloud-kubernetes-fabric8-client-configmap-event-reload",
- "image": "image_name_here",
- "env": [
- {
- "name": "SPRING_PROFILES_ACTIVE",
- "value": "with-bootstrap"
- },
- {
- "name": "SPRING_CLOUD_BOOTSTRAP_ENABLED",
- "value": "TRUE"
- },
- {
- "name": "LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_CLOUD_KUBERNETES_COMMONS_CONFIG_RELOAD",
- "value": "DEBUG"
- },
- {
- "name": "LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_CLOUD_KUBERNETES_COMMONS_CONFIG",
- "value": "DEBUG"
- },
- {
- "name": "LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_CLOUD_KUBERNETES_COMMONS",
- "value": "DEBUG"
- }
- ]
- }]
- }
- }
- }
- }
- """;
-
- private static final String BODY_SEVEN = """
- {
- "spec": {
- "template": {
- "spec": {
- "containers": [{
- "name": "spring-cloud-kubernetes-fabric8-client-configmap-event-reload",
- "image": "image_name_here",
- "env": [
- {
- "name": "SPRING_PROFILES_ACTIVE",
- "value": "with-secret"
- }
- ]
- }]
- }
- }
- }
- }
- """;
-
- private TestUtil() {
-
- }
-
- static void reCreateSources(Util util, KubernetesClient client) {
- InputStream leftConfigMapStream = util.inputStream("left-configmap.yaml");
- InputStream rightConfigMapStream = util.inputStream("right-configmap.yaml");
- InputStream configMapStream = util.inputStream("configmap.yaml");
-
- ConfigMap leftConfigMap = Serialization.unmarshal(leftConfigMapStream, ConfigMap.class);
- ConfigMap rightConfigMap = Serialization.unmarshal(rightConfigMapStream, ConfigMap.class);
- ConfigMap configMap = Serialization.unmarshal(configMapStream, ConfigMap.class);
-
- replaceConfigMap(client, leftConfigMap, "left");
- replaceConfigMap(client, rightConfigMap, "right");
- replaceConfigMap(client, configMap, "default");
- }
-
- static void replaceConfigMap(KubernetesClient client, ConfigMap configMap, String namespace) {
- client.configMaps().inNamespace(namespace).resource(configMap).createOrReplace();
- }
-
- static void patchOne(Util util, String dockerImage, String deploymentName, String namespace) {
- util.patchWithReplace(dockerImage, deploymentName, namespace, BODY_ONE, POD_LABELS);
- }
-
- static void patchTwo(Util util, String dockerImage, String deploymentName, String namespace) {
- util.patchWithReplace(dockerImage, deploymentName, namespace, BODY_TWO, POD_LABELS);
- }
-
- static void patchThree(Util util, String dockerImage, String deploymentName, String namespace) {
- util.patchWithReplace(dockerImage, deploymentName, namespace, BODY_THREE, POD_LABELS);
- }
-
- static void patchFour(Util util, String dockerImage, String deploymentName, String namespace) {
- util.patchWithReplace(dockerImage, deploymentName, namespace, BODY_FOUR, POD_LABELS);
- }
-
- static void patchFive(Util util, String dockerImage, String deploymentName, String namespace) {
- util.patchWithReplace(dockerImage, deploymentName, namespace, BODY_FIVE, POD_LABELS);
- }
-
- static void patchSix(Util util, String dockerImage, String deploymentName, String namespace) {
- util.patchWithReplace(dockerImage, deploymentName, namespace, BODY_SIX, POD_LABELS);
- }
-
- static void patchSeven(Util util, String dockerImage, String deploymentName, String namespace) {
- util.patchWithReplace(dockerImage, deploymentName, namespace, BODY_SEVEN, POD_LABELS);
- }
-
- static WebClient.Builder builder() {
- return WebClient.builder().clientConnector(new ReactorClientHttpConnector(HttpClient.create()));
- }
-
- static RetryBackoffSpec retrySpec() {
- return Retry.fixedDelay(120, Duration.ofSeconds(2)).filter(Objects::nonNull);
- }
-
- static String logs(K3sContainer container, String appLabelValue) {
- try {
- String appPodName = container
- .execInContainer("sh", "-c",
- "kubectl get pods -l app=" + appLabelValue + " -o=name --no-headers | tr -d '\n'")
- .getStdout();
-
- Container.ExecResult execResult = container.execInContainer("sh", "-c",
- "kubectl logs " + appPodName.trim());
- return execResult.getStdout();
- }
- catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
-}
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/META-INF/spring.factories b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/META-INF/spring.factories
new file mode 100644
index 0000000000..cc4154d5ba
--- /dev/null
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/META-INF/spring.factories
@@ -0,0 +1,2 @@
+org.springframework.cloud.bootstrap.BootstrapConfiguration=\
+org.springframework.cloud.kubernetes.fabric8.client.reload.Fabric8EventReloadBase.TestConfig
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/logback-test.xml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/logback-test.xml
index ee24334373..0f9de3d918 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/logback-test.xml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/logback-test.xml
@@ -12,4 +12,6 @@
+
+
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/configmap.yaml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/manifests/configmap.yaml
similarity index 100%
rename from spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/configmap.yaml
rename to spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/manifests/configmap.yaml
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/deployment.yaml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/manifests/deployment.yaml
similarity index 74%
rename from spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/deployment.yaml
rename to spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/manifests/deployment.yaml
index aba13d5127..a430c69bf2 100644
--- a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/deployment.yaml
+++ b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/manifests/deployment.yaml
@@ -30,6 +30,18 @@ spec:
- name: LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_CLOUD_KUBERNETES_FABRIC8_CONFIG_RELOAD
value: "DEBUG"
- name: SPRING_PROFILES_ACTIVE
- value: "one"
+ value: "with-bootstrap"
- name: SPRING_CLOUD_BOOTSTRAP_ENABLED
value: "TRUE"
+ - name: LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_CLOUD_KUBERNETES_COMMONS_CONFIG
+ value: "DEBUG"
+
+ volumeMounts:
+ - mountPath: /tmp
+ name: "config-map-volume"
+
+ volumes:
+ - name: "config-map-volume"
+ configMap:
+ defaultMode: 420
+ name: "poll-reload"
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/ingress.yaml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/manifests/ingress.yaml
similarity index 100%
rename from spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/ingress.yaml
rename to spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/manifests/ingress.yaml
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/left-configmap.yaml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/manifests/left-configmap.yaml
similarity index 100%
rename from spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/left-configmap.yaml
rename to spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/manifests/left-configmap.yaml
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/right-configmap-with-label.yaml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/manifests/right-configmap-with-label.yaml
similarity index 100%
rename from spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/right-configmap-with-label.yaml
rename to spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/manifests/right-configmap-with-label.yaml
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/right-configmap.yaml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/manifests/right-configmap.yaml
similarity index 100%
rename from spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/right-configmap.yaml
rename to spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/manifests/right-configmap.yaml
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/secret.yaml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/manifests/secret.yaml
similarity index 100%
rename from spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/secret.yaml
rename to spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/manifests/secret.yaml
diff --git a/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/service.yaml b/spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/manifests/service.yaml
similarity index 100%
rename from spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/service.yaml
rename to spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-reload/src/test/resources/manifests/service.yaml
diff --git a/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/Images.java b/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/Images.java
index 47021c563f..4a39540a1b 100644
--- a/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/Images.java
+++ b/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/integration/tests/commons/Images.java
@@ -79,11 +79,15 @@ public static String wiremockVersion() {
}
public static void loadBusybox(K3sContainer container) {
- Commons.load(container, BUSYBOX_TAR, BUSYBOX, busyboxVersion());
+ if (!imageAlreadyInK3s(container, BUSYBOX_TAR)) {
+ Commons.load(container, BUSYBOX_TAR, BUSYBOX, busyboxVersion());
+ }
}
public static void loadWiremock(K3sContainer container) {
- Commons.load(container, WIREMOCK_TAR, WIREMOCK, wiremockVersion());
+ if (!imageAlreadyInK3s(container, WIREMOCK_TAR)) {
+ Commons.load(container, WIREMOCK_TAR, WIREMOCK, wiremockVersion());
+ }
}
public static void loadIstioCtl(K3sContainer container) {
@@ -106,6 +110,25 @@ public static void loadRabbitmq(K3sContainer container) {
Commons.load(container, RABBITMQ_TAR, RABBITMQ, rabbitMqVersion());
}
+ private static boolean imageAlreadyInK3s(K3sContainer container, String tarName) {
+ try {
+ boolean present = container.execInContainer("sh", "-c", "ctr images list | grep " + tarName)
+ .getStdout()
+ .contains(tarName);
+ if (present) {
+ System.out.println("image : " + tarName + " already in k3s, skipping");
+ return true;
+ }
+ else {
+ System.out.println("image : " + tarName + " not in k3s");
+ return false;
+ }
+ }
+ catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
// find the image version from current-images.txt
private static String imageVersion(String imageNameForDownload) {
BufferedReader reader = new BufferedReader(
diff --git a/spring-cloud-kubernetes-test-support/src/main/resources/current-images.txt b/spring-cloud-kubernetes-test-support/src/main/resources/current-images.txt
index 34d4371080..2853673403 100644
--- a/spring-cloud-kubernetes-test-support/src/main/resources/current-images.txt
+++ b/spring-cloud-kubernetes-test-support/src/main/resources/current-images.txt
@@ -1,7 +1,7 @@
busybox:1.36.1
-istio/istioctl:1.20.5
-istio/proxyv2:1.20.5
-istio/pilot:1.20.5
+istio/istioctl:1.21.6
+istio/proxyv2:1.21.6
+istio/pilot:1.21.6
confluentinc/cp-kafka:7.2.1
rabbitmq:3-management
wiremock/wiremock:3.4.2