Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor last fabric8 integration test package (1) #1824

Open
wants to merge 43 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
40252b6
started work
wind57 Oct 4, 2024
86d2e8a
dirty
wind57 Oct 5, 2024
0589167
dirty
wind57 Oct 5, 2024
840fc59
fix
wind57 Oct 5, 2024
71d0a5e
Merge branch 'change-delete-sequence' into refactor-integration-tests-1
wind57 Oct 5, 2024
fe07a73
dirty
wind57 Oct 5, 2024
6b3200f
first working
wind57 Oct 5, 2024
e4a88a9
cleanup
wind57 Oct 5, 2024
f88a581
cleanup
wind57 Oct 5, 2024
ed6565c
cleanup
wind57 Oct 5, 2024
096cf99
dirty
wind57 Oct 6, 2024
8824f14
more improvements
wind57 Oct 6, 2024
543c8a5
Merge branch 'refactor-integration-tests-1' into refactor-integration…
wind57 Oct 6, 2024
7dda032
more improvements
wind57 Oct 6, 2024
53db36f
Merge branch 'refactor-integration-tests-1' into refactor-integration…
wind57 Oct 6, 2024
d0d3b03
dirty
wind57 Oct 6, 2024
947cc43
cleanup
wind57 Oct 6, 2024
e38293f
Merge branch 'refactor-integration-tests-1' into refactor-integration…
wind57 Oct 6, 2024
b87b82b
dirty
wind57 Oct 6, 2024
566dfd6
dirty
wind57 Oct 6, 2024
fe9b3f5
dirty
wind57 Oct 6, 2024
b138b42
static import
wind57 Oct 6, 2024
ab24227
Merge branch 'refactor-integration-tests-1' into refactor-integration…
wind57 Oct 6, 2024
6d7e298
dirty
wind57 Oct 6, 2024
7b134e6
Merge branch '3.1.x' into refactor-integration-tests-1
wind57 Oct 6, 2024
260af17
Merge branch 'refactor-integration-tests-1' into refactor-integration…
wind57 Oct 6, 2024
c5d83f6
dirty
wind57 Oct 6, 2024
f1fa96e
dirty
wind57 Oct 6, 2024
b0dcb45
first ready
wind57 Oct 7, 2024
fed5559
started basic work
wind57 Oct 9, 2024
6668e41
dirty
wind57 Oct 11, 2024
3a0f108
dirty
wind57 Oct 12, 2024
62f4ccd
dirty
wind57 Dec 4, 2024
d8579ac
dirty
wind57 Dec 12, 2024
c201be4
dirty
wind57 Dec 20, 2024
f791927
dirty
wind57 Dec 20, 2024
f1e0774
dirty
wind57 Dec 20, 2024
b1c3c38
fix
wind57 Dec 20, 2024
fcb3952
merge 3.1.x
wind57 Dec 20, 2024
9b4dc97
fix
wind57 Dec 20, 2024
ef10f74
fix
wind57 Dec 20, 2024
9dff134
fix
wind57 Dec 20, 2024
a5564fb
fix
wind57 Dec 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading