Skip to content

Commit

Permalink
Merge branch '3.1.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanjbaxter committed Jan 7, 2025
2 parents 02c97d5 + 7831b62 commit b956a1e
Show file tree
Hide file tree
Showing 36 changed files with 924 additions and 1,109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
*/
class Fabric8DiscoveryAllServicesIT extends Fabric8DiscoveryBase {


private static Service externalServiceName;

@BeforeAll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"spring.cloud.kubernetes.discovery.namespaces[1]=b-uat",
"spring.cloud.kubernetes.discovery.filter=#root.metadata.namespace matches 'a-uat$'",
"logging.level.org.springframework.cloud.kubernetes.fabric8.discovery=DEBUG"

})
class Fabric8DiscoveryFilterMatchOneNamespaceIT extends Fabric8DiscoveryBase {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"spring.cloud.kubernetes.discovery.namespaces[1]=b-uat",
"spring.cloud.kubernetes.discovery.filter=#root.metadata.namespace matches '^.*uat$'",
"logging.level.org.springframework.cloud.kubernetes.fabric8.discovery=DEBUG"

})
class Fabric8DiscoveryFilterMatchTwoNamespacesIT extends Fabric8DiscoveryBase {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ spring:
- /tmp/application.properties
config:
import: "kubernetes:"

Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
logging:
level:
root: DEBUG

spring:
application:
name: poll-reload
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
logging:
level:
root: DEBUG

spring:
application:
name: event-reload
cloud:
kubernetes:
reload:
enabled: true
strategy: shutdown
strategy: refresh
mode: event
namespaces:
- right
monitoring-config-maps: true

main:
cloud-platform: kubernetes
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
logging:
level:
root: DEBUG

spring:
application:
name: event-reload
Expand All @@ -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


Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
* <pre>
Expand All @@ -50,27 +87,27 @@ final class BootstrapEnabledPollingReloadConfigMapMountDelegate {
* - our polling will then detect that change, and trigger a reload.
* </pre>
*/
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();
Expand All @@ -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"));

}

}
Loading

0 comments on commit b956a1e

Please sign in to comment.