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

Simply k8s client configmap event reload it (7) #1425

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
e971ae5
started work
wind57 Aug 16, 2023
0308a1a
continue work
wind57 Aug 18, 2023
eff1441
checkstyle
wind57 Aug 18, 2023
f00b815
fix tests
wind57 Aug 18, 2023
32ec64f
add integration test
wind57 Aug 18, 2023
6ea5a5b
started work on refactor intergariton tests
wind57 Aug 19, 2023
4cfd2d0
more changes
wind57 Aug 19, 2023
861beec
fix review comments
wind57 Aug 19, 2023
2a3f80a
merge latest
wind57 Aug 19, 2023
a7a5d76
more changes
wind57 Aug 19, 2023
1bb509c
more changes
wind57 Aug 20, 2023
565573c
Merge branch '3.0.x' into use-patch-like-tests-in-fabric8-discovery-it
wind57 Aug 20, 2023
c5a2965
refactor tests
wind57 Aug 20, 2023
4341115
a few logs added for the failing test
wind57 Aug 20, 2023
382ba24
placeholder commit
wind57 Aug 20, 2023
8d9969a
fix failing test
wind57 Aug 20, 2023
9e2e9ce
started work
wind57 Aug 20, 2023
1332b9f
Merge branch '3.0.x' into use-patch-like-tests-in-fabric8-discovery-it
wind57 Aug 21, 2023
ced7ce0
make tests static
wind57 Aug 21, 2023
10f4e36
checkstyle
wind57 Aug 21, 2023
f73e772
with wait for log statements
wind57 Aug 21, 2023
1380dd9
Merge branch '3.0.x' into simply-k8s-client-catalog-watcher-it
wind57 Aug 21, 2023
eca9edf
Merge branch 'use-patch-like-tests-in-fabric8-discovery-it' into simp…
wind57 Aug 21, 2023
38d09f7
dirty
wind57 Aug 21, 2023
e767b0e
dirty
wind57 Aug 21, 2023
8db1673
moer changes
wind57 Aug 21, 2023
8df3cac
merge 3.0.x
wind57 Aug 21, 2023
c18aa76
remove un-used method
wind57 Aug 21, 2023
89c79f7
fix
wind57 Aug 27, 2023
9187d8a
Merge branch '3.0.x' into simply-k8s-client-catalog-watcher-it
wind57 Aug 27, 2023
20de20a
placeholder commit
wind57 Aug 27, 2023
97980ee
dirty
wind57 Aug 27, 2023
b2b329d
fix integration test
wind57 Aug 27, 2023
333e104
fix integration test
wind57 Aug 27, 2023
acc04f7
dirty
wind57 Aug 27, 2023
c900bd5
dirty
wind57 Aug 28, 2023
2ca5591
refactor test
wind57 Aug 29, 2023
d7b6baf
placeholder commit
wind57 Aug 29, 2023
8c0bb3f
Merge branch '3.0.x' into replace-serialization-calls
wind57 Aug 31, 2023
c81ab7c
Merge branch '3.0.x' into simply-k8s-client-catalog-watcher-it
wind57 Aug 31, 2023
a84f444
Merge branch 'replace-serialization-calls' into simply-k8s-client-cat…
wind57 Aug 31, 2023
75b4dce
dirty
wind57 Sep 1, 2023
5211358
fix test
wind57 Sep 1, 2023
39e748b
checkstyle
wind57 Sep 1, 2023
c9335d4
fix test
wind57 Sep 1, 2023
869b855
checkstyle
wind57 Sep 1, 2023
bbfd00c
Merge branch '3.0.x' into simply-k8s-client-catalog-watcher-it
wind57 Sep 1, 2023
3a6f7de
placeholder commit
wind57 Sep 1, 2023
7271d57
Merge branch '3.0.x' into simply-k8s-client-config-it
wind57 Sep 1, 2023
b45fdf8
Merge branch 'simply-k8s-client-catalog-watcher-it' into simply-k8s-c…
wind57 Sep 2, 2023
24adf7c
Merge branch 'simply-k8s-client-config-it' into simply-k8s-client-con…
wind57 Sep 3, 2023
2a52150
fix compilation
wind57 Sep 3, 2023
dabf286
fix IT
wind57 Sep 3, 2023
20fd204
fix IT
wind57 Sep 4, 2023
4e2ccca
merge 3.0.x
wind57 Sep 11, 2023
0853184
formatting
wind57 Sep 11, 2023
0877c2a
remove ahrdcoded version
wind57 Sep 11, 2023
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 @@ -16,13 +16,18 @@

package org.springframework.cloud.kubernetes.client.catalog;

import java.util.Map;

import static org.springframework.cloud.kubernetes.integration.tests.commons.native_client.Util.patchWithReplace;

/**
* @author wind57
*/
final class KubernetesClientCatalogWatchUtils {

private static final Map<String, String> POD_LABELS = Map.of("app",
"spring-cloud-kubernetes-client-catalog-watcher");

private KubernetesClientCatalogWatchUtils() {

}
Expand Down Expand Up @@ -119,15 +124,15 @@ private KubernetesClientCatalogWatchUtils() {
""";

static void patchForEndpointSlices(String deploymentName, String namespace, String imageName) {
patchWithReplace(imageName, deploymentName, namespace, BODY_ONE);
patchWithReplace(imageName, deploymentName, namespace, BODY_ONE, POD_LABELS);
}

static void patchForEndpointsNamespaces(String deploymentName, String namespace, String imageName) {
patchWithReplace(imageName, deploymentName, namespace, BODY_TWO);
patchWithReplace(imageName, deploymentName, namespace, BODY_TWO, POD_LABELS);
}

static void patchForEndpointSlicesNamespaces(String deploymentName, String namespace, String imageName) {
patchWithReplace(imageName, deploymentName, namespace, BODY_THREE);
patchWithReplace(imageName, deploymentName, namespace, BODY_THREE, POD_LABELS);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
*/
class ConfigMapAndSecretIT {

private static final Map<String, String> POD_LABELS = Map.of("app", "spring-cloud-kubernetes-client-config-it");

private static final String BODY = """
{
"spec": {
Expand Down Expand Up @@ -134,9 +136,8 @@ void testConfigMapAndSecretRefresh() throws Exception {
WebClient propertyClient = builder.baseUrl(PROPERTY_URL).build();

await().timeout(Duration.ofSeconds(120)).pollInterval(Duration.ofSeconds(2))
.ignoreException(WebClientResponseException.BadGateway.class)
.until(() -> propertyClient
.method(HttpMethod.GET).retrieve().bodyToMono(String.class).block().equals("from-config-map"));
.ignoreException(WebClientResponseException.BadGateway.class).until(() -> propertyClient
.method(HttpMethod.GET).retrieve().bodyToMono(String.class).block().equals("from-config-map"));

WebClient secretClient = builder.baseUrl(SECRET_URL).build();
String secret = secretClient.method(HttpMethod.GET).retrieve().bodyToMono(String.class).retryWhen(retrySpec())
Expand Down Expand Up @@ -206,7 +207,7 @@ private RetryBackoffSpec retrySpec() {

private static void patchForPollingReload() {
patchWithReplace(ConfigMapAndSecretIT.DOCKER_IMAGE, ConfigMapAndSecretIT.APP_NAME + "-deployment",
ConfigMapAndSecretIT.NAMESPACE, BODY);
ConfigMapAndSecretIT.NAMESPACE, BODY, POD_LABELS);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@
package org.springframework.cloud.kubernetes.client.configmap.event.reload;

import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;
Expand All @@ -31,7 +28,6 @@
import io.kubernetes.client.openapi.models.V1ConfigMap;
import io.kubernetes.client.openapi.models.V1ConfigMapBuilder;
import io.kubernetes.client.openapi.models.V1Deployment;
import io.kubernetes.client.openapi.models.V1EnvVar;
import io.kubernetes.client.openapi.models.V1Ingress;
import io.kubernetes.client.openapi.models.V1ObjectMeta;
import io.kubernetes.client.openapi.models.V1Service;
Expand All @@ -52,6 +48,10 @@
import org.springframework.web.reactive.function.client.WebClient;

import static org.awaitility.Awaitility.await;
import static org.springframework.cloud.kubernetes.client.configmap.event.reload.ConfigMapEventReloadITUtil.patchOne;
import static org.springframework.cloud.kubernetes.client.configmap.event.reload.ConfigMapEventReloadITUtil.patchThree;
import static org.springframework.cloud.kubernetes.client.configmap.event.reload.ConfigMapEventReloadITUtil.patchTwo;
import static org.springframework.cloud.kubernetes.client.configmap.event.reload.DataChangesInConfigMapReloadDelegate.testSimple;

/**
* @author wind57
Expand All @@ -60,6 +60,8 @@ class ConfigMapEventReloadIT {

private static final String IMAGE_NAME = "spring-cloud-kubernetes-client-configmap-event-reload";

private static final String DOCKER_IMAGE = "docker.io/springcloud/" + IMAGE_NAME + ":" + Commons.pomVersion();

private static final String NAMESPACE = "default";

private static final K3sContainer K3S = Commons.container();
Expand All @@ -83,6 +85,7 @@ static void beforeAll() throws Exception {
@AfterAll
static void afterAll() throws Exception {
util.deleteClusterWide(NAMESPACE, Set.of("left", "right"));
manifests(Phase.DELETE);
util.deleteNamespace("left");
util.deleteNamespace("right");
Commons.cleanUp(IMAGE_NAME, K3S);
Expand All @@ -99,7 +102,7 @@ static void afterAll() throws Exception {
*/
@Test
void testInformFromOneNamespaceEventNotTriggered() throws Exception {
manifests("one", Phase.CREATE, false);
manifests(Phase.CREATE);
Commons.assertReloadLogStatements("added configmap informer for namespace",
"added secret informer for namespace", IMAGE_NAME);

Expand Down Expand Up @@ -130,7 +133,11 @@ void testInformFromOneNamespaceEventNotTriggered() throws Exception {
// left configmap has not changed, no restart of app has happened
Assertions.assertEquals("left-initial", result);

manifests("one", Phase.DELETE, false);
testInformFromOneNamespaceEventTriggered();
testInform();
testInformFromOneNamespaceEventTriggeredSecretsDisabled();
testSimple(DOCKER_IMAGE);

}

/**
Expand All @@ -141,9 +148,9 @@ void testInformFromOneNamespaceEventNotTriggered() throws Exception {
* - as such, event is triggered and we see the updated value
* </pre>
*/
@Test
void testInformFromOneNamespaceEventTriggered() throws Exception {
manifests("two", Phase.CREATE, false);
recreateConfigMaps();
patchOne("spring-cloud-kubernetes-client-configmap-deployment-event-reload", NAMESPACE, DOCKER_IMAGE);
Commons.assertReloadLogStatements("added configmap informer for namespace",
"added secret informer for namespace", IMAGE_NAME);

Expand All @@ -170,8 +177,6 @@ void testInformFromOneNamespaceEventTriggered() throws Exception {
return innerResult != null;
});
Assertions.assertEquals("right-after-change", resultAfterChange[0]);

manifests("two", Phase.DELETE, false);
}

/**
Expand All @@ -183,9 +188,12 @@ void testInformFromOneNamespaceEventTriggered() throws Exception {
* right-configmap-with-label triggers changes.
* </pre>
*/
@Test
void testInform() throws Exception {
manifests("three", Phase.CREATE, false);
recreateConfigMaps();
V1ConfigMap rightWithLabelConfigMap = (V1ConfigMap) util.yaml("right-configmap-with-label.yaml");
util.createAndWait("right", rightWithLabelConfigMap, null);
patchTwo("spring-cloud-kubernetes-client-configmap-deployment-event-reload", NAMESPACE, DOCKER_IMAGE);

Commons.assertReloadLogStatements("added configmap informer for namespace",
"added secret informer for namespace", IMAGE_NAME);

Expand Down Expand Up @@ -240,8 +248,7 @@ void testInform() throws Exception {
rightResult = rightWebClient.method(HttpMethod.GET).retrieve().bodyToMono(String.class).retryWhen(retrySpec())
.block();
Assertions.assertEquals("right-after-change", rightResult);

manifests("three", Phase.DELETE, false);
util.deleteAndWait("right", rightWithLabelConfigMap, null);
}

/**
Expand All @@ -252,9 +259,9 @@ void testInform() throws Exception {
* - as such, event is triggered and we see the updated value
* </pre>
*/
@Test
void testInformFromOneNamespaceEventTriggeredSecretsDisabled() throws Exception {
manifests("two", Phase.CREATE, true);
recreateConfigMaps();
patchThree("spring-cloud-kubernetes-client-configmap-deployment-event-reload", NAMESPACE, DOCKER_IMAGE);
Commons.assertReloadLogStatements("added configmap informer for namespace",
"added secret informer for namespace", IMAGE_NAME);

Expand All @@ -281,49 +288,39 @@ void testInformFromOneNamespaceEventTriggeredSecretsDisabled() throws Exception
return innerResult != null;
});
Assertions.assertEquals("right-after-change", resultAfterChange[0]);
}

private void recreateConfigMaps() {
V1ConfigMap leftConfigMap = (V1ConfigMap) util.yaml("left-configmap.yaml");
V1ConfigMap rightConfigMap = (V1ConfigMap) util.yaml("right-configmap.yaml");

manifests("two", Phase.DELETE, true);
util.deleteAndWait("left", leftConfigMap, null);
util.deleteAndWait("right", rightConfigMap, null);

util.createAndWait("left", leftConfigMap, null);
util.createAndWait("right", rightConfigMap, null);
}

private static void manifests(String deploymentRoot, Phase phase, boolean secretsDisabled) {
private static void manifests(Phase phase) {

try {

V1ConfigMap leftConfigMap = (V1ConfigMap) util.yaml("left-configmap.yaml");
V1ConfigMap rightConfigMap = (V1ConfigMap) util.yaml("right-configmap.yaml");
V1ConfigMap rightWithLabelConfigMap = (V1ConfigMap) util.yaml("right-configmap-with-label.yaml");

V1Deployment deployment = (V1Deployment) util.yaml(deploymentRoot + "/deployment.yaml");
V1Deployment deployment = (V1Deployment) util.yaml("deployment.yaml");
V1Service service = (V1Service) util.yaml("service.yaml");
V1Ingress ingress = (V1Ingress) util.yaml("ingress.yaml");

List<V1EnvVar> envVars = new ArrayList<>(
Optional.ofNullable(deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getEnv())
.orElse(List.of()));

if (secretsDisabled) {
V1EnvVar secretsDisabledEnvVar = new V1EnvVar().name("SPRING_CLOUD_KUBERNETES_SECRETS_ENABLED")
.value("FALSE");
envVars.add(secretsDisabledEnvVar);
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).setEnv(envVars);
}

if (phase.equals(Phase.CREATE)) {
util.createAndWait("left", leftConfigMap, null);
util.createAndWait("right", rightConfigMap, null);

if ("three".equals(deploymentRoot)) {
util.createAndWait("right", rightWithLabelConfigMap, null);
}
util.createAndWait(NAMESPACE, null, deployment, service, ingress, true);
}

if (phase.equals(Phase.DELETE)) {
util.deleteAndWait("left", leftConfigMap, null);
util.deleteAndWait("right", rightConfigMap, null);
if ("three".equals(deploymentRoot)) {
util.deleteAndWait("right", rightWithLabelConfigMap, null);
}
util.deleteAndWait(NAMESPACE, deployment, service, ingress);
}

Expand Down
Loading
Loading