Skip to content

Commit a33086e

Browse files
committed
Merge branch '3.2.x'
2 parents 1c266c8 + 8fd8cb2 commit a33086e

File tree

7 files changed

+155
-373
lines changed

7 files changed

+155
-373
lines changed

spring-cloud-kubernetes-dependencies/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<properties>
3535
<kubernetes-fabric8-client.version>6.13.5</kubernetes-fabric8-client.version>
3636
<kubernetes-native-client.version>19.0.2</kubernetes-native-client.version>
37-
<wiremock.version>3.4.2</wiremock.version>
37+
<wiremock.version>3.9.1</wiremock.version>
3838
</properties>
3939
<dependencyManagement>
4040
<dependencies>

spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-fabric8-client-istio/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/istio/Fabric8IstioIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
import io.fabric8.kubernetes.api.model.Service;
2323
import io.fabric8.kubernetes.api.model.apps.Deployment;
2424
import io.fabric8.kubernetes.client.utils.Serialization;
25+
import org.assertj.core.api.Assertions;
2526
import org.junit.jupiter.api.AfterAll;
26-
import org.junit.jupiter.api.Assertions;
2727
import org.junit.jupiter.api.BeforeAll;
2828
import org.junit.jupiter.api.Test;
2929
import org.testcontainers.containers.Container;
@@ -106,7 +106,7 @@ void test() {
106106
.block();
107107

108108
// istio profile is present
109-
Assertions.assertTrue(result.contains("istio"));
109+
Assertions.assertThat(result).contains("istio");
110110
}
111111

112112
private static void appManifests(Phase phase) {

spring-cloud-kubernetes-integration-tests/spring-cloud-kubernetes-k8s-client-configuration-watcher/pom.xml

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
<modelVersion>4.0.0</modelVersion>
1111

1212
<artifactId>spring-cloud-kubernetes-k8s-client-configuration-watcher</artifactId>
13-
<packaging>jar</packaging>
1413

1514
<properties>
16-
<wiremock.version>3.4.2</wiremock.version>
15+
<spring-boot.repackage.skip>true</spring-boot.repackage.skip>
16+
<spring-boot.build-image.skip>true</spring-boot.build-image.skip>
1717
</properties>
1818

1919
<dependencies>
@@ -40,7 +40,6 @@
4040
<dependency>
4141
<groupId>org.wiremock</groupId>
4242
<artifactId>wiremock-standalone</artifactId>
43-
<version>${wiremock.version}</version>
4443
<scope>test</scope>
4544
</dependency>
4645

@@ -67,29 +66,5 @@
6766
<filtering>true</filtering>
6867
</resource>
6968
</resources>
70-
<plugins>
71-
<plugin>
72-
<groupId>org.springframework.boot</groupId>
73-
<artifactId>spring-boot-maven-plugin</artifactId>
74-
<configuration>
75-
<skip>true</skip>
76-
</configuration>
77-
<executions>
78-
<execution>
79-
<id>build-image</id>
80-
<configuration>
81-
<skip>true</skip>
82-
</configuration>
83-
</execution>
84-
<execution>
85-
<id>repackage</id>
86-
<configuration>
87-
<skip>true</skip>
88-
</configuration>
89-
</execution>
90-
</executions>
91-
</plugin>
92-
</plugins>
9369
</build>
94-
9570
</project>
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2020 the original author or authors.
2+
* Copyright 2013-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,48 +16,38 @@
1616

1717
package org.springframework.cloud.kubernetes.configuration.watcher;
1818

19-
import java.net.SocketTimeoutException;
20-
import java.time.Duration;
19+
import java.util.List;
2120

22-
import com.github.tomakehurst.wiremock.client.WireMock;
23-
import io.kubernetes.client.openapi.models.V1ConfigMap;
24-
import io.kubernetes.client.openapi.models.V1ConfigMapBuilder;
2521
import io.kubernetes.client.openapi.models.V1Deployment;
22+
import io.kubernetes.client.openapi.models.V1EnvVar;
2623
import io.kubernetes.client.openapi.models.V1Service;
2724
import org.junit.jupiter.api.AfterAll;
2825
import org.junit.jupiter.api.AfterEach;
29-
import org.junit.jupiter.api.Assertions;
3026
import org.junit.jupiter.api.BeforeAll;
3127
import org.junit.jupiter.api.BeforeEach;
3228
import org.junit.jupiter.api.Test;
33-
import org.testcontainers.containers.Container;
3429
import org.testcontainers.k3s.K3sContainer;
3530

3631
import org.springframework.cloud.kubernetes.integration.tests.commons.Commons;
3732
import org.springframework.cloud.kubernetes.integration.tests.commons.Images;
3833
import org.springframework.cloud.kubernetes.integration.tests.commons.Phase;
3934
import org.springframework.cloud.kubernetes.integration.tests.commons.native_client.Util;
4035

41-
import static org.awaitility.Awaitility.await;
36+
import static org.springframework.cloud.kubernetes.configuration.watcher.TestUtil.SPRING_CLOUD_K8S_CONFIG_WATCHER_APP_NAME;
37+
import static org.springframework.cloud.kubernetes.configuration.watcher.TestUtil.configureWireMock;
38+
import static org.springframework.cloud.kubernetes.configuration.watcher.TestUtil.createConfigMap;
39+
import static org.springframework.cloud.kubernetes.configuration.watcher.TestUtil.deleteConfigMap;
40+
import static org.springframework.cloud.kubernetes.configuration.watcher.TestUtil.verifyActuatorCalled;
4241

4342
/**
4443
* @author Ryan Baxter
4544
*/
4645
class ActuatorRefreshIT {
4746

48-
private static final String SPRING_CLOUD_K8S_CONFIG_WATCHER_APP_NAME = "spring-cloud-kubernetes-configuration-watcher";
49-
50-
private static final String WIREMOCK_HOST = "localhost";
51-
5247
private static final String WIREMOCK_PATH = "/";
5348

54-
private static final int WIREMOCK_PORT = 80;
55-
5649
private static final String NAMESPACE = "default";
5750

58-
private static final String DOCKER_IMAGE = "docker.io/springcloud/" + SPRING_CLOUD_K8S_CONFIG_WATCHER_APP_NAME + ":"
59-
+ Commons.pomVersion();
60-
6151
private static final K3sContainer K3S = Commons.container();
6252

6353
private static Util util;
@@ -67,7 +57,6 @@ static void beforeAll() throws Exception {
6757
K3S.start();
6858
Commons.validateImage(SPRING_CLOUD_K8S_CONFIG_WATCHER_APP_NAME, K3S);
6959
Commons.loadSpringCloudKubernetesImage(SPRING_CLOUD_K8S_CONFIG_WATCHER_APP_NAME, K3S);
70-
7160
Images.loadWiremock(K3S);
7261

7362
util = new Util(K3S);
@@ -92,155 +81,45 @@ void after() {
9281
}
9382

9483
/*
95-
* this test loads uses two services: wiremock on port 8080 and configuration-watcher
96-
* on port 8888. we deploy configuration-watcher first and configure it via a
97-
* configmap with the same name. then, we mock the call to actuator/refresh endpoint
98-
* and deploy a new configmap: "service-wiremock", this in turn will trigger that
84+
* This test loads two services: wiremock on port 8080 and configuration-watcher on
85+
* port 8888. We deploy configuration-watcher first and configure its env variables
86+
* that we need for this test. Then, we mock the call to actuator/refresh endpoint and
87+
* deploy a new configmap: "service-wiremock". Because This in turn will trigger a
9988
* refresh that we capture and assert for.
10089
*/
101-
// curl <WIREMOCK_POD_IP>:8080/__admin/mappings
10290
@Test
10391
void testActuatorRefresh() {
104-
105-
WireMock.configureFor(WIREMOCK_HOST, WIREMOCK_PORT);
106-
await().timeout(Duration.ofSeconds(60))
107-
.ignoreException(SocketTimeoutException.class)
108-
.until(() -> WireMock
109-
.stubFor(WireMock.post(WireMock.urlEqualTo("/actuator/refresh"))
110-
.willReturn(WireMock.aResponse().withBody("{}").withStatus(200)))
111-
.getResponse()
112-
.wasConfigured());
113-
114-
createConfigMap();
115-
116-
// Wait a bit before we verify
117-
await().atMost(Duration.ofSeconds(30))
118-
.until(() -> !WireMock.findAll(WireMock.postRequestedFor(WireMock.urlEqualTo("/actuator/refresh")))
119-
.isEmpty());
120-
WireMock.verify(WireMock.postRequestedFor(WireMock.urlEqualTo("/actuator/refresh")));
121-
122-
deleteConfigMap();
123-
124-
// the other test
125-
testActuatorRefreshReloadDisabled();
126-
127-
}
128-
129-
void testActuatorShutdown() {
130-
TestUtil.patchForShutdownRefresh(SPRING_CLOUD_K8S_CONFIG_WATCHER_APP_NAME, NAMESPACE, DOCKER_IMAGE);
131-
WireMock.configureFor(WIREMOCK_HOST, WIREMOCK_PORT);
132-
await().timeout(Duration.ofSeconds(60))
133-
.ignoreException(SocketTimeoutException.class)
134-
.until(() -> WireMock
135-
.stubFor(WireMock.post(WireMock.urlEqualTo("/actuator/shutdown"))
136-
.willReturn(WireMock.aResponse().withBody("{}").withStatus(200)))
137-
.getResponse()
138-
.wasConfigured());
139-
140-
createConfigMap();
141-
142-
// Wait a bit before we verify
143-
await().atMost(Duration.ofSeconds(30))
144-
.until(() -> !WireMock.findAll(WireMock.postRequestedFor(WireMock.urlEqualTo("/actuator/shutdown")))
145-
.isEmpty());
146-
WireMock.verify(WireMock.postRequestedFor(WireMock.urlEqualTo("/actuator/shutdown")));
147-
148-
deleteConfigMap();
149-
150-
// the other test
151-
testActuatorRefreshReloadDisabled();
152-
153-
}
154-
155-
/*
156-
* same test as above, but reload is disabled.
157-
*/
158-
void testActuatorRefreshReloadDisabled() {
159-
160-
TestUtil.patchForDisabledReload(SPRING_CLOUD_K8S_CONFIG_WATCHER_APP_NAME, NAMESPACE, DOCKER_IMAGE);
161-
162-
WireMock.configureFor(WIREMOCK_HOST, WIREMOCK_PORT);
163-
await().timeout(Duration.ofSeconds(60))
164-
.until(() -> WireMock
165-
.stubFor(WireMock.post(WireMock.urlEqualTo("/actuator/refresh"))
166-
.willReturn(WireMock.aResponse().withBody("{}").withStatus(200)))
167-
.getResponse()
168-
.wasConfigured());
169-
170-
createConfigMap();
171-
172-
// Wait a bit before we verify
173-
await().atMost(Duration.ofSeconds(30))
174-
.until(() -> !WireMock.findAll(WireMock.postRequestedFor(WireMock.urlEqualTo("/actuator/refresh")))
175-
.isEmpty());
92+
configureWireMock();
93+
createConfigMap(util, NAMESPACE);
94+
verifyActuatorCalled(1);
17695

17796
Commons.waitForLogStatement("creating NOOP strategy because reload is disabled", K3S,
17897
SPRING_CLOUD_K8S_CONFIG_WATCHER_APP_NAME);
17998

180-
// nothing related to 'ConfigReloadUtil' is present in logs
181-
// this proves that once we disable reload everything still works
182-
Assertions.assertFalse(logs().contains("ConfigReloadUtil"));
183-
WireMock.verify(WireMock.postRequestedFor(WireMock.urlEqualTo("/actuator/refresh")));
184-
185-
deleteConfigMap();
186-
99+
deleteConfigMap(util, NAMESPACE);
187100
}
188101

189102
private static void configWatcher(Phase phase) {
190-
V1ConfigMap configMap = (V1ConfigMap) util
191-
.yaml("config-watcher/spring-cloud-kubernetes-configuration-watcher-configmap.yaml");
192103
V1Deployment deployment = (V1Deployment) util
193104
.yaml("config-watcher/spring-cloud-kubernetes-configuration-watcher-deployment.yaml");
194105
V1Service service = (V1Service) util
195106
.yaml("config-watcher/spring-cloud-kubernetes-configuration-watcher-service.yaml");
196107

108+
List<V1EnvVar> envVars = List.of(
109+
new V1EnvVar().name("SPRING_CLOUD_KUBERNETES_CONFIGURATION_WATCHER_REFRESHDELAY").value("0"),
110+
new V1EnvVar().name("SPRING_CLOUD_KUBERNETES_RELOAD_ENABLED").value("FALSE"),
111+
new V1EnvVar().name("LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_CLOUD_KUBERNETES_CONFIGURATION_WATCHER")
112+
.value("DEBUG"));
113+
114+
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).setEnv(envVars);
115+
197116
if (phase.equals(Phase.CREATE)) {
198-
util.createAndWait(NAMESPACE, configMap, null);
199117
util.createAndWait(NAMESPACE, null, deployment, service, null, true);
200118
}
201119
else {
202-
util.deleteAndWait(NAMESPACE, configMap, null);
203120
util.deleteAndWait(NAMESPACE, deployment, service, null);
204121
}
205122

206123
}
207124

208-
// Create new configmap to trigger controller to signal app to refresh
209-
private void createConfigMap() {
210-
V1ConfigMap configMap = new V1ConfigMapBuilder().editOrNewMetadata()
211-
.withName("service-wiremock")
212-
.addToLabels("spring.cloud.kubernetes.config", "true")
213-
.endMetadata()
214-
.addToData("foo", "bar")
215-
.build();
216-
util.createAndWait(NAMESPACE, configMap, null);
217-
}
218-
219-
private void deleteConfigMap() {
220-
V1ConfigMap configMap = new V1ConfigMapBuilder().editOrNewMetadata()
221-
.withName("service-wiremock")
222-
.addToLabels("spring.cloud.kubernetes.config", "true")
223-
.endMetadata()
224-
.addToData("foo", "bar")
225-
.build();
226-
util.deleteAndWait(NAMESPACE, configMap, null);
227-
}
228-
229-
private String logs() {
230-
try {
231-
String appPodName = K3S
232-
.execInContainer("sh", "-c",
233-
"kubectl get pods -l app=" + SPRING_CLOUD_K8S_CONFIG_WATCHER_APP_NAME
234-
+ " -o=name --no-headers | tr -d '\n'")
235-
.getStdout();
236-
237-
Container.ExecResult execResult = K3S.execInContainer("sh", "-c", "kubectl logs " + appPodName.trim());
238-
return execResult.getStdout();
239-
}
240-
catch (Exception e) {
241-
e.printStackTrace();
242-
throw new RuntimeException(e);
243-
}
244-
}
245-
246125
}

0 commit comments

Comments
 (0)