Bumping versions

This commit is contained in:
buildmaster
2024-07-24 01:52:01 +00:00
parent a7ac576779
commit f8b18ae8ff
376 changed files with 8513 additions and 4472 deletions

View File

@@ -47,9 +47,15 @@ class ActuatorDisabledHealthTest {
@Test
void healthEndpointShouldNotContainKubernetes() {
this.webClient.get().uri("http://localhost:{port}/actuator/health", this.port)
.accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody()
.jsonPath("components.kubernetes").doesNotExist();
this.webClient.get()
.uri("http://localhost:{port}/actuator/health", this.port)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("components.kubernetes")
.doesNotExist();
Assertions.assertNull(registry.getContributor("kubernetes"),
"reactive kubernetes contributor must NOT be present when 'management.health.kubernetes.enabled=false'");

View File

@@ -77,7 +77,7 @@ class ActuatorEnabledFailFastExceptionTest {
pathsMockedStatic = Mockito.mockStatic(Paths.class);
envReaderMockedStatic.when(() -> EnvReader.getEnv(KubernetesClientPodUtils.KUBERNETES_SERVICE_HOST))
.thenReturn("k8s-host");
.thenReturn("k8s-host");
envReaderMockedStatic.when(() -> EnvReader.getEnv(KubernetesClientPodUtils.HOSTNAME)).thenReturn("host");
Path serviceAccountTokenPath = Mockito.mock(Path.class);
@@ -104,7 +104,7 @@ class ActuatorEnabledFailFastExceptionTest {
mocks();
Mockito.when(coreV1Api.readNamespacedPod("host", "my-namespace", null))
.thenThrow(new RuntimeException("just because"));
.thenThrow(new RuntimeException("just because"));
return new KubernetesClientPodUtils(coreV1Api, "my-namespace", FAIL_FAST);
}

View File

@@ -44,9 +44,15 @@ class ActuatorEnabledHealthTest {
@Test
void healthEndpointShouldContainKubernetes() {
this.webClient.get().uri("http://localhost:{port}/actuator/health", this.port)
.accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody()
.jsonPath("components.kubernetes").exists();
this.webClient.get()
.uri("http://localhost:{port}/actuator/health", this.port)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("components.kubernetes")
.exists();
Assertions.assertNotNull(registry.getContributor("kubernetes"),
"reactive kubernetes contributor must be present when 'management.health.kubernetes.enabled=true'");

View File

@@ -80,7 +80,7 @@ class ActuatorEnabledNoFailFastExceptionTest {
pathsMockedStatic = Mockito.mockStatic(Paths.class);
envReaderMockedStatic.when(() -> EnvReader.getEnv(KubernetesClientPodUtils.KUBERNETES_SERVICE_HOST))
.thenReturn("k8s-host");
.thenReturn("k8s-host");
envReaderMockedStatic.when(() -> EnvReader.getEnv(KubernetesClientPodUtils.HOSTNAME)).thenReturn("host");
Path serviceAccountTokenPath = Mockito.mock(Path.class);
@@ -107,7 +107,7 @@ class ActuatorEnabledNoFailFastExceptionTest {
mocks();
Mockito.when(coreV1Api.readNamespacedPod("host", "my-namespace", null))
.thenThrow(new RuntimeException("just because"));
.thenThrow(new RuntimeException("just because"));
return new KubernetesClientPodUtils(coreV1Api, "my-namespace", FAIL_FAST);
}

View File

@@ -40,7 +40,7 @@ public class KubernetesClientHealthIndicatorNotInsideTests {
@Test
public void test() {
assertThatThrownBy(() -> context.getBean(KubernetesClientHealthIndicator.class))
.isInstanceOf(NoSuchBeanDefinitionException.class);
.isInstanceOf(NoSuchBeanDefinitionException.class);
}
}

View File

@@ -40,7 +40,7 @@ public class KubernetesClientInfoContributorNotInsideTests {
@Test
public void test() {
assertThatThrownBy(() -> context.getBean(KubernetesClientInfoContributor.class))
.isInstanceOf(NoSuchBeanDefinitionException.class);
.isInstanceOf(NoSuchBeanDefinitionException.class);
}
}

View File

@@ -84,8 +84,8 @@ class KubernetesClientPodUtilsTests {
@Test
void constructorThrowsIllegalArgumentExceptionWhenKubeClientIsNull() {
assertThatThrownBy(() -> new KubernetesClientPodUtils(null, "namespace", false))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Must provide an instance of KubernetesClient");
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Must provide an instance of KubernetesClient");
}
@Test

View File

@@ -48,7 +48,7 @@ class KubernetesClientUtilsTests {
@Test
void testNamespaceResolutionFailed() {
assertThatThrownBy(() -> KubernetesClientUtils.getApplicationNamespace("", "target", null))
.isInstanceOf(NamespaceResolutionFailedException.class);
.isInstanceOf(NamespaceResolutionFailedException.class);
}
}

View File

@@ -53,7 +53,7 @@ class ApiClientUserAgentDefaultHeader {
Request.Builder builder = new Request.Builder();
apiClient.processHeaderParams(Collections.emptyMap(), builder);
assertThat(builder.url(new URL("http://example.com")).build().headers().get("User-Agent"))
.isEqualTo("Spring-Cloud-Kubernetes-Application");
.isEqualTo("Spring-Cloud-Kubernetes-Application");
}
}

View File

@@ -57,7 +57,7 @@ class ApiClientUserAgentNonDefaultHeader {
Request.Builder builder = new Request.Builder();
apiClient.processHeaderParams(Collections.emptyMap(), builder);
assertThat(builder.url(new URL("http://example.com")).build().headers().get("User-Agent"))
.isEqualTo("non-default");
.isEqualTo("non-default");
}
}

View File

@@ -43,8 +43,9 @@ public class KubernetesClientConfigMapPropertySource extends SourceDataEntriesPr
private static SourceData getSourceData(KubernetesClientConfigContext context) {
NormalizedSourceType type = context.normalizedSource().type();
return Optional.ofNullable(STRATEGIES.get(type)).map(x -> x.apply(context))
.orElseThrow(() -> new IllegalArgumentException("no strategy found for : " + type));
return Optional.ofNullable(STRATEGIES.get(type))
.map(x -> x.apply(context))
.orElseThrow(() -> new IllegalArgumentException("no strategy found for : " + type));
}
private static KubernetesClientContextToSourceData namedConfigMap() {

View File

@@ -55,8 +55,10 @@ public final class KubernetesClientConfigMapsCache implements ConfigMapCache {
List<StrippedSourceContainer> result = CACHE.computeIfAbsent(namespace, x -> {
try {
b[0] = true;
return strippedConfigMaps(coreV1Api.listNamespacedConfigMap(namespace, null, null, null, null, null,
null, null, null, null, null, null).getItems());
return strippedConfigMaps(coreV1Api
.listNamespacedConfigMap(namespace, null, null, null, null, null, null, null, null, null, null,
null)
.getItems());
}
catch (ApiException apiException) {
throw new RuntimeException(apiException.getResponseBody(), apiException);
@@ -74,8 +76,10 @@ public final class KubernetesClientConfigMapsCache implements ConfigMapCache {
}
private static List<StrippedSourceContainer> strippedConfigMaps(List<V1ConfigMap> configMaps) {
return configMaps.stream().map(configMap -> new StrippedSourceContainer(configMap.getMetadata().getLabels(),
configMap.getMetadata().getName(), configMap.getData())).collect(Collectors.toList());
return configMaps.stream()
.map(configMap -> new StrippedSourceContainer(configMap.getMetadata().getLabels(),
configMap.getMetadata().getName(), configMap.getData()))
.collect(Collectors.toList());
}
}

View File

@@ -57,8 +57,9 @@ public class KubernetesClientSecretsCache implements SecretsCache {
List<StrippedSourceContainer> result = CACHE.computeIfAbsent(namespace, x -> {
try {
b[0] = true;
return strippedSecrets(coreV1Api.listNamespacedSecret(namespace, null, null, null, null, null, null,
null, null, null, null, null).getItems());
return strippedSecrets(coreV1Api
.listNamespacedSecret(namespace, null, null, null, null, null, null, null, null, null, null, null)
.getItems());
}
catch (ApiException apiException) {
throw new RuntimeException(apiException.getResponseBody(), apiException);
@@ -76,8 +77,10 @@ public class KubernetesClientSecretsCache implements SecretsCache {
}
private static List<StrippedSourceContainer> strippedSecrets(List<V1Secret> secrets) {
return secrets.stream().map(secret -> new StrippedSourceContainer(secret.getMetadata().getLabels(),
secret.getMetadata().getName(), transform(secret.getData()))).collect(Collectors.toList());
return secrets.stream()
.map(secret -> new StrippedSourceContainer(secret.getMetadata().getLabels(), secret.getMetadata().getName(),
transform(secret.getData())))
.collect(Collectors.toList());
}
private static Map<String, String> transform(Map<String, byte[]> in) {

View File

@@ -48,8 +48,9 @@ public class KubernetesClientSecretsPropertySource extends SecretsPropertySource
private static SourceData getSourceData(KubernetesClientConfigContext context) {
NormalizedSourceType type = context.normalizedSource().type();
return Optional.ofNullable(STRATEGIES.get(type)).map(x -> x.apply(context))
.orElseThrow(() -> new IllegalArgumentException("no strategy found for : " + type));
return Optional.ofNullable(STRATEGIES.get(type))
.map(x -> x.apply(context))
.orElseThrow(() -> new IllegalArgumentException("no strategy found for : " + type));
}
private static KubernetesClientContextToSourceData namedSecret() {

View File

@@ -124,11 +124,9 @@ public class KubernetesClientEventBasedConfigMapChangeDetector extends Configura
SharedInformerFactory factory = new SharedInformerFactory(apiClient);
factories.add(factory);
informer = factory
.sharedIndexInformerFor(
(CallGeneratorParams params) -> coreV1Api.listNamespacedConfigMapCall(namespace, null, null,
null, null, filter[0], null, params.resourceVersion, null, null,
params.timeoutSeconds, params.watch, null),
V1ConfigMap.class, V1ConfigMapList.class);
.sharedIndexInformerFor((CallGeneratorParams params) -> coreV1Api.listNamespacedConfigMapCall(namespace,
null, null, null, null, filter[0], null, params.resourceVersion, null, null,
params.timeoutSeconds, params.watch, null), V1ConfigMap.class, V1ConfigMapList.class);
LOG.debug(() -> "added configmap informer for namespace : " + namespace + " with filter : " + filter[0]);

View File

@@ -126,11 +126,10 @@ public class KubernetesClientEventBasedSecretsChangeDetector extends Configurati
}
SharedInformerFactory factory = new SharedInformerFactory(apiClient);
factories.add(factory);
informer = factory.sharedIndexInformerFor(
(CallGeneratorParams params) -> coreV1Api.listNamespacedSecretCall(namespace, null, null, null,
null, filter[0], null, params.resourceVersion, null, null, params.timeoutSeconds,
params.watch, null),
V1Secret.class, V1SecretList.class);
informer = factory
.sharedIndexInformerFor((CallGeneratorParams params) -> coreV1Api.listNamespacedSecretCall(namespace,
null, null, null, null, filter[0], null, params.resourceVersion, null, null,
params.timeoutSeconds, params.watch, null), V1Secret.class, V1SecretList.class);
LOG.debug(() -> "added secret informer for namespace : " + namespace + " with filter : " + filter[0]);

View File

@@ -52,7 +52,7 @@ class KubernetesClientConfigDataLocationResolverTests {
private static final DeferredLogFactory FACTORY = Supplier::get;
private static final ConfigDataLocationResolverContext RESOLVER_CONTEXT = Mockito
.mock(ConfigDataLocationResolverContext.class);
.mock(ConfigDataLocationResolverContext.class);
private static final KubernetesClientConfigDataLocationResolver RESOLVER = new KubernetesClientConfigDataLocationResolver(
FACTORY);
@@ -125,7 +125,7 @@ class KubernetesClientConfigDataLocationResolverTests {
Assertions.assertTrue(context.isRegistered(SecretsPropertySourceLocator.class));
ConfigMapPropertySourceLocator configMapPropertySourceLocator = context
.get(ConfigMapPropertySourceLocator.class);
.get(ConfigMapPropertySourceLocator.class);
Assertions.assertSame(KubernetesClientConfigMapPropertySourceLocator.class,
configMapPropertySourceLocator.getClass());
@@ -169,7 +169,7 @@ class KubernetesClientConfigDataLocationResolverTests {
Assertions.assertTrue(context.isRegistered(SecretsConfigProperties.class));
ConfigMapPropertySourceLocator configMapPropertySourceLocator = context
.get(ConfigMapPropertySourceLocator.class);
.get(ConfigMapPropertySourceLocator.class);
Assertions.assertSame(KubernetesClientConfigMapPropertySourceLocator.class,
configMapPropertySourceLocator.getClass());
@@ -178,8 +178,8 @@ class KubernetesClientConfigDataLocationResolverTests {
secretsPropertySourceLocator.getClass());
Assertions.assertTrue(capturedOutput.getOut()
.contains("Could not create the Kubernetes ApiClient in a cluster environment, because connection port "
+ "was not provided."));
.contains("Could not create the Kubernetes ApiClient in a cluster environment, because connection port "
+ "was not provided."));
}
/*
@@ -222,7 +222,7 @@ class KubernetesClientConfigDataLocationResolverTests {
Assertions.assertTrue(context.isRegistered(SecretsPropertySourceLocator.class));
ConfigMapPropertySourceLocator configMapPropertySourceLocator = context
.get(ConfigMapPropertySourceLocator.class);
.get(ConfigMapPropertySourceLocator.class);
Assertions.assertSame(ConfigDataRetryableConfigMapPropertySourceLocator.class,
configMapPropertySourceLocator.getClass());

View File

@@ -57,14 +57,15 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
class KubernetesClientConfigMapPropertySourceLocatorTests {
private static final V1ConfigMapList PROPERTIES_CONFIGMAP_LIST = new V1ConfigMapList()
.addItemsItem(
new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("bootstrap-640").withNamespace("default")
.withResourceVersion("1").build())
.addToData("application.properties",
"spring.cloud.kubernetes.configuration.watcher.refreshDelay=0\n"
+ "logging.level.org.springframework.cloud.kubernetes=TRACE")
.build());
.addItemsItem(new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("bootstrap-640")
.withNamespace("default")
.withResourceVersion("1")
.build())
.addToData("application.properties",
"spring.cloud.kubernetes.configuration.watcher.refreshDelay=0\n"
+ "logging.level.org.springframework.cloud.kubernetes=TRACE")
.build());
private static WireMockServer wireMockServer;
@@ -96,22 +97,23 @@ class KubernetesClientConfigMapPropertySourceLocatorTests {
void locateWithoutSources() {
CoreV1Api api = new CoreV1Api();
stubFor(get("/api/v1/namespaces/default/configmaps")
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(PROPERTIES_CONFIGMAP_LIST))));
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(PROPERTIES_CONFIGMAP_LIST))));
ConfigMapConfigProperties configMapConfigProperties = new ConfigMapConfigProperties(true, List.of(), List.of(),
Map.of(), true, "bootstrap-640", null, false, false, false, RetryProperties.DEFAULT);
MockEnvironment mockEnvironment = new MockEnvironment();
mockEnvironment.setProperty("spring.cloud.kubernetes.client.namespace", "default");
PropertySource<?> propertySource = new KubernetesClientConfigMapPropertySourceLocator(api,
configMapConfigProperties, new KubernetesNamespaceProvider(mockEnvironment)).locate(ENV);
configMapConfigProperties, new KubernetesNamespaceProvider(mockEnvironment))
.locate(ENV);
assertThat(propertySource.containsProperty("spring.cloud.kubernetes.configuration.watcher.refreshDelay"))
.isTrue();
.isTrue();
}
@Test
void locateWithSources() {
CoreV1Api api = new CoreV1Api();
stubFor(get("/api/v1/namespaces/default/configmaps")
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(PROPERTIES_CONFIGMAP_LIST))));
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(PROPERTIES_CONFIGMAP_LIST))));
ConfigMapConfigProperties.Source source = new ConfigMapConfigProperties.Source("bootstrap-640", "default",
Collections.emptyMap(), null, null, null);
@@ -119,9 +121,10 @@ class KubernetesClientConfigMapPropertySourceLocatorTests {
List.of(source), Map.of(), true, "fake-name", null, false, false, false, RetryProperties.DEFAULT);
PropertySource<?> propertySource = new KubernetesClientConfigMapPropertySourceLocator(api,
configMapConfigProperties, new KubernetesNamespaceProvider(new MockEnvironment())).locate(ENV);
configMapConfigProperties, new KubernetesNamespaceProvider(new MockEnvironment()))
.locate(ENV);
assertThat(propertySource.containsProperty("spring.cloud.kubernetes.configuration.watcher.refreshDelay"))
.isTrue();
.isTrue();
}
/**
@@ -135,14 +138,14 @@ class KubernetesClientConfigMapPropertySourceLocatorTests {
void testLocateWithoutNamespaceConstructor() {
CoreV1Api api = new CoreV1Api();
stubFor(get("/api/v1/namespaces/default/configmaps")
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(PROPERTIES_CONFIGMAP_LIST))));
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(PROPERTIES_CONFIGMAP_LIST))));
ConfigMapConfigProperties configMapConfigProperties = new ConfigMapConfigProperties(true, List.of(), List.of(),
Map.of(), true, "bootstrap-640", null, false, false, false, RetryProperties.DEFAULT);
assertThatThrownBy(() -> new KubernetesClientConfigMapPropertySourceLocator(api, configMapConfigProperties,
new KubernetesNamespaceProvider(new MockEnvironment())).locate(ENV))
.isInstanceOf(NamespaceResolutionFailedException.class);
new KubernetesNamespaceProvider(new MockEnvironment()))
.locate(ENV)).isInstanceOf(NamespaceResolutionFailedException.class);
}
/**
@@ -156,19 +159,19 @@ class KubernetesClientConfigMapPropertySourceLocatorTests {
void testLocateWithoutNamespace() {
CoreV1Api api = new CoreV1Api();
stubFor(get("/api/v1/namespaces/default/configmaps")
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(PROPERTIES_CONFIGMAP_LIST))));
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(PROPERTIES_CONFIGMAP_LIST))));
ConfigMapConfigProperties configMapConfigProperties = new ConfigMapConfigProperties(true, List.of(), List.of(),
Map.of(), true, "bootstrap-640", null, false, false, false, RetryProperties.DEFAULT);
assertThatThrownBy(() -> new KubernetesClientConfigMapPropertySourceLocator(api, configMapConfigProperties,
new KubernetesNamespaceProvider(ENV)).locate(ENV))
.isInstanceOf(NamespaceResolutionFailedException.class);
new KubernetesNamespaceProvider(ENV))
.locate(ENV)).isInstanceOf(NamespaceResolutionFailedException.class);
}
@Test
public void locateShouldThrowExceptionOnFailureWhenFailFastIsEnabled() {
CoreV1Api api = new CoreV1Api();
stubFor(get("/api/v1/namespaces/default/configmaps")
.willReturn(aResponse().withStatus(500).withBody("Internal Server Error")));
.willReturn(aResponse().withStatus(500).withBody("Internal Server Error")));
ConfigMapConfigProperties configMapConfigProperties = new ConfigMapConfigProperties(true, List.of(), List.of(),
Map.of(), true, "bootstrap-640", "default", false, false, true, RetryProperties.DEFAULT);
@@ -177,14 +180,14 @@ class KubernetesClientConfigMapPropertySourceLocatorTests {
configMapConfigProperties, new KubernetesNamespaceProvider(new MockEnvironment()));
assertThatThrownBy(() -> locator.locate(new MockEnvironment())).isInstanceOf(IllegalStateException.class)
.hasMessage("Internal Server Error");
.hasMessage("Internal Server Error");
}
@Test
public void locateShouldNotThrowExceptionOnFailureWhenFailFastIsDisabled() {
CoreV1Api api = new CoreV1Api();
stubFor(get("/api/v1/namespaces/default/configmaps")
.willReturn(aResponse().withStatus(500).withBody("Internal Server Error")));
.willReturn(aResponse().withStatus(500).withBody("Internal Server Error")));
ConfigMapConfigProperties configMapConfigProperties = new ConfigMapConfigProperties(true, List.of(), List.of(),
Map.of(), true, "bootstrap-640", "default", false, false, false, RetryProperties.DEFAULT);

View File

@@ -54,22 +54,24 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
class KubernetesClientConfigMapPropertySourceTests {
private static final V1ConfigMapList PROPERTIES_CONFIGMAP_LIST = new V1ConfigMapList()
.addItemsItem(
new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("bootstrap-640").withNamespace("default")
.withResourceVersion("1").build())
.addToData("application.properties",
"spring.cloud.kubernetes.configuration.watcher.refreshDelay=0\n"
+ "logging.level.org.springframework.cloud.kubernetes=TRACE")
.build());
.addItemsItem(new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("bootstrap-640")
.withNamespace("default")
.withResourceVersion("1")
.build())
.addToData("application.properties",
"spring.cloud.kubernetes.configuration.watcher.refreshDelay=0\n"
+ "logging.level.org.springframework.cloud.kubernetes=TRACE")
.build());
private static final V1ConfigMapList YAML_CONFIGMAP_LIST = new V1ConfigMapList()
.addItemsItem(new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("bootstrap-641").withNamespace("default")
.withResourceVersion("1").build())
.addToData("application.yaml",
"dummy:\n property:\n string2: \"a\"\n int2: 1\n bool2: true\n")
.build());
.addItemsItem(new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("bootstrap-641")
.withNamespace("default")
.withResourceVersion("1")
.build())
.addToData("application.yaml", "dummy:\n property:\n string2: \"a\"\n int2: 1\n bool2: true\n")
.build());
private static WireMockServer wireMockServer;
@@ -100,7 +102,7 @@ class KubernetesClientConfigMapPropertySourceTests {
public void propertiesFile() {
CoreV1Api api = new CoreV1Api();
stubFor(get("/api/v1/namespaces/default/configmaps")
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(PROPERTIES_CONFIGMAP_LIST))));
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(PROPERTIES_CONFIGMAP_LIST))));
NormalizedSource source = new NamedConfigMapNormalizedSource("bootstrap-640", "default", false, true);
KubernetesClientConfigContext context = new KubernetesClientConfigContext(api, source, "default",
@@ -109,9 +111,9 @@ class KubernetesClientConfigMapPropertySourceTests {
verify(getRequestedFor(urlEqualTo("/api/v1/namespaces/default/configmaps")));
assertThat(propertySource.containsProperty("spring.cloud.kubernetes.configuration.watcher.refreshDelay"))
.isTrue();
.isTrue();
assertThat(propertySource.getProperty("spring.cloud.kubernetes.configuration.watcher.refreshDelay"))
.isEqualTo("0");
.isEqualTo("0");
assertThat(propertySource.containsProperty("logging.level.org.springframework.cloud.kubernetes")).isTrue();
assertThat(propertySource.getProperty("logging.level.org.springframework.cloud.kubernetes")).isEqualTo("TRACE");
@@ -121,7 +123,7 @@ class KubernetesClientConfigMapPropertySourceTests {
public void yamlFile() {
CoreV1Api api = new CoreV1Api();
stubFor(get("/api/v1/namespaces/default/configmaps")
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(YAML_CONFIGMAP_LIST))));
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(YAML_CONFIGMAP_LIST))));
NormalizedSource source = new NamedConfigMapNormalizedSource("bootstrap-641", "default", false, true);
KubernetesClientConfigContext context = new KubernetesClientConfigContext(api, source, "default",
@@ -142,7 +144,7 @@ class KubernetesClientConfigMapPropertySourceTests {
public void propertiesFileWithPrefix() {
CoreV1Api api = new CoreV1Api();
stubFor(get("/api/v1/namespaces/default/configmaps")
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(PROPERTIES_CONFIGMAP_LIST))));
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(PROPERTIES_CONFIGMAP_LIST))));
ConfigUtils.Prefix prefix = ConfigUtils.findPrefix("prefix", false, false, null);
NormalizedSource source = new NamedConfigMapNormalizedSource("bootstrap-640", "default", false, prefix, true);
@@ -152,13 +154,13 @@ class KubernetesClientConfigMapPropertySourceTests {
verify(getRequestedFor(urlEqualTo("/api/v1/namespaces/default/configmaps")));
assertThat(propertySource.containsProperty("prefix.spring.cloud.kubernetes.configuration.watcher.refreshDelay"))
.isTrue();
.isTrue();
assertThat(propertySource.getProperty("prefix.spring.cloud.kubernetes.configuration.watcher.refreshDelay"))
.isEqualTo("0");
.isEqualTo("0");
assertThat(propertySource.containsProperty("prefix.logging.level.org.springframework.cloud.kubernetes"))
.isTrue();
.isTrue();
assertThat(propertySource.getProperty("prefix.logging.level.org.springframework.cloud.kubernetes"))
.isEqualTo("TRACE");
.isEqualTo("TRACE");
}
@Test
@@ -175,7 +177,7 @@ class KubernetesClientConfigMapPropertySourceTests {
@Test
public void constructorShouldThrowExceptionOnFailureWhenFailFastIsEnabled() {
stubFor(get("/api/v1/namespaces/default/configmaps")
.willReturn(aResponse().withStatus(500).withBody("Internal Server Error")));
.willReturn(aResponse().withStatus(500).withBody("Internal Server Error")));
ConfigUtils.Prefix prefix = ConfigUtils.findPrefix("prefix", false, false, null);
NormalizedSource source = new NamedConfigMapNormalizedSource("my-config", "default", true, prefix, true);
@@ -183,14 +185,15 @@ class KubernetesClientConfigMapPropertySourceTests {
new MockEnvironment());
assertThatThrownBy(() -> new KubernetesClientConfigMapPropertySource(context))
.isInstanceOf(IllegalStateException.class).hasMessage("Internal Server Error");
.isInstanceOf(IllegalStateException.class)
.hasMessage("Internal Server Error");
verify(getRequestedFor(urlEqualTo("/api/v1/namespaces/default/configmaps")));
}
@Test
public void constructorShouldNotThrowExceptionOnFailureWhenFailFastIsDisabled() {
stubFor(get("/api/v1/namespaces/default/configmaps")
.willReturn(aResponse().withStatus(500).withBody("Internal Server Error")));
.willReturn(aResponse().withStatus(500).withBody("Internal Server Error")));
ConfigUtils.Prefix prefix = ConfigUtils.findPrefix("prefix", false, false, null);
NormalizedSource source = new NamedConfigMapNormalizedSource("my-config", "default", false, prefix, true);

View File

@@ -89,7 +89,9 @@ public class KubernetesClientConfigReloadAutoConfigurationTest {
ConfigurationPropertiesBindingPostProcessor.class, ConfigReloadPropertiesAutoConfiguration.class,
ConfigurationPropertiesRebinderAutoConfiguration.class, KubernetesClientBootstrapConfiguration.class,
KubernetesBootstrapConfiguration.class, KubernetesClientConfigReloadAutoConfiguration.class)
.web(org.springframework.boot.WebApplicationType.NONE).properties(envArray).run();
.web(org.springframework.boot.WebApplicationType.NONE)
.properties(envArray)
.run();
}
@BeforeAll
@@ -111,10 +113,11 @@ public class KubernetesClientConfigReloadAutoConfigurationTest {
void beforeEach() {
V1ConfigMapList TEST_CONFIGMAP = new V1ConfigMapList().addItemsItem(new V1ConfigMapBuilder().withMetadata(
new V1ObjectMetaBuilder().withName("test-cm").withNamespace("default").withResourceVersion("1").build())
.addToData("app.name", "test").build());
.addToData("app.name", "test")
.build());
WireMock.stubFor(get(urlMatching("^/api/v1/namespaces/default/configmaps.*"))
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(TEST_CONFIGMAP))));
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(TEST_CONFIGMAP))));
}
// 1. watchers
@@ -174,8 +177,11 @@ public class KubernetesClientConfigReloadAutoConfigurationTest {
setup("spring.cloud.kubernetes.reload.enabled=true", "spring.main.cloud-platform=KUBERNETES");
Map<String, ConfigurationChangeDetector> map = context.getBeansOfType(ConfigurationChangeDetector.class);
Assertions.assertEquals(map.size(), 1);
Assertions.assertTrue(map.values().iterator().next().getClass()
.isAssignableFrom(KubernetesClientEventBasedConfigMapChangeDetector.class));
Assertions.assertTrue(map.values()
.iterator()
.next()
.getClass()
.isAssignableFrom(KubernetesClientEventBasedConfigMapChangeDetector.class));
}
/**
@@ -195,8 +201,11 @@ public class KubernetesClientConfigReloadAutoConfigurationTest {
"spring.main.cloud-platform=KUBERNETES");
Map<String, ConfigurationChangeDetector> map = context.getBeansOfType(ConfigurationChangeDetector.class);
Assertions.assertEquals(map.size(), 1);
Assertions.assertTrue(map.values().iterator().next().getClass()
.isAssignableFrom(KubernetesClientEventBasedConfigMapChangeDetector.class));
Assertions.assertTrue(map.values()
.iterator()
.next()
.getClass()
.isAssignableFrom(KubernetesClientEventBasedConfigMapChangeDetector.class));
}
/**
@@ -278,8 +287,11 @@ public class KubernetesClientConfigReloadAutoConfigurationTest {
"spring.cloud.kubernetes.reload.mode=event");
Map<String, ConfigurationChangeDetector> map = context.getBeansOfType(ConfigurationChangeDetector.class);
Assertions.assertEquals(map.size(), 1);
Assertions.assertTrue(map.values().iterator().next().getClass()
.isAssignableFrom(KubernetesClientEventBasedSecretsChangeDetector.class));
Assertions.assertTrue(map.values()
.iterator()
.next()
.getClass()
.isAssignableFrom(KubernetesClientEventBasedSecretsChangeDetector.class));
}
/**
@@ -302,8 +314,8 @@ public class KubernetesClientConfigReloadAutoConfigurationTest {
"spring.cloud.kubernetes.reload.mode=polling");
Map<String, ConfigurationChangeDetector> map = context.getBeansOfType(ConfigurationChangeDetector.class);
Assertions.assertEquals(map.size(), 1);
Assertions.assertTrue(
map.values().iterator().next().getClass().isAssignableFrom(PollingSecretsChangeDetector.class));
Assertions
.assertTrue(map.values().iterator().next().getClass().isAssignableFrom(PollingSecretsChangeDetector.class));
}
/**
@@ -326,8 +338,10 @@ public class KubernetesClientConfigReloadAutoConfigurationTest {
"spring.cloud.kubernetes.reload.mode=event");
Map<String, ConfigurationChangeDetector> map = context.getBeansOfType(ConfigurationChangeDetector.class);
Assertions.assertEquals(map.size(), 2);
List<ConfigurationChangeDetector> result = map.values().stream()
.sorted(Comparator.comparing(x -> x.getClass().getName())).toList();
List<ConfigurationChangeDetector> result = map.values()
.stream()
.sorted(Comparator.comparing(x -> x.getClass().getName()))
.toList();
Assertions.assertEquals(result.get(0).getClass(), KubernetesClientEventBasedConfigMapChangeDetector.class);
Assertions.assertEquals(result.get(1).getClass(), KubernetesClientEventBasedSecretsChangeDetector.class);
}
@@ -352,8 +366,10 @@ public class KubernetesClientConfigReloadAutoConfigurationTest {
"spring.cloud.kubernetes.reload.mode=polling");
Map<String, ConfigurationChangeDetector> map = context.getBeansOfType(ConfigurationChangeDetector.class);
Assertions.assertEquals(map.size(), 2);
List<ConfigurationChangeDetector> result = map.values().stream()
.sorted(Comparator.comparing(x -> x.getClass().getName())).toList();
List<ConfigurationChangeDetector> result = map.values()
.stream()
.sorted(Comparator.comparing(x -> x.getClass().getName()))
.toList();
Assertions.assertEquals(result.get(0).getClass(), PollingConfigMapChangeDetector.class);
Assertions.assertEquals(result.get(1).getClass(), PollingSecretsChangeDetector.class);
}
@@ -419,8 +435,10 @@ public class KubernetesClientConfigReloadAutoConfigurationTest {
"spring.cloud.kubernetes.reload.monitoring-secrets=false");
Map<String, ConfigurationChangeDetector> map = context.getBeansOfType(ConfigurationChangeDetector.class);
Assertions.assertEquals(map.size(), 1);
List<ConfigurationChangeDetector> result = map.values().stream()
.sorted(Comparator.comparing(x -> x.getClass().getName())).toList();
List<ConfigurationChangeDetector> result = map.values()
.stream()
.sorted(Comparator.comparing(x -> x.getClass().getName()))
.toList();
Assertions.assertEquals(result.get(0).getClass(), KubernetesClientEventBasedConfigMapChangeDetector.class);
}
@@ -443,8 +461,10 @@ public class KubernetesClientConfigReloadAutoConfigurationTest {
"spring.cloud.kubernetes.reload.monitoring-secrets=false");
Map<String, ConfigurationChangeDetector> map = context.getBeansOfType(ConfigurationChangeDetector.class);
Assertions.assertEquals(map.size(), 1);
List<ConfigurationChangeDetector> result = map.values().stream()
.sorted(Comparator.comparing(x -> x.getClass().getName())).toList();
List<ConfigurationChangeDetector> result = map.values()
.stream()
.sorted(Comparator.comparing(x -> x.getClass().getName()))
.toList();
Assertions.assertEquals(result.get(0).getClass(), PollingConfigMapChangeDetector.class);
}

View File

@@ -37,7 +37,7 @@ class KubernetesClientConfigUtilsTests {
ConfigReloadProperties.ReloadStrategy.REFRESH, ConfigReloadProperties.ReloadDetectionMode.EVENT,
Duration.ofMillis(15000), Set.of("non-default"), false, Duration.ofSeconds(2));
Set<String> namespaces = KubernetesClientConfigUtils
.namespaces(new KubernetesNamespaceProvider(new MockEnvironment()), properties, "configmap");
.namespaces(new KubernetesNamespaceProvider(new MockEnvironment()), properties, "configmap");
Assertions.assertEquals(1, namespaces.size());
Assertions.assertEquals(namespaces.iterator().next(), "non-default");
}

View File

@@ -118,7 +118,8 @@ class KubernetesClientSecretsPropertySourceLocatorTests {
List.of(source1, source2), true, "app", "default", false, true, false, RetryProperties.DEFAULT);
PropertySource<?> propertySource = new KubernetesClientSecretsPropertySourceLocator(api,
new KubernetesNamespaceProvider(new MockEnvironment()), secretsConfigProperties).locate(ENV);
new KubernetesNamespaceProvider(new MockEnvironment()), secretsConfigProperties)
.locate(ENV);
assertThat(propertySource.containsProperty("password")).isTrue();
assertThat(propertySource.getProperty("password")).isEqualTo("p455w0rd");
}
@@ -131,7 +132,8 @@ class KubernetesClientSecretsPropertySourceLocatorTests {
List.of(), true, "db-secret", "default", false, true, false, RetryProperties.DEFAULT);
PropertySource<?> propertySource = new KubernetesClientSecretsPropertySourceLocator(api,
new KubernetesNamespaceProvider(new MockEnvironment()), secretsConfigProperties).locate(ENV);
new KubernetesNamespaceProvider(new MockEnvironment()), secretsConfigProperties)
.locate(ENV);
assertThat(propertySource.containsProperty("password")).isTrue();
assertThat(propertySource.getProperty("password")).isEqualTo("p455w0rd");
}
@@ -152,8 +154,8 @@ class KubernetesClientSecretsPropertySourceLocatorTests {
List.of(), true, "db-secret", "", false, true, false, RetryProperties.DEFAULT);
assertThatThrownBy(() -> new KubernetesClientSecretsPropertySourceLocator(api,
new KubernetesNamespaceProvider(new MockEnvironment()), secretsConfigProperties).locate(ENV))
.isInstanceOf(NamespaceResolutionFailedException.class);
new KubernetesNamespaceProvider(new MockEnvironment()), secretsConfigProperties)
.locate(ENV)).isInstanceOf(NamespaceResolutionFailedException.class);
}
@Test
@@ -168,7 +170,7 @@ class KubernetesClientSecretsPropertySourceLocatorTests {
new KubernetesNamespaceProvider(new MockEnvironment()), secretsConfigProperties);
assertThatThrownBy(() -> locator.locate(new MockEnvironment())).isInstanceOf(IllegalStateException.class)
.hasMessage("Internal Server Error");
.hasMessage("Internal Server Error");
}
@Test

View File

@@ -59,15 +59,24 @@ class KubernetesClientSecretsPropertySourceTests {
private static final String API = "/api/v1/namespaces/default/secrets";
private static final V1SecretList SECRET_LIST = new V1SecretListBuilder().addToItems(new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("db-secret").withResourceVersion("0")
.withNamespace("default").build())
.addToData("password", "p455w0rd".getBytes()).addToData("username", "user".getBytes()).build()).build();
private static final V1SecretList SECRET_LIST = new V1SecretListBuilder()
.addToItems(
new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("db-secret")
.withResourceVersion("0")
.withNamespace("default")
.build())
.addToData("password", "p455w0rd".getBytes())
.addToData("username", "user".getBytes())
.build())
.build();
private static final V1SecretList EMPTY_DATA_SECRET_LIST = new V1SecretListBuilder()
.addToItems(new V1SecretBuilder().withMetadata(new V1ObjectMetaBuilder().withName("db-secret")
.withResourceVersion("0").withNamespace("default").build()).build())
.build();
.addToItems(new V1SecretBuilder().withMetadata(new V1ObjectMetaBuilder().withName("db-secret")
.withResourceVersion("0")
.withNamespace("default")
.build()).build())
.build();
private static final String LIST_API_WITH_LABEL = "/api/v1/namespaces/default/secrets";
@@ -124,7 +133,7 @@ class KubernetesClientSecretsPropertySourceTests {
void emptyDataSecretTest() {
CoreV1Api api = new CoreV1Api();
stubFor(get(API)
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(EMPTY_DATA_SECRET_LIST))));
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(EMPTY_DATA_SECRET_LIST))));
NormalizedSource source = new NamedSecretNormalizedSource("db-secret", "default", false, false);
KubernetesClientConfigContext context = new KubernetesClientConfigContext(api, source, "default",
@@ -177,7 +186,8 @@ class KubernetesClientSecretsPropertySourceTests {
new MockEnvironment());
assertThatThrownBy(() -> new KubernetesClientSecretsPropertySource(context))
.isInstanceOf(IllegalStateException.class).hasMessage("Internal Server Error");
.isInstanceOf(IllegalStateException.class)
.hasMessage("Internal Server Error");
verify(getRequestedFor(urlEqualTo(API)));
}

View File

@@ -97,8 +97,13 @@ class LabeledConfigMapContextToSourceDataProviderTests {
@Test
void singleConfigMapMatchAgainstLabels() {
V1ConfigMap one = new V1ConfigMapBuilder().withMetadata(new V1ObjectMetaBuilder().withName("test-configmap")
.withLabels(LABELS).withNamespace(NAMESPACE).build()).addToData("name", "value").build();
V1ConfigMap one = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("test-configmap")
.withLabels(LABELS)
.withNamespace(NAMESPACE)
.build())
.addToData("name", "value")
.build();
V1ConfigMapList configMapList = new V1ConfigMapList().addItemsItem(one);
stubCall(configMapList);
@@ -123,18 +128,33 @@ class LabeledConfigMapContextToSourceDataProviderTests {
@Test
void twoConfigMapsMatchAgainstLabels() {
V1ConfigMap redOne = new V1ConfigMapBuilder().withMetadata(new V1ObjectMetaBuilder().withName("red-configmap")
.withLabels(RED_LABEL).withNamespace(NAMESPACE).build()).addToData("colorOne", "really-red").build();
V1ConfigMap redOne = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("red-configmap")
.withLabels(RED_LABEL)
.withNamespace(NAMESPACE)
.build())
.addToData("colorOne", "really-red")
.build();
V1ConfigMap redTwo = new V1ConfigMapBuilder().withMetadata(new V1ObjectMetaBuilder()
.withName("red-configmap-again").withLabels(RED_LABEL).withNamespace(NAMESPACE).build())
.addToData("colorTwo", "really-red-again").build();
V1ConfigMap redTwo = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("red-configmap-again")
.withLabels(RED_LABEL)
.withNamespace(NAMESPACE)
.build())
.addToData("colorTwo", "really-red-again")
.build();
V1ConfigMap blue = new V1ConfigMapBuilder().withMetadata(new V1ObjectMetaBuilder().withName("blue-configmap")
.withLabels(BLUE_LABEL).withNamespace(NAMESPACE).build()).addToData("color", "blue").build();
V1ConfigMap blue = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("blue-configmap")
.withLabels(BLUE_LABEL)
.withNamespace(NAMESPACE)
.build())
.addToData("color", "blue")
.build();
V1ConfigMapList configMapList = new V1ConfigMapList().addItemsItem(redOne).addItemsItem(redTwo)
.addItemsItem(blue);
V1ConfigMapList configMapList = new V1ConfigMapList().addItemsItem(redOne)
.addItemsItem(redTwo)
.addItemsItem(blue);
stubCall(configMapList);
CoreV1Api api = new CoreV1Api();
@@ -159,8 +179,13 @@ class LabeledConfigMapContextToSourceDataProviderTests {
@Test
void configMapNoMatch() {
V1ConfigMap one = new V1ConfigMapBuilder().withMetadata(new V1ObjectMetaBuilder().withName("pink-configmap")
.withLabels(PINK_LABEL).withNamespace(NAMESPACE).build()).addToData("color", "pink").build();
V1ConfigMap one = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("pink-configmap")
.withLabels(PINK_LABEL)
.withNamespace(NAMESPACE)
.build())
.addToData("color", "pink")
.build();
V1ConfigMapList configMapList = new V1ConfigMapList().addItemsItem(one);
stubCall(configMapList);
@@ -186,8 +211,13 @@ class LabeledConfigMapContextToSourceDataProviderTests {
*/
@Test
void namespaceMatch() {
V1ConfigMap one = new V1ConfigMapBuilder().withMetadata(new V1ObjectMetaBuilder().withName("test-configmap")
.withLabels(LABELS).withNamespace(NAMESPACE).build()).addToData("name", "value").build();
V1ConfigMap one = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("test-configmap")
.withLabels(LABELS)
.withNamespace(NAMESPACE)
.build())
.addToData("name", "value")
.build();
V1ConfigMapList configMapList = new V1ConfigMapList().addItemsItem(one);
stubCall(configMapList);
@@ -213,8 +243,13 @@ class LabeledConfigMapContextToSourceDataProviderTests {
*/
@Test
void testWithPrefix() {
V1ConfigMap one = new V1ConfigMapBuilder().withMetadata(new V1ObjectMetaBuilder().withName("blue-configmap")
.withLabels(BLUE_LABEL).withNamespace(NAMESPACE).build()).addToData("what-color", "blue-color").build();
V1ConfigMap one = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("blue-configmap")
.withLabels(BLUE_LABEL)
.withNamespace(NAMESPACE)
.build())
.addToData("what-color", "blue-color")
.build();
V1ConfigMapList configMapList = new V1ConfigMapList().addItemsItem(one);
stubCall(configMapList);
@@ -245,12 +280,21 @@ class LabeledConfigMapContextToSourceDataProviderTests {
@Test
void testTwoConfigmapsWithPrefix() {
V1ConfigMap one = new V1ConfigMapBuilder().withMetadata(new V1ObjectMetaBuilder().withName("blue-configmap")
.withLabels(BLUE_LABEL).withNamespace(NAMESPACE).build()).addToData("first", "blue").build();
V1ConfigMap one = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("blue-configmap")
.withLabels(BLUE_LABEL)
.withNamespace(NAMESPACE)
.build())
.addToData("first", "blue")
.build();
V1ConfigMap two = new V1ConfigMapBuilder().withMetadata(new V1ObjectMetaBuilder()
.withName("another-blue-configmap").withLabels(BLUE_LABEL).withNamespace(NAMESPACE).build())
.addToData("second", "blue").build();
V1ConfigMap two = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("another-blue-configmap")
.withLabels(BLUE_LABEL)
.withNamespace(NAMESPACE)
.build())
.addToData("second", "blue")
.build();
V1ConfigMapList configMapList = new V1ConfigMapList().addItemsItem(one).addItemsItem(two);
@@ -291,12 +335,18 @@ class LabeledConfigMapContextToSourceDataProviderTests {
@Test
void searchWithLabelsNoConfigmapsFound() {
V1ConfigMap one = new V1ConfigMapBuilder().withMetadata(new V1ObjectMetaBuilder().withName("color-configmap")
.withLabels(BLUE_LABEL).withNamespace(NAMESPACE).build()).addToData("one", "1").build();
V1ConfigMap one = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("color-configmap")
.withLabels(BLUE_LABEL)
.withNamespace(NAMESPACE)
.build())
.addToData("one", "1")
.build();
V1ConfigMap two = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("color-config-k8s").withNamespace(NAMESPACE).build())
.addToData("two", "2").build();
.withMetadata(new V1ObjectMetaBuilder().withName("color-config-k8s").withNamespace(NAMESPACE).build())
.addToData("two", "2")
.build();
V1ConfigMapList configMapList = new V1ConfigMapList().addItemsItem(one).addItemsItem(two);
@@ -324,12 +374,18 @@ class LabeledConfigMapContextToSourceDataProviderTests {
@Test
void searchWithLabelsOneConfigMapFound() {
V1ConfigMap one = new V1ConfigMapBuilder().withMetadata(new V1ObjectMetaBuilder().withName("color-configmap")
.withLabels(BLUE_LABEL).withNamespace(NAMESPACE).build()).addToData("one", "1").build();
V1ConfigMap one = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("color-configmap")
.withLabels(BLUE_LABEL)
.withNamespace(NAMESPACE)
.build())
.addToData("one", "1")
.build();
V1ConfigMap two = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("shape-configmap").withNamespace(NAMESPACE).build())
.addToData("two", "2").build();
.withMetadata(new V1ObjectMetaBuilder().withName("shape-configmap").withNamespace(NAMESPACE).build())
.addToData("two", "2")
.build();
V1ConfigMapList configMapList = new V1ConfigMapList().addItemsItem(one).addItemsItem(two);
@@ -359,12 +415,21 @@ class LabeledConfigMapContextToSourceDataProviderTests {
@Test
void searchWithLabelsOneConfigMapFoundAndOneFromProfileFound() {
V1ConfigMap one = new V1ConfigMapBuilder().withMetadata(new V1ObjectMetaBuilder().withName("color-configmap")
.withLabels(BLUE_LABEL).withNamespace(NAMESPACE).build()).addToData("one", "1").build();
V1ConfigMap one = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("color-configmap")
.withLabels(BLUE_LABEL)
.withNamespace(NAMESPACE)
.build())
.addToData("one", "1")
.build();
V1ConfigMap two = new V1ConfigMapBuilder().withMetadata(new V1ObjectMetaBuilder()
.withName("color-configmap-k8s").withLabels(RED_LABEL).withNamespace(NAMESPACE).build())
.addToData("two", "2").build();
V1ConfigMap two = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("color-configmap-k8s")
.withLabels(RED_LABEL)
.withNamespace(NAMESPACE)
.build())
.addToData("two", "2")
.build();
V1ConfigMapList configMapList = new V1ConfigMapList().addItemsItem(one).addItemsItem(two);
@@ -399,29 +464,51 @@ class LabeledConfigMapContextToSourceDataProviderTests {
@Test
void searchWithLabelsTwoConfigMapsFoundAndOneFromProfileFound() {
V1ConfigMap colorConfigMap = new V1ConfigMapBuilder().withMetadata(new V1ObjectMetaBuilder()
.withName("color-configmap").withLabels(BLUE_LABEL).withNamespace(NAMESPACE).build())
.addToData("one", "1").build();
V1ConfigMap colorConfigMap = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("color-configmap")
.withLabels(BLUE_LABEL)
.withNamespace(NAMESPACE)
.build())
.addToData("one", "1")
.build();
V1ConfigMap shapeConfigmap = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("shape-configmap")
.withLabels(Map.of("color", "blue", "shape", "round")).withNamespace(NAMESPACE).build())
.addToData("two", "2").build();
.withMetadata(new V1ObjectMetaBuilder().withName("shape-configmap")
.withLabels(Map.of("color", "blue", "shape", "round"))
.withNamespace(NAMESPACE)
.build())
.addToData("two", "2")
.build();
V1ConfigMap noFit = new V1ConfigMapBuilder().withMetadata(new V1ObjectMetaBuilder().withName("no-fit")
.withLabels(Map.of("tag", "no-fit")).withNamespace(NAMESPACE).build()).addToData("three", "3").build();
V1ConfigMap noFit = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("no-fit")
.withLabels(Map.of("tag", "no-fit"))
.withNamespace(NAMESPACE)
.build())
.addToData("three", "3")
.build();
V1ConfigMap colorConfigmapK8s = new V1ConfigMapBuilder().withMetadata(new V1ObjectMetaBuilder()
.withName("color-configmap-k8s").withLabels(RED_LABEL).withNamespace(NAMESPACE).build())
.addToData("four", "4").build();
V1ConfigMap colorConfigmapK8s = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("color-configmap-k8s")
.withLabels(RED_LABEL)
.withNamespace(NAMESPACE)
.build())
.addToData("four", "4")
.build();
V1ConfigMap shapeConfigmapK8s = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("shape-configmap-k8s")
.withLabels(Map.of("shape", "triangle")).withNamespace(NAMESPACE).build())
.addToData("five", "5").build();
.withMetadata(new V1ObjectMetaBuilder().withName("shape-configmap-k8s")
.withLabels(Map.of("shape", "triangle"))
.withNamespace(NAMESPACE)
.build())
.addToData("five", "5")
.build();
V1ConfigMapList configMapList = new V1ConfigMapList().addItemsItem(colorConfigMap).addItemsItem(shapeConfigmap)
.addItemsItem(noFit).addItemsItem(colorConfigmapK8s).addItemsItem(shapeConfigmapK8s);
V1ConfigMapList configMapList = new V1ConfigMapList().addItemsItem(colorConfigMap)
.addItemsItem(shapeConfigmap)
.addItemsItem(noFit)
.addItemsItem(colorConfigmapK8s)
.addItemsItem(shapeConfigmapK8s);
stubCall(configMapList);
CoreV1Api api = new CoreV1Api();
@@ -437,13 +524,13 @@ class LabeledConfigMapContextToSourceDataProviderTests {
Assertions.assertEquals(sourceData.sourceData().size(), 4);
Assertions.assertEquals(sourceData.sourceData()
.get("color-configmap.color-configmap-k8s.shape-configmap.shape-configmap-k8s.one"), "1");
.get("color-configmap.color-configmap-k8s.shape-configmap.shape-configmap-k8s.one"), "1");
Assertions.assertEquals(sourceData.sourceData()
.get("color-configmap.color-configmap-k8s.shape-configmap.shape-configmap-k8s.two"), "2");
.get("color-configmap.color-configmap-k8s.shape-configmap.shape-configmap-k8s.two"), "2");
Assertions.assertEquals(sourceData.sourceData()
.get("color-configmap.color-configmap-k8s.shape-configmap.shape-configmap-k8s.four"), "4");
.get("color-configmap.color-configmap-k8s.shape-configmap.shape-configmap-k8s.four"), "4");
Assertions.assertEquals(sourceData.sourceData()
.get("color-configmap.color-configmap-k8s.shape-configmap.shape-configmap-k8s.five"), "5");
.get("color-configmap.color-configmap-k8s.shape-configmap.shape-configmap-k8s.five"), "5");
Assertions.assertEquals(sourceData.sourceName(),
"configmap.color-configmap.color-configmap-k8s.shape-configmap.shape-configmap-k8s.default");
@@ -461,13 +548,21 @@ class LabeledConfigMapContextToSourceDataProviderTests {
*/
@Test
void cache(CapturedOutput output) {
V1ConfigMap red = new V1ConfigMapBuilder().withMetadata(new V1ObjectMetaBuilder()
.withLabels(Map.of("color", "red")).withNamespace(NAMESPACE).withName("red-configmap").build())
.addToData("color", "red").build();
V1ConfigMap red = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withLabels(Map.of("color", "red"))
.withNamespace(NAMESPACE)
.withName("red-configmap")
.build())
.addToData("color", "red")
.build();
V1ConfigMap green = new V1ConfigMapBuilder().withMetadata(new V1ObjectMetaBuilder()
.withLabels(Map.of("color", "green")).withNamespace(NAMESPACE).withName("green-configmap").build())
.addToData("color", "green").build();
V1ConfigMap green = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withLabels(Map.of("color", "green"))
.withNamespace(NAMESPACE)
.withName("green-configmap")
.build())
.addToData("color", "green")
.build();
V1ConfigMapList configMapList = new V1ConfigMapList().addItemsItem(red).addItemsItem(green);
@@ -508,7 +603,7 @@ class LabeledConfigMapContextToSourceDataProviderTests {
private void stubCall(V1ConfigMapList list) {
stubFor(get("/api/v1/namespaces/default/configmaps")
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(list))));
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(list))));
}
}

View File

@@ -94,9 +94,12 @@ class LabeledSecretContextToSourceDataProviderTests {
void noMatch() {
V1Secret red = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withLabels(Collections.singletonMap("color", "red"))
.withNamespace(NAMESPACE).withName("red-secret").build())
.addToData("color", Base64.getEncoder().encode("really-red".getBytes())).build();
.withMetadata(new V1ObjectMetaBuilder().withLabels(Collections.singletonMap("color", "red"))
.withNamespace(NAMESPACE)
.withName("red-secret")
.build())
.addToData("color", Base64.getEncoder().encode("really-red".getBytes()))
.build();
V1SecretList secretList = new V1SecretList().addItemsItem(red);
stubCall(secretList);
@@ -125,7 +128,8 @@ class LabeledSecretContextToSourceDataProviderTests {
V1Secret red = new V1SecretBuilder().withMetadata(
new V1ObjectMetaBuilder().withLabels(LABELS).withNamespace(NAMESPACE).withName("test-secret").build())
.addToData("color", "really-red".getBytes()).build();
.addToData("color", "really-red".getBytes())
.build();
V1SecretList secretList = new V1SecretList().addItemsItem(red);
stubCall(secretList);
@@ -151,11 +155,13 @@ class LabeledSecretContextToSourceDataProviderTests {
V1Secret one = new V1SecretBuilder().withMetadata(
new V1ObjectMetaBuilder().withLabels(RED_LABEL).withNamespace(NAMESPACE).withName("color-one").build())
.addToData("colorOne", "really-red-one".getBytes()).build();
.addToData("colorOne", "really-red-one".getBytes())
.build();
V1Secret two = new V1SecretBuilder().withMetadata(
new V1ObjectMetaBuilder().withLabels(RED_LABEL).withNamespace(NAMESPACE).withName("color-two").build())
.addToData("colorTwo", "really-red-two".getBytes()).build();
.addToData("colorTwo", "really-red-two".getBytes())
.build();
V1SecretList secretList = new V1SecretList().addItemsItem(one).addItemsItem(two);
stubCall(secretList);
@@ -179,7 +185,8 @@ class LabeledSecretContextToSourceDataProviderTests {
void namespaceMatch() {
V1Secret one = new V1SecretBuilder().withMetadata(
new V1ObjectMetaBuilder().withLabels(LABELS).withNamespace(NAMESPACE).withName("test-secret").build())
.addToData("color", "really-red".getBytes()).build();
.addToData("color", "really-red".getBytes())
.build();
V1SecretList secretList = new V1SecretList().addItemsItem(one);
stubCall(secretList);
@@ -205,9 +212,13 @@ class LabeledSecretContextToSourceDataProviderTests {
@Test
void testWithPrefix() {
V1Secret one = new V1SecretBuilder().withMetadata(new V1ObjectMetaBuilder().withLabels(Map.of("color", "blue"))
.withNamespace(NAMESPACE).withName("blue-secret").build())
.addToData("what-color", "blue-color".getBytes()).build();
V1Secret one = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withLabels(Map.of("color", "blue"))
.withNamespace(NAMESPACE)
.withName("blue-secret")
.build())
.addToData("what-color", "blue-color".getBytes())
.build();
V1SecretList secretList = new V1SecretList().addItemsItem(one);
stubCall(secretList);
@@ -238,13 +249,21 @@ class LabeledSecretContextToSourceDataProviderTests {
@Test
void testTwoSecretsWithPrefix() {
V1Secret one = new V1SecretBuilder().withMetadata(new V1ObjectMetaBuilder().withLabels(Map.of("color", "blue"))
.withNamespace(NAMESPACE).withName("blue-secret").build()).addToData("first", "blue".getBytes())
.build();
V1Secret one = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withLabels(Map.of("color", "blue"))
.withNamespace(NAMESPACE)
.withName("blue-secret")
.build())
.addToData("first", "blue".getBytes())
.build();
V1Secret two = new V1SecretBuilder().withMetadata(new V1ObjectMetaBuilder().withLabels(Map.of("color", "blue"))
.withNamespace(NAMESPACE).withName("another-blue-secret").build())
.addToData("second", "blue".getBytes()).build();
V1Secret two = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withLabels(Map.of("color", "blue"))
.withNamespace(NAMESPACE)
.withName("another-blue-secret")
.build())
.addToData("second", "blue".getBytes())
.build();
V1SecretList secretList = new V1SecretList().addItemsItem(one).addItemsItem(two);
@@ -289,13 +308,21 @@ class LabeledSecretContextToSourceDataProviderTests {
@Test
void searchWithLabelsOneSecretFound() {
V1Secret colorSecret = new V1SecretBuilder().withMetadata(new V1ObjectMetaBuilder()
.withLabels(Map.of("color", "blue")).withNamespace(NAMESPACE).withName("color-secret").build())
.addToData("one", "1".getBytes()).build();
V1Secret colorSecret = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withLabels(Map.of("color", "blue"))
.withNamespace(NAMESPACE)
.withName("color-secret")
.build())
.addToData("one", "1".getBytes())
.build();
V1Secret shapeSecret = new V1SecretBuilder().withMetadata(new V1ObjectMetaBuilder()
.withLabels(Map.of("shape", "round")).withNamespace(NAMESPACE).withName("shape-secret").build())
.addToData("two", "2".getBytes()).build();
V1Secret shapeSecret = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withLabels(Map.of("shape", "round"))
.withNamespace(NAMESPACE)
.withName("shape-secret")
.build())
.addToData("two", "2".getBytes())
.build();
V1SecretList secretList = new V1SecretList().addItemsItem(colorSecret).addItemsItem(shapeSecret);
@@ -325,13 +352,21 @@ class LabeledSecretContextToSourceDataProviderTests {
@Test
void searchWithLabelsOneSecretFoundAndOneFromProfileFound() {
V1Secret colorSecret = new V1SecretBuilder().withMetadata(new V1ObjectMetaBuilder()
.withLabels(Map.of("color", "blue")).withNamespace(NAMESPACE).withName("color-secret").build())
.addToData("one", "1".getBytes()).build();
V1Secret colorSecret = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withLabels(Map.of("color", "blue"))
.withNamespace(NAMESPACE)
.withName("color-secret")
.build())
.addToData("one", "1".getBytes())
.build();
V1Secret shapeSecret = new V1SecretBuilder().withMetadata(new V1ObjectMetaBuilder()
.withLabels(Map.of("color", "red")).withNamespace(NAMESPACE).withName("color-secret-k8s").build())
.addToData("two", "2".getBytes()).build();
V1Secret shapeSecret = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withLabels(Map.of("color", "red"))
.withNamespace(NAMESPACE)
.withName("color-secret-k8s")
.build())
.addToData("two", "2".getBytes())
.build();
V1SecretList secretList = new V1SecretList().addItemsItem(colorSecret).addItemsItem(shapeSecret);
@@ -366,29 +401,51 @@ class LabeledSecretContextToSourceDataProviderTests {
@Test
void searchWithLabelsTwoSecretsFoundAndOneFromProfileFound() {
V1Secret colorSecret = new V1SecretBuilder().withMetadata(new V1ObjectMetaBuilder()
.withLabels(Map.of("color", "blue")).withNamespace(NAMESPACE).withName("color-secret").build())
.addToData("one", "1".getBytes()).build();
V1Secret colorSecret = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withLabels(Map.of("color", "blue"))
.withNamespace(NAMESPACE)
.withName("color-secret")
.build())
.addToData("one", "1".getBytes())
.build();
V1Secret shapeSecret = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withLabels(Map.of("color", "blue", "shape", "round"))
.withNamespace(NAMESPACE).withName("shape-secret").build())
.addToData("two", "2".getBytes()).build();
.withMetadata(new V1ObjectMetaBuilder().withLabels(Map.of("color", "blue", "shape", "round"))
.withNamespace(NAMESPACE)
.withName("shape-secret")
.build())
.addToData("two", "2".getBytes())
.build();
V1Secret noFit = new V1SecretBuilder().withMetadata(new V1ObjectMetaBuilder()
.withLabels(Map.of("tag", "no-fit")).withNamespace(NAMESPACE).withName("no-fit").build())
.addToData("three", "3".getBytes()).build();
V1Secret noFit = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withLabels(Map.of("tag", "no-fit"))
.withNamespace(NAMESPACE)
.withName("no-fit")
.build())
.addToData("three", "3".getBytes())
.build();
V1Secret colorSecretK8s = new V1SecretBuilder().withMetadata(new V1ObjectMetaBuilder()
.withLabels(Map.of("color", "red")).withNamespace(NAMESPACE).withName("color-secret-k8s").build())
.addToData("four", "4".getBytes()).build();
V1Secret colorSecretK8s = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withLabels(Map.of("color", "red"))
.withNamespace(NAMESPACE)
.withName("color-secret-k8s")
.build())
.addToData("four", "4".getBytes())
.build();
V1Secret shapeSecretK8s = new V1SecretBuilder().withMetadata(new V1ObjectMetaBuilder()
.withLabels(Map.of("shape", "triangle")).withNamespace(NAMESPACE).withName("shape-secret-k8s").build())
.addToData("five", "5".getBytes()).build();
V1Secret shapeSecretK8s = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withLabels(Map.of("shape", "triangle"))
.withNamespace(NAMESPACE)
.withName("shape-secret-k8s")
.build())
.addToData("five", "5".getBytes())
.build();
V1SecretList secretList = new V1SecretList().addItemsItem(colorSecret).addItemsItem(shapeSecret)
.addItemsItem(noFit).addItemsItem(colorSecretK8s).addItemsItem(shapeSecretK8s);
V1SecretList secretList = new V1SecretList().addItemsItem(colorSecret)
.addItemsItem(shapeSecret)
.addItemsItem(noFit)
.addItemsItem(colorSecretK8s)
.addItemsItem(shapeSecretK8s);
stubCall(secretList);
CoreV1Api api = new CoreV1Api();
@@ -422,9 +479,13 @@ class LabeledSecretContextToSourceDataProviderTests {
*/
@Test
void testYaml() {
V1Secret colorSecret = new V1SecretBuilder().withMetadata(new V1ObjectMetaBuilder()
.withLabels(Map.of("color", "blue")).withNamespace(NAMESPACE).withName("color-secret").build())
.addToData("test.yaml", "color: blue".getBytes()).build();
V1Secret colorSecret = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withLabels(Map.of("color", "blue"))
.withNamespace(NAMESPACE)
.withName("color-secret")
.build())
.addToData("test.yaml", "color: blue".getBytes())
.build();
V1SecretList secretList = new V1SecretList().addItemsItem(colorSecret);
@@ -455,12 +516,21 @@ class LabeledSecretContextToSourceDataProviderTests {
*/
@Test
void cache(CapturedOutput output) {
V1Secret red = new V1SecretBuilder().withMetadata(new V1ObjectMetaBuilder().withLabels(Map.of("color", "red"))
.withNamespace(NAMESPACE).withName("red").build()).addToData("color", "red".getBytes()).build();
V1Secret red = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withLabels(Map.of("color", "red"))
.withNamespace(NAMESPACE)
.withName("red")
.build())
.addToData("color", "red".getBytes())
.build();
V1Secret green = new V1SecretBuilder().withMetadata(new V1ObjectMetaBuilder()
.withLabels(Map.of("color", "green")).withNamespace(NAMESPACE).withName("green").build())
.addToData("color", "green".getBytes()).build();
V1Secret green = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withLabels(Map.of("color", "green"))
.withNamespace(NAMESPACE)
.withName("green")
.build())
.addToData("color", "green".getBytes())
.build();
V1SecretList secretList = new V1SecretList().addItemsItem(red).addItemsItem(green);
@@ -501,7 +571,7 @@ class LabeledSecretContextToSourceDataProviderTests {
private void stubCall(V1SecretList list) {
stubFor(get("/api/v1/namespaces/default/secrets")
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(list))));
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(list))));
}
}

View File

@@ -94,8 +94,9 @@ class NamedConfigMapContextToSourceDataProviderTests {
@Test
void noMatch() {
V1ConfigMap redConfigMap = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName(RED_CONFIG_MAP_NAME).withNamespace(NAMESPACE).build())
.addToData(COLOR_REALLY_RED).build();
.withMetadata(new V1ObjectMetaBuilder().withName(RED_CONFIG_MAP_NAME).withNamespace(NAMESPACE).build())
.addToData(COLOR_REALLY_RED)
.build();
V1ConfigMapList configMapList = new V1ConfigMapList().addItemsItem(redConfigMap);
stubCall(configMapList);
@@ -123,8 +124,9 @@ class NamedConfigMapContextToSourceDataProviderTests {
void match() {
V1ConfigMap configMap = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName(RED_CONFIG_MAP_NAME).withNamespace(NAMESPACE).build())
.addToData(COLOR_REALLY_RED).build();
.withMetadata(new V1ObjectMetaBuilder().withName(RED_CONFIG_MAP_NAME).withNamespace(NAMESPACE).build())
.addToData(COLOR_REALLY_RED)
.build();
V1ConfigMapList configMapList = new V1ConfigMapList().addItemsItem(configMap);
stubCall(configMapList);
@@ -153,12 +155,14 @@ class NamedConfigMapContextToSourceDataProviderTests {
void matchIncludeSingleProfile() {
V1ConfigMap red = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName(RED_CONFIG_MAP_NAME).withNamespace(NAMESPACE).build())
.addToData(COLOR_REALLY_RED).build();
.withMetadata(new V1ObjectMetaBuilder().withName(RED_CONFIG_MAP_NAME).withNamespace(NAMESPACE).build())
.addToData(COLOR_REALLY_RED)
.build();
V1ConfigMap redWithProfile = new V1ConfigMapBuilder().withMetadata(
new V1ObjectMetaBuilder().withName(RED_WITH_PROFILE_CONFIG_MAP_NAME).withNamespace(NAMESPACE).build())
.addToData(TASTE_MANGO).build();
.addToData(TASTE_MANGO)
.build();
V1ConfigMapList configMapList = new V1ConfigMapList().addItemsItem(red).addItemsItem(redWithProfile);
stubCall(configMapList);
@@ -193,12 +197,14 @@ class NamedConfigMapContextToSourceDataProviderTests {
void matchIncludeSingleProfileWithPrefix() {
V1ConfigMap red = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName(RED_CONFIG_MAP_NAME).withNamespace(NAMESPACE).build())
.addToData(COLOR_REALLY_RED).build();
.withMetadata(new V1ObjectMetaBuilder().withName(RED_CONFIG_MAP_NAME).withNamespace(NAMESPACE).build())
.addToData(COLOR_REALLY_RED)
.build();
V1ConfigMap redWithTaste = new V1ConfigMapBuilder().withMetadata(
new V1ObjectMetaBuilder().withName(RED_WITH_PROFILE_CONFIG_MAP_NAME).withNamespace(NAMESPACE).build())
.addToData(TASTE_MANGO).build();
.addToData(TASTE_MANGO)
.build();
V1ConfigMapList configMapList = new V1ConfigMapList().addItemsItem(red).addItemsItem(redWithTaste);
stubCall(configMapList);
@@ -233,20 +239,28 @@ class NamedConfigMapContextToSourceDataProviderTests {
void matchIncludeTwoProfilesWithPrefix() {
V1ConfigMap red = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName(RED_CONFIG_MAP_NAME).withNamespace(NAMESPACE).build())
.addToData(COLOR_REALLY_RED).build();
.withMetadata(new V1ObjectMetaBuilder().withName(RED_CONFIG_MAP_NAME).withNamespace(NAMESPACE).build())
.addToData(COLOR_REALLY_RED)
.build();
V1ConfigMap redWithTaste = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName(RED_CONFIG_MAP_NAME + "-with-taste")
.withNamespace(NAMESPACE).withResourceVersion("1").build())
.addToData(TASTE_MANGO).build();
.withMetadata(new V1ObjectMetaBuilder().withName(RED_CONFIG_MAP_NAME + "-with-taste")
.withNamespace(NAMESPACE)
.withResourceVersion("1")
.build())
.addToData(TASTE_MANGO)
.build();
V1ConfigMap redWithShape = new V1ConfigMapBuilder().withMetadata(new V1ObjectMetaBuilder()
.withName(RED_CONFIG_MAP_NAME + "-with-shape").withNamespace(NAMESPACE).build())
.addToData("shape", "round").build();
V1ConfigMap redWithShape = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName(RED_CONFIG_MAP_NAME + "-with-shape")
.withNamespace(NAMESPACE)
.build())
.addToData("shape", "round")
.build();
V1ConfigMapList configMapList = new V1ConfigMapList().addItemsItem(red).addItemsItem(redWithTaste)
.addItemsItem(redWithShape);
V1ConfigMapList configMapList = new V1ConfigMapList().addItemsItem(red)
.addItemsItem(redWithTaste)
.addItemsItem(redWithShape);
stubCall(configMapList);
CoreV1Api api = new CoreV1Api();
@@ -279,8 +293,9 @@ class NamedConfigMapContextToSourceDataProviderTests {
void matchWithName() {
V1ConfigMap red = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("application").withNamespace(NAMESPACE).build())
.addToData("color", "red").build();
.withMetadata(new V1ObjectMetaBuilder().withName("application").withNamespace(NAMESPACE).build())
.addToData("color", "red")
.build();
V1ConfigMapList configMapList = new V1ConfigMapList().addItemsItem(red);
stubCall(configMapList);
@@ -309,8 +324,9 @@ class NamedConfigMapContextToSourceDataProviderTests {
void namespaceMatch() {
V1ConfigMap configMap = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName(RED_CONFIG_MAP_NAME).withNamespace(NAMESPACE).build())
.addToData(COLOR_REALLY_RED).build();
.withMetadata(new V1ObjectMetaBuilder().withName(RED_CONFIG_MAP_NAME).withNamespace(NAMESPACE).build())
.addToData(COLOR_REALLY_RED)
.build();
V1ConfigMapList configMapList = new V1ConfigMapList().addItemsItem(configMap);
stubCall(configMapList);
@@ -336,8 +352,9 @@ class NamedConfigMapContextToSourceDataProviderTests {
@Test
void testSingleYaml() {
V1ConfigMap singleYaml = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName(RED_CONFIG_MAP_NAME).withNamespace(NAMESPACE).build())
.addToData("single.yaml", "key: value").build();
.withMetadata(new V1ObjectMetaBuilder().withName(RED_CONFIG_MAP_NAME).withNamespace(NAMESPACE).build())
.addToData("single.yaml", "key: value")
.build();
V1ConfigMapList configMapList = new V1ConfigMapList().addItemsItem(singleYaml);
stubCall(configMapList);
@@ -365,8 +382,9 @@ class NamedConfigMapContextToSourceDataProviderTests {
@Test
void testCorrectNameWithProfile() {
V1ConfigMap one = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("one").withNamespace(NAMESPACE).build())
.addToData("key", "value").build();
.withMetadata(new V1ObjectMetaBuilder().withName("one").withNamespace(NAMESPACE).build())
.addToData("key", "value")
.build();
V1ConfigMapList configMapList = new V1ConfigMapList().addItemsItem(one);
stubCall(configMapList);
@@ -397,12 +415,14 @@ class NamedConfigMapContextToSourceDataProviderTests {
@Test
void cache(CapturedOutput output) {
V1ConfigMap red = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("red").withNamespace(NAMESPACE).build())
.addToData("color", "red").build();
.withMetadata(new V1ObjectMetaBuilder().withName("red").withNamespace(NAMESPACE).build())
.addToData("color", "red")
.build();
V1ConfigMap green = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("green").withNamespace(NAMESPACE).build())
.addToData("color", "green").build();
.withMetadata(new V1ObjectMetaBuilder().withName("green").withNamespace(NAMESPACE).build())
.addToData("color", "green")
.build();
V1ConfigMapList configMapList = new V1ConfigMapList().addItemsItem(red).addItemsItem(green);
@@ -442,7 +462,7 @@ class NamedConfigMapContextToSourceDataProviderTests {
private void stubCall(V1ConfigMapList list) {
stubFor(get("/api/v1/namespaces/default/configmaps")
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(list))));
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(list))));
}
}

View File

@@ -84,8 +84,9 @@ class NamedSecretContextToSourceDataProviderTests {
void singleSecretMatchAgainstLabels() {
V1Secret red = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withNamespace(NAMESPACE).withName("red").build())
.addToData(COLOR_REALLY_RED).build();
.withMetadata(new V1ObjectMetaBuilder().withNamespace(NAMESPACE).withName("red").build())
.addToData(COLOR_REALLY_RED)
.build();
V1SecretList secretList = new V1SecretList().addItemsItem(red);
stubCall(secretList);
CoreV1Api api = new CoreV1Api();
@@ -111,16 +112,19 @@ class NamedSecretContextToSourceDataProviderTests {
void twoSecretMatchAgainstLabels() {
V1Secret red = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withNamespace(NAMESPACE).withName("red").build())
.addToData(COLOR_REALLY_RED).build();
.withMetadata(new V1ObjectMetaBuilder().withNamespace(NAMESPACE).withName("red").build())
.addToData(COLOR_REALLY_RED)
.build();
V1Secret blue = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withNamespace(NAMESPACE).withName("blue").build())
.addToData(COLOR_REALLY_RED).build();
.withMetadata(new V1ObjectMetaBuilder().withNamespace(NAMESPACE).withName("blue").build())
.addToData(COLOR_REALLY_RED)
.build();
V1Secret pink = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withNamespace(NAMESPACE).withName("pink").build())
.addToData(COLOR_REALLY_RED).build();
.withMetadata(new V1ObjectMetaBuilder().withNamespace(NAMESPACE).withName("pink").build())
.addToData(COLOR_REALLY_RED)
.build();
V1SecretList secretList = new V1SecretListBuilder().addToItems(red).addToItems(blue).addToItems(pink).build();
@@ -148,8 +152,9 @@ class NamedSecretContextToSourceDataProviderTests {
void testSecretNoMatch() {
V1Secret secret = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withNamespace(NAMESPACE).withName("red").build())
.addToData(COLOR_REALLY_RED).build();
.withMetadata(new V1ObjectMetaBuilder().withNamespace(NAMESPACE).withName("red").build())
.addToData(COLOR_REALLY_RED)
.build();
V1SecretList secretList = new V1SecretList().addItemsItem(secret);
stubCall(secretList);
@@ -178,8 +183,9 @@ class NamedSecretContextToSourceDataProviderTests {
void namespaceMatch() {
V1Secret secret = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withNamespace(NAMESPACE).withName("red").build())
.addToData(COLOR_REALLY_RED).build();
.withMetadata(new V1ObjectMetaBuilder().withNamespace(NAMESPACE).withName("red").build())
.addToData(COLOR_REALLY_RED)
.build();
V1SecretList secretList = new V1SecretList().addItemsItem(secret);
stubCall(secretList);
@@ -205,12 +211,14 @@ class NamedSecretContextToSourceDataProviderTests {
void matchIncludeSingleProfile() {
V1Secret red = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withNamespace(NAMESPACE).withName("red").build())
.addToData(COLOR_REALLY_RED).build();
.withMetadata(new V1ObjectMetaBuilder().withNamespace(NAMESPACE).withName("red").build())
.addToData(COLOR_REALLY_RED)
.build();
V1Secret mango = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withNamespace(NAMESPACE).withName("red-with-profile").build())
.addToData("taste", "mango".getBytes()).build();
.withMetadata(new V1ObjectMetaBuilder().withNamespace(NAMESPACE).withName("red-with-profile").build())
.addToData("taste", "mango".getBytes())
.build();
V1SecretList secretList = new V1SecretList().addItemsItem(red).addItemsItem(mango);
@@ -243,12 +251,14 @@ class NamedSecretContextToSourceDataProviderTests {
void matchIncludeSingleProfileWithPrefix() {
V1Secret red = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withNamespace(NAMESPACE).withName("red").build())
.addToData(COLOR_REALLY_RED).build();
.withMetadata(new V1ObjectMetaBuilder().withNamespace(NAMESPACE).withName("red").build())
.addToData(COLOR_REALLY_RED)
.build();
V1Secret mango = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withNamespace(NAMESPACE).withName("red-with-taste").build())
.addToData("taste", "mango".getBytes()).build();
.withMetadata(new V1ObjectMetaBuilder().withNamespace(NAMESPACE).withName("red-with-taste").build())
.addToData("taste", "mango".getBytes())
.build();
V1SecretList secretList = new V1SecretList().addItemsItem(red).addItemsItem(mango);
@@ -280,16 +290,19 @@ class NamedSecretContextToSourceDataProviderTests {
void matchIncludeTwoProfilesWithPrefix() {
V1Secret red = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withNamespace(NAMESPACE).withName("red").build())
.addToData(COLOR_REALLY_RED).build();
.withMetadata(new V1ObjectMetaBuilder().withNamespace(NAMESPACE).withName("red").build())
.addToData(COLOR_REALLY_RED)
.build();
V1Secret mango = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withNamespace(NAMESPACE).withName("red-with-taste").build())
.addToData("taste", "mango".getBytes()).build();
.withMetadata(new V1ObjectMetaBuilder().withNamespace(NAMESPACE).withName("red-with-taste").build())
.addToData("taste", "mango".getBytes())
.build();
V1Secret shape = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withNamespace(NAMESPACE).withName("red-with-shape").build())
.addToData("shape", "round".getBytes()).build();
.withMetadata(new V1ObjectMetaBuilder().withNamespace(NAMESPACE).withName("red-with-shape").build())
.addToData("shape", "round".getBytes())
.build();
V1SecretList secretList = new V1SecretList().addItemsItem(red).addItemsItem(mango).addItemsItem(shape);
@@ -321,8 +334,9 @@ class NamedSecretContextToSourceDataProviderTests {
@Test
void testSingleYaml() {
V1Secret singleYaml = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("single-yaml").withNamespace(NAMESPACE).build())
.addToData("single.yaml", "key: value".getBytes()).build();
.withMetadata(new V1ObjectMetaBuilder().withName("single-yaml").withNamespace(NAMESPACE).build())
.addToData("single.yaml", "key: value".getBytes())
.build();
V1SecretList secretList = new V1SecretList().addItemsItem(singleYaml);
stubCall(secretList);
@@ -351,12 +365,14 @@ class NamedSecretContextToSourceDataProviderTests {
@Test
void cache(CapturedOutput output) {
V1Secret red = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("red").withNamespace(NAMESPACE).build())
.addToData("color", "red".getBytes()).build();
.withMetadata(new V1ObjectMetaBuilder().withName("red").withNamespace(NAMESPACE).build())
.addToData("color", "red".getBytes())
.build();
V1Secret green = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("green").withNamespace(NAMESPACE).build())
.addToData("color", "green".getBytes()).build();
.withMetadata(new V1ObjectMetaBuilder().withName("green").withNamespace(NAMESPACE).build())
.addToData("color", "green".getBytes())
.build();
V1SecretList configMapList = new V1SecretList().addItemsItem(red).addItemsItem(green);
@@ -396,7 +412,7 @@ class NamedSecretContextToSourceDataProviderTests {
private void stubCall(V1SecretList list) {
stubFor(get("/api/v1/namespaces/default/secrets")
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(list))));
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(list))));
}
}

View File

@@ -50,10 +50,10 @@ class LabeledConfigMapWithPrefixConfigDataTests extends LabeledConfigMapWithPref
WireMock.configureFor("localhost", server.port());
clientUtilsMock = mockStatic(KubernetesClientUtils.class);
clientUtilsMock.when(KubernetesClientUtils::kubernetesApiClient)
.thenReturn(new ClientBuilder().setBasePath(server.baseUrl()).build());
.thenReturn(new ClientBuilder().setBasePath(server.baseUrl()).build());
clientUtilsMock
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn("spring-k8s");
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn("spring-k8s");
stubData();
}

View File

@@ -57,8 +57,13 @@ abstract class LabeledConfigMapWithPrefixTests {
*/
@Test
void testOne() {
this.webClient.get().uri("/labeled-configmap/prefix/one").exchange().expectStatus().isOk()
.expectBody(String.class).value(Matchers.equalTo("one"));
this.webClient.get()
.uri("/labeled-configmap/prefix/one")
.exchange()
.expectStatus()
.isOk()
.expectBody(String.class)
.value(Matchers.equalTo("one"));
}
/**
@@ -72,8 +77,13 @@ abstract class LabeledConfigMapWithPrefixTests {
*/
@Test
void testTwo() {
this.webClient.get().uri("/labeled-configmap/prefix/two").exchange().expectStatus().isOk()
.expectBody(String.class).value(Matchers.equalTo("two"));
this.webClient.get()
.uri("/labeled-configmap/prefix/two")
.exchange()
.expectStatus()
.isOk()
.expectBody(String.class)
.value(Matchers.equalTo("two"));
}
/**
@@ -89,8 +99,13 @@ abstract class LabeledConfigMapWithPrefixTests {
*/
@Test
void testThree() {
this.webClient.get().uri("/labeled-configmap/prefix/three").exchange().expectStatus().isOk()
.expectBody(String.class).value(Matchers.equalTo("three"));
this.webClient.get()
.uri("/labeled-configmap/prefix/three")
.exchange()
.expectStatus()
.isOk()
.expectBody(String.class)
.value(Matchers.equalTo("three"));
}
/**
@@ -106,8 +121,13 @@ abstract class LabeledConfigMapWithPrefixTests {
*/
@Test
void testFour() {
this.webClient.get().uri("/labeled-configmap/prefix/four").exchange().expectStatus().isOk()
.expectBody(String.class).value(Matchers.equalTo("four"));
this.webClient.get()
.uri("/labeled-configmap/prefix/four")
.exchange()
.expectStatus()
.isOk()
.expectBody(String.class)
.value(Matchers.equalTo("four"));
}
}

View File

@@ -52,10 +52,10 @@ class LabeledConfigMapWithProfileConfigDataTests extends LabeledConfigMapWithPro
WireMock.configureFor("localhost", server.port());
clientUtilsMock = mockStatic(KubernetesClientUtils.class);
clientUtilsMock.when(KubernetesClientUtils::kubernetesApiClient)
.thenReturn(new ClientBuilder().setBasePath(server.baseUrl()).build());
.thenReturn(new ClientBuilder().setBasePath(server.baseUrl()).build());
clientUtilsMock
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn("spring-k8s");
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn("spring-k8s");
stubData();
}

View File

@@ -55,8 +55,13 @@ abstract class LabeledConfigMapWithProfileTests {
*/
@Test
void testBlue() {
this.webClient.get().uri("/labeled-configmap/profile/blue").exchange().expectStatus().isOk()
.expectBody(String.class).value(Matchers.equalTo("1"));
this.webClient.get()
.uri("/labeled-configmap/profile/blue")
.exchange()
.expectStatus()
.isOk()
.expectBody(String.class)
.value(Matchers.equalTo("1"));
}
/**
@@ -69,8 +74,13 @@ abstract class LabeledConfigMapWithProfileTests {
*/
@Test
void testGreen() {
this.webClient.get().uri("/labeled-configmap/profile/green").exchange().expectStatus().isOk()
.expectBody(String.class).value(Matchers.equalTo("2#6#7#eight-ish"));
this.webClient.get()
.uri("/labeled-configmap/profile/green")
.exchange()
.expectStatus()
.isOk()
.expectBody(String.class)
.value(Matchers.equalTo("2#6#7#eight-ish"));
}
}

View File

@@ -49,10 +49,10 @@ class LabeledSecretWithPrefixConfigDataTests extends LabeledSecretWithPrefixTest
WireMock.configureFor("localhost", server.port());
clientUtilsMock = mockStatic(KubernetesClientUtils.class);
clientUtilsMock.when(KubernetesClientUtils::kubernetesApiClient)
.thenReturn(new ClientBuilder().setBasePath(server.baseUrl()).build());
.thenReturn(new ClientBuilder().setBasePath(server.baseUrl()).build());
clientUtilsMock
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn("spring-k8s");
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn("spring-k8s");
stubData();
}

View File

@@ -57,8 +57,13 @@ abstract class LabeledSecretWithPrefixTests {
*/
@Test
void testOne() {
this.webClient.get().uri("/labeled-secret/prefix/one").exchange().expectStatus().isOk().expectBody(String.class)
.value(Matchers.equalTo("one"));
this.webClient.get()
.uri("/labeled-secret/prefix/one")
.exchange()
.expectStatus()
.isOk()
.expectBody(String.class)
.value(Matchers.equalTo("one"));
}
/**
@@ -72,8 +77,13 @@ abstract class LabeledSecretWithPrefixTests {
*/
@Test
void testTwo() {
this.webClient.get().uri("/labeled-secret/prefix/two").exchange().expectStatus().isOk().expectBody(String.class)
.value(Matchers.equalTo("two"));
this.webClient.get()
.uri("/labeled-secret/prefix/two")
.exchange()
.expectStatus()
.isOk()
.expectBody(String.class)
.value(Matchers.equalTo("two"));
}
/**
@@ -89,8 +99,13 @@ abstract class LabeledSecretWithPrefixTests {
*/
@Test
void testThree() {
this.webClient.get().uri("/labeled-secret/prefix/three").exchange().expectStatus().isOk()
.expectBody(String.class).value(Matchers.equalTo("three"));
this.webClient.get()
.uri("/labeled-secret/prefix/three")
.exchange()
.expectStatus()
.isOk()
.expectBody(String.class)
.value(Matchers.equalTo("three"));
}
/**
@@ -106,8 +121,13 @@ abstract class LabeledSecretWithPrefixTests {
*/
@Test
void testFour() {
this.webClient.get().uri("/labeled-secret/prefix/four").exchange().expectStatus().isOk()
.expectBody(String.class).value(Matchers.equalTo("four"));
this.webClient.get()
.uri("/labeled-secret/prefix/four")
.exchange()
.expectStatus()
.isOk()
.expectBody(String.class)
.value(Matchers.equalTo("four"));
}
}

View File

@@ -51,10 +51,10 @@ class LabeledSecretWithProfileConfigDataTests extends LabeledSecretWithProfileTe
WireMock.configureFor("localhost", server.port());
clientUtilsMock = mockStatic(KubernetesClientUtils.class);
clientUtilsMock.when(KubernetesClientUtils::kubernetesApiClient)
.thenReturn(new ClientBuilder().setBasePath(server.baseUrl()).build());
.thenReturn(new ClientBuilder().setBasePath(server.baseUrl()).build());
clientUtilsMock
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn("spring-k8s");
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn("spring-k8s");
stubData();
}

View File

@@ -67,8 +67,13 @@ abstract class LabeledSecretWithProfileTests {
*/
@Test
void testBlue() {
this.webClient.get().uri("/labeled-secret/profile/blue").exchange().expectStatus().isOk()
.expectBody(String.class).value(Matchers.equalTo("1"));
this.webClient.get()
.uri("/labeled-secret/profile/blue")
.exchange()
.expectStatus()
.isOk()
.expectBody(String.class)
.value(Matchers.equalTo("1"));
}
/**
@@ -81,8 +86,13 @@ abstract class LabeledSecretWithProfileTests {
*/
@Test
void testGreen() {
this.webClient.get().uri("/labeled-secret/profile/green").exchange().expectStatus().isOk()
.expectBody(String.class).value(Matchers.equalTo("2#6#7#eight-ish"));
this.webClient.get()
.uri("/labeled-secret/profile/green")
.exchange()
.expectStatus()
.isOk()
.expectBody(String.class)
.value(Matchers.equalTo("2#6#7#eight-ish"));
}
}

View File

@@ -49,10 +49,10 @@ class NamedConfigMapWithPrefixConfigDataTests extends NamedConfigMapWithPrefixTe
WireMock.configureFor("localhost", server.port());
clientUtilsMock = mockStatic(KubernetesClientUtils.class);
clientUtilsMock.when(KubernetesClientUtils::kubernetesApiClient)
.thenReturn(new ClientBuilder().setBasePath(server.baseUrl()).build());
.thenReturn(new ClientBuilder().setBasePath(server.baseUrl()).build());
clientUtilsMock
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn("spring-k8s");
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn("spring-k8s");
stubData();
}

View File

@@ -57,8 +57,13 @@ abstract class NamedConfigMapWithPrefixTests {
*/
@Test
void testOne() {
this.webClient.get().uri("/named-configmap/prefix/one").exchange().expectStatus().isOk()
.expectBody(String.class).value(Matchers.equalTo("one"));
this.webClient.get()
.uri("/named-configmap/prefix/one")
.exchange()
.expectStatus()
.isOk()
.expectBody(String.class)
.value(Matchers.equalTo("one"));
}
/**
@@ -72,8 +77,13 @@ abstract class NamedConfigMapWithPrefixTests {
*/
@Test
void testTwo() {
this.webClient.get().uri("/named-configmap/prefix/two").exchange().expectStatus().isOk()
.expectBody(String.class).value(Matchers.equalTo("two"));
this.webClient.get()
.uri("/named-configmap/prefix/two")
.exchange()
.expectStatus()
.isOk()
.expectBody(String.class)
.value(Matchers.equalTo("two"));
}
/**
@@ -87,8 +97,13 @@ abstract class NamedConfigMapWithPrefixTests {
*/
@Test
void testThree() {
this.webClient.get().uri("/named-configmap/prefix/three").exchange().expectStatus().isOk()
.expectBody(String.class).value(Matchers.equalTo("three"));
this.webClient.get()
.uri("/named-configmap/prefix/three")
.exchange()
.expectStatus()
.isOk()
.expectBody(String.class)
.value(Matchers.equalTo("three"));
}
}

View File

@@ -52,10 +52,10 @@ class NamedConfigMapWithProfileConfigDataTests extends NamedConfigMapWithProfile
WireMock.configureFor("localhost", server.port());
clientUtilsMock = mockStatic(KubernetesClientUtils.class);
clientUtilsMock.when(KubernetesClientUtils::kubernetesApiClient)
.thenReturn(new ClientBuilder().setBasePath(server.baseUrl()).build());
.thenReturn(new ClientBuilder().setBasePath(server.baseUrl()).build());
clientUtilsMock
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn("spring-k8s");
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn("spring-k8s");
stubData();
}

View File

@@ -59,8 +59,13 @@ abstract class NamedConfigMapWithProfileTests {
*/
@Test
void testOne() {
this.webClient.get().uri("/named-configmap/profile/one").exchange().expectStatus().isOk()
.expectBody(String.class).value(Matchers.equalTo("one-from-k8s"));
this.webClient.get()
.uri("/named-configmap/profile/one")
.exchange()
.expectStatus()
.isOk()
.expectBody(String.class)
.value(Matchers.equalTo("one-from-k8s"));
}
/**
@@ -77,8 +82,13 @@ abstract class NamedConfigMapWithProfileTests {
*/
@Test
void testTwo() {
this.webClient.get().uri("/named-configmap/profile/two").exchange().expectStatus().isOk()
.expectBody(String.class).value(Matchers.equalTo("two"));
this.webClient.get()
.uri("/named-configmap/profile/two")
.exchange()
.expectStatus()
.isOk()
.expectBody(String.class)
.value(Matchers.equalTo("two"));
}
/**
@@ -94,8 +104,13 @@ abstract class NamedConfigMapWithProfileTests {
*/
@Test
void testThree() {
this.webClient.get().uri("/named-configmap/profile/three").exchange().expectStatus().isOk()
.expectBody(String.class).value(Matchers.equalTo("three-from-k8s"));
this.webClient.get()
.uri("/named-configmap/profile/three")
.exchange()
.expectStatus()
.isOk()
.expectBody(String.class)
.value(Matchers.equalTo("three-from-k8s"));
}
}

View File

@@ -50,10 +50,10 @@ class NamedSecretWithPrefixConfigDataTests extends NamedSecretWithPrefixTests {
WireMock.configureFor("localhost", server.port());
clientUtilsMock = mockStatic(KubernetesClientUtils.class);
clientUtilsMock.when(KubernetesClientUtils::kubernetesApiClient)
.thenReturn(new ClientBuilder().setBasePath(server.baseUrl()).build());
.thenReturn(new ClientBuilder().setBasePath(server.baseUrl()).build());
clientUtilsMock
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn("spring-k8s");
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn("spring-k8s");
stubData();
}

View File

@@ -57,8 +57,13 @@ abstract class NamedSecretWithPrefixTests {
*/
@Test
void testOne() {
this.webClient.get().uri("/named-secret/prefix/one").exchange().expectStatus().isOk().expectBody(String.class)
.value(Matchers.equalTo("one"));
this.webClient.get()
.uri("/named-secret/prefix/one")
.exchange()
.expectStatus()
.isOk()
.expectBody(String.class)
.value(Matchers.equalTo("one"));
}
/**
@@ -72,8 +77,13 @@ abstract class NamedSecretWithPrefixTests {
*/
@Test
void testTwo() {
this.webClient.get().uri("/named-secret/prefix/two").exchange().expectStatus().isOk().expectBody(String.class)
.value(Matchers.equalTo("two"));
this.webClient.get()
.uri("/named-secret/prefix/two")
.exchange()
.expectStatus()
.isOk()
.expectBody(String.class)
.value(Matchers.equalTo("two"));
}
/**
@@ -87,8 +97,13 @@ abstract class NamedSecretWithPrefixTests {
*/
@Test
void testThree() {
this.webClient.get().uri("/named-secret/prefix/three").exchange().expectStatus().isOk().expectBody(String.class)
.value(Matchers.equalTo("three"));
this.webClient.get()
.uri("/named-secret/prefix/three")
.exchange()
.expectStatus()
.isOk()
.expectBody(String.class)
.value(Matchers.equalTo("three"));
}
}

View File

@@ -52,10 +52,10 @@ class NamedSecretWithProfileConfigDataTests extends NamedSecretWithProfileTests
WireMock.configureFor("localhost", server.port());
clientUtilsMock = mockStatic(KubernetesClientUtils.class);
clientUtilsMock.when(KubernetesClientUtils::kubernetesApiClient)
.thenReturn(new ClientBuilder().setBasePath(server.baseUrl()).build());
.thenReturn(new ClientBuilder().setBasePath(server.baseUrl()).build());
clientUtilsMock
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn("spring-k8s");
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn("spring-k8s");
stubData();
}

View File

@@ -59,8 +59,13 @@ abstract class NamedSecretWithProfileTests {
*/
@Test
void testOne() {
this.webClient.get().uri("/named-secret/profile/one").exchange().expectStatus().isOk().expectBody(String.class)
.value(Matchers.equalTo("one-from-k8s"));
this.webClient.get()
.uri("/named-secret/profile/one")
.exchange()
.expectStatus()
.isOk()
.expectBody(String.class)
.value(Matchers.equalTo("one-from-k8s"));
}
/**
@@ -77,8 +82,13 @@ abstract class NamedSecretWithProfileTests {
*/
@Test
void testTwo() {
this.webClient.get().uri("/named-secret/profile/two").exchange().expectStatus().isOk().expectBody(String.class)
.value(Matchers.equalTo("two"));
this.webClient.get()
.uri("/named-secret/profile/two")
.exchange()
.expectStatus()
.isOk()
.expectBody(String.class)
.value(Matchers.equalTo("two"));
}
/**
@@ -94,8 +104,13 @@ abstract class NamedSecretWithProfileTests {
*/
@Test
void testThree() {
this.webClient.get().uri("/named-secret/profile/three").exchange().expectStatus().isOk()
.expectBody(String.class).value(Matchers.equalTo("three-from-k8s"));
this.webClient.get()
.uri("/named-secret/profile/three")
.exchange()
.expectStatus()
.isOk()
.expectBody(String.class)
.value(Matchers.equalTo("three-from-k8s"));
}
}

View File

@@ -50,10 +50,10 @@ class SingleSourceMultipleFilesConfigDataTests extends SingleSourceMultipleFiles
WireMock.configureFor("localhost", server.port());
clientUtilsMock = mockStatic(KubernetesClientUtils.class);
clientUtilsMock.when(KubernetesClientUtils::kubernetesApiClient)
.thenReturn(new ClientBuilder().setBasePath(server.baseUrl()).build());
.thenReturn(new ClientBuilder().setBasePath(server.baseUrl()).build());
clientUtilsMock
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn("spring-k8s");
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn("spring-k8s");
stubData();
}

View File

@@ -57,8 +57,13 @@ abstract class SingleSourceMultipleFilesTests {
*/
@Test
void color() {
this.webClient.get().uri("/single_source-multiple-files/color").exchange().expectStatus().isOk()
.expectBody(String.class).value(Matchers.equalTo("raw:green###ripe:yellow"));
this.webClient.get()
.uri("/single_source-multiple-files/color")
.exchange()
.expectStatus()
.isOk()
.expectBody(String.class)
.value(Matchers.equalTo("raw:green###ripe:yellow"));
}
/**
@@ -68,8 +73,13 @@ abstract class SingleSourceMultipleFilesTests {
*/
@Test
void name() {
this.webClient.get().uri("/single_source-multiple-files/name").exchange().expectStatus().isOk()
.expectBody(String.class).value(Matchers.equalTo("banana"));
this.webClient.get()
.uri("/single_source-multiple-files/name")
.exchange()
.expectStatus()
.isOk()
.expectBody(String.class)
.value(Matchers.equalTo("banana"));
}
/**
@@ -80,8 +90,13 @@ abstract class SingleSourceMultipleFilesTests {
*/
@Test
void shape() {
this.webClient.get().uri("/single_source-multiple-files/shape").exchange().expectStatus().isOk()
.expectBody(String.class).value(Matchers.nullValue());
this.webClient.get()
.uri("/single_source-multiple-files/shape")
.exchange()
.expectStatus()
.isOk()
.expectBody(String.class)
.value(Matchers.nullValue());
}
/**
@@ -91,8 +106,13 @@ abstract class SingleSourceMultipleFilesTests {
*/
@Test
void type() {
this.webClient.get().uri("/single_source-multiple-files/type").exchange().expectStatus().isOk()
.expectBody(String.class).value(Matchers.equalTo("yummy"));
this.webClient.get()
.uri("/single_source-multiple-files/type")
.exchange()
.expectStatus()
.isOk()
.expectBody(String.class)
.value(Matchers.equalTo("yummy"));
}
}

View File

@@ -57,10 +57,10 @@ class ConfigDataRetryableSourcesOrderTests extends SourcesOrderTests {
WireMock.configureFor("localhost", server.port());
clientUtilsMock = mockStatic(KubernetesClientUtils.class);
clientUtilsMock.when(KubernetesClientUtils::kubernetesApiClient)
.thenReturn(new ClientBuilder().setBasePath(server.baseUrl()).build());
.thenReturn(new ClientBuilder().setBasePath(server.baseUrl()).build());
clientUtilsMock
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn("spring-k8s");
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn("spring-k8s");
stubConfigMapData();
stubSecretsData();
}

View File

@@ -51,10 +51,10 @@ class ConfigDataSourcesOrderTests extends SourcesOrderTests {
WireMock.configureFor("localhost", server.port());
clientUtilsMock = mockStatic(KubernetesClientUtils.class);
clientUtilsMock.when(KubernetesClientUtils::kubernetesApiClient)
.thenReturn(new ClientBuilder().setBasePath(server.baseUrl()).build());
.thenReturn(new ClientBuilder().setBasePath(server.baseUrl()).build());
clientUtilsMock
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn("spring-k8s");
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn("spring-k8s");
stubConfigMapData();
stubSecretsData();
}

View File

@@ -67,13 +67,28 @@ abstract class SourcesOrderTests {
*/
@Test
void test() {
this.webClient.get().uri("/one").exchange().expectStatus().isOk().expectBody(String.class)
.value(Matchers.equalTo("one"));
this.webClient.get().uri("/two").exchange().expectStatus().isOk().expectBody(String.class)
.value(Matchers.equalTo("two"));
this.webClient.get()
.uri("/one")
.exchange()
.expectStatus()
.isOk()
.expectBody(String.class)
.value(Matchers.equalTo("one"));
this.webClient.get()
.uri("/two")
.exchange()
.expectStatus()
.isOk()
.expectBody(String.class)
.value(Matchers.equalTo("two"));
this.webClient.get().uri("/key").exchange().expectStatus().isOk().expectBody(String.class)
.value(Matchers.equalTo("from-configmap"));
this.webClient.get()
.uri("/key")
.exchange()
.expectStatus()
.isOk()
.expectBody(String.class)
.value(Matchers.equalTo("from-configmap"));
}
}

View File

@@ -69,16 +69,19 @@ public class BootstrapKubernetesClientSanitizeEnvEndpointStub {
public static void stubData() {
V1ConfigMap one = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("sanitize-configmap").withNamespace("test").build())
.addToData(Map.of("sanitize.sanitizeConfigMapName", "sanitizeConfigMapValue")).build();
.withMetadata(new V1ObjectMetaBuilder().withName("sanitize-configmap").withNamespace("test").build())
.addToData(Map.of("sanitize.sanitizeConfigMapName", "sanitizeConfigMapValue"))
.build();
V1Secret secretOne = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("sanitize-secret").withNamespace("test").build())
.addToData(Map.of("sanitize.sanitizeSecretName", "sanitizeSecretValue".getBytes())).build();
.withMetadata(new V1ObjectMetaBuilder().withName("sanitize-secret").withNamespace("test").build())
.addToData(Map.of("sanitize.sanitizeSecretName", "sanitizeSecretValue".getBytes()))
.build();
V1Secret secretTwo = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("sanitize-secret-two").withNamespace("test").build())
.addToData(Map.of("sanitize.sanitizeSecretNameTwo", "sanitizeSecretValueTwo".getBytes())).build();
.withMetadata(new V1ObjectMetaBuilder().withName("sanitize-secret-two").withNamespace("test").build())
.addToData(Map.of("sanitize.sanitizeSecretNameTwo", "sanitizeSecretValueTwo".getBytes()))
.build();
// the actual stub for CoreV1Api calls
V1ConfigMapList configMapList = new V1ConfigMapList();
@@ -89,10 +92,10 @@ public class BootstrapKubernetesClientSanitizeEnvEndpointStub {
secretList.addItemsItem(secretTwo);
WireMock.stubFor(WireMock.get("/api/v1/namespaces/test/configmaps")
.willReturn(WireMock.aResponse().withStatus(200).withBody(new JSON().serialize(configMapList))));
.willReturn(WireMock.aResponse().withStatus(200).withBody(new JSON().serialize(configMapList))));
WireMock.stubFor(WireMock.get("/api/v1/namespaces/test/secrets")
.willReturn(WireMock.aResponse().withStatus(200).withBody(new JSON().serialize(secretList))));
.willReturn(WireMock.aResponse().withStatus(200).withBody(new JSON().serialize(secretList))));
}
}

View File

@@ -67,24 +67,36 @@ public class LabeledConfigMapWithPrefixConfigurationStub {
public static void stubData() {
V1ConfigMap one = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("configmap-one").withNamespace("spring-k8s")
.withLabels(Map.of("letter", "a")).build())
.addToData(Collections.singletonMap("one.property", "one")).build();
.withMetadata(new V1ObjectMetaBuilder().withName("configmap-one")
.withNamespace("spring-k8s")
.withLabels(Map.of("letter", "a"))
.build())
.addToData(Collections.singletonMap("one.property", "one"))
.build();
V1ConfigMap two = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("configmap-two").withNamespace("spring-k8s")
.withLabels(Map.of("letter", "b")).build())
.addToData(Collections.singletonMap("property", "two")).build();
.withMetadata(new V1ObjectMetaBuilder().withName("configmap-two")
.withNamespace("spring-k8s")
.withLabels(Map.of("letter", "b"))
.build())
.addToData(Collections.singletonMap("property", "two"))
.build();
V1ConfigMap three = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("configmap-three").withNamespace("spring-k8s")
.withLabels(Map.of("letter", "c")).build())
.addToData(Collections.singletonMap("property", "three")).build();
.withMetadata(new V1ObjectMetaBuilder().withName("configmap-three")
.withNamespace("spring-k8s")
.withLabels(Map.of("letter", "c"))
.build())
.addToData(Collections.singletonMap("property", "three"))
.build();
V1ConfigMap four = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("configmap-four").withNamespace("spring-k8s")
.withLabels(Map.of("letter", "d")).build())
.addToData(Collections.singletonMap("property", "four")).build();
.withMetadata(new V1ObjectMetaBuilder().withName("configmap-four")
.withNamespace("spring-k8s")
.withLabels(Map.of("letter", "d"))
.build())
.addToData(Collections.singletonMap("property", "four"))
.build();
// the actual stub for CoreV1Api calls
V1ConfigMapList configMapList = new V1ConfigMapList();
@@ -94,7 +106,7 @@ public class LabeledConfigMapWithPrefixConfigurationStub {
configMapList.addItemsItem(four);
WireMock.stubFor(WireMock.get("/api/v1/namespaces/spring-k8s/configmaps")
.willReturn(WireMock.aResponse().withStatus(200).withBody(new JSON().serialize(configMapList))));
.willReturn(WireMock.aResponse().withStatus(200).withBody(new JSON().serialize(configMapList))));
}
}

View File

@@ -84,56 +84,83 @@ public class LabeledConfigMapWithProfileConfigurationStub {
// is found by labels
V1ConfigMap colorConfigMap = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("color-configmap").withNamespace("spring-k8s")
.withLabels(Map.of("color", "blue")).build())
.addToData(Collections.singletonMap("one", "1")).build();
.withMetadata(new V1ObjectMetaBuilder().withName("color-configmap")
.withNamespace("spring-k8s")
.withLabels(Map.of("color", "blue"))
.build())
.addToData(Collections.singletonMap("one", "1"))
.build();
// is not taken, since "profileSpecificSources=false" for the above
V1ConfigMap colorConfigMapK8s = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("color-configmap-k8s").withNamespace("spring-k8s")
.withLabels(Map.of("color", "not-blue")).build())
.addToData(Collections.singletonMap("five", "5")).build();
.withMetadata(new V1ObjectMetaBuilder().withName("color-configmap-k8s")
.withNamespace("spring-k8s")
.withLabels(Map.of("color", "not-blue"))
.build())
.addToData(Collections.singletonMap("five", "5"))
.build();
// is found by labels
V1ConfigMap greenConfigMap = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("green-configmap").withNamespace("spring-k8s")
.withLabels(Map.of("color", "green")).build())
.addToData(Collections.singletonMap("two", "2")).build();
.withMetadata(new V1ObjectMetaBuilder().withName("green-configmap")
.withNamespace("spring-k8s")
.withLabels(Map.of("color", "green"))
.build())
.addToData(Collections.singletonMap("two", "2"))
.build();
V1ConfigMap greenConfigMapK8s = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("green-configmap-k8s").withNamespace("spring-k8s")
.withLabels(Map.of("color", "green-k8s")).build())
.addToData(Collections.singletonMap("six", "6")).build();
.withMetadata(new V1ObjectMetaBuilder().withName("green-configmap-k8s")
.withNamespace("spring-k8s")
.withLabels(Map.of("color", "green-k8s"))
.build())
.addToData(Collections.singletonMap("six", "6"))
.build();
// is taken because prod profile is active and "profileSpecificSources=true"
V1ConfigMap greenConfigMapProd = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("green-configmap-prod").withNamespace("spring-k8s")
.withLabels(Map.of("color", "green-prod")).build())
.addToData(Collections.singletonMap("seven", "7")).build();
.withMetadata(new V1ObjectMetaBuilder().withName("green-configmap-prod")
.withNamespace("spring-k8s")
.withLabels(Map.of("color", "green-prod"))
.build())
.addToData(Collections.singletonMap("seven", "7"))
.build();
// not taken
V1ConfigMap redConfigMap = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("red-configmap").withNamespace("spring-k8s")
.withLabels(Map.of("color", "red")).build())
.addToData(Collections.singletonMap("three", "3")).build();
.withMetadata(new V1ObjectMetaBuilder().withName("red-configmap")
.withNamespace("spring-k8s")
.withLabels(Map.of("color", "red"))
.build())
.addToData(Collections.singletonMap("three", "3"))
.build();
// not taken
V1ConfigMap yellowConfigMap = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("yellow-configmap").withNamespace("spring-k8s")
.withLabels(Map.of("color", "yellow")).build())
.addToData(Collections.singletonMap("four", "4")).build();
.withMetadata(new V1ObjectMetaBuilder().withName("yellow-configmap")
.withNamespace("spring-k8s")
.withLabels(Map.of("color", "yellow"))
.build())
.addToData(Collections.singletonMap("four", "4"))
.build();
// is found by labels
V1ConfigMap greenPurpleConfigMap = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("green-purple-configmap").withNamespace("spring-k8s")
.withLabels(Map.of("color", "green", "shape", "round")).build())
.addToData(Collections.singletonMap("eight", "8")).build();
.withMetadata(new V1ObjectMetaBuilder().withName("green-purple-configmap")
.withNamespace("spring-k8s")
.withLabels(Map.of("color", "green", "shape", "round"))
.build())
.addToData(Collections.singletonMap("eight", "8"))
.build();
// is taken and thus overrides the above
V1ConfigMap greenPurpleConfigMapK8s = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("green-purple-configmap-k8s")
.withNamespace("spring-k8s").withLabels(Map.of("color", "black")).build())
.addToData(Collections.singletonMap("eight", "eight-ish")).build();
.withMetadata(new V1ObjectMetaBuilder().withName("green-purple-configmap-k8s")
.withNamespace("spring-k8s")
.withLabels(Map.of("color", "black"))
.build())
.addToData(Collections.singletonMap("eight", "eight-ish"))
.build();
// the actual stub for CoreV1Api calls
V1ConfigMapList configMaps = new V1ConfigMapList();
@@ -148,7 +175,7 @@ public class LabeledConfigMapWithProfileConfigurationStub {
configMaps.addItemsItem(greenPurpleConfigMapK8s);
WireMock.stubFor(WireMock.get("/api/v1/namespaces/spring-k8s/configmaps")
.willReturn(WireMock.aResponse().withStatus(200).withBody(new JSON().serialize(configMaps))));
.willReturn(WireMock.aResponse().withStatus(200).withBody(new JSON().serialize(configMaps))));
}
}

View File

@@ -66,24 +66,40 @@ public class LabeledSecretWithPrefixConfigurationStub {
public static void stubData() {
V1Secret one = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("secret-one").withNamespace("spring-k8s")
.withLabels(Map.of("letter", "a")).withResourceVersion("1").build())
.addToData(Collections.singletonMap("one.property", "one".getBytes())).build();
.withMetadata(new V1ObjectMetaBuilder().withName("secret-one")
.withNamespace("spring-k8s")
.withLabels(Map.of("letter", "a"))
.withResourceVersion("1")
.build())
.addToData(Collections.singletonMap("one.property", "one".getBytes()))
.build();
V1Secret two = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("secret-two").withNamespace("spring-k8s")
.withLabels(Map.of("letter", "b")).withResourceVersion("1").build())
.addToData(Collections.singletonMap("property", "two".getBytes())).build();
.withMetadata(new V1ObjectMetaBuilder().withName("secret-two")
.withNamespace("spring-k8s")
.withLabels(Map.of("letter", "b"))
.withResourceVersion("1")
.build())
.addToData(Collections.singletonMap("property", "two".getBytes()))
.build();
V1Secret three = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("secret-three").withNamespace("spring-k8s")
.withLabels(Map.of("letter", "c")).withResourceVersion("1").build())
.addToData(Collections.singletonMap("property", "three".getBytes())).build();
.withMetadata(new V1ObjectMetaBuilder().withName("secret-three")
.withNamespace("spring-k8s")
.withLabels(Map.of("letter", "c"))
.withResourceVersion("1")
.build())
.addToData(Collections.singletonMap("property", "three".getBytes()))
.build();
V1Secret four = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("secret-four").withNamespace("spring-k8s")
.withLabels(Map.of("letter", "d")).withResourceVersion("1").build())
.addToData(Collections.singletonMap("property", "four".getBytes())).build();
.withMetadata(new V1ObjectMetaBuilder().withName("secret-four")
.withNamespace("spring-k8s")
.withLabels(Map.of("letter", "d"))
.withResourceVersion("1")
.build())
.addToData(Collections.singletonMap("property", "four".getBytes()))
.build();
// the actual stub for CoreV1Api calls
V1SecretList secrets = new V1SecretList();
@@ -93,7 +109,7 @@ public class LabeledSecretWithPrefixConfigurationStub {
secrets.addItemsItem(four);
WireMock.stubFor(WireMock.get("/api/v1/namespaces/spring-k8s/secrets")
.willReturn(WireMock.aResponse().withStatus(200).withBody(new JSON().serialize(secrets))));
.willReturn(WireMock.aResponse().withStatus(200).withBody(new JSON().serialize(secrets))));
}
}

View File

@@ -85,56 +85,83 @@ public class LabeledSecretWithProfileConfigurationStub {
// is found by labels
V1Secret colorSecret = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("color-secret").withNamespace("spring-k8s")
.withLabels(Map.of("color", "blue")).build())
.addToData(Collections.singletonMap("one", "1".getBytes(StandardCharsets.UTF_8))).build();
.withMetadata(new V1ObjectMetaBuilder().withName("color-secret")
.withNamespace("spring-k8s")
.withLabels(Map.of("color", "blue"))
.build())
.addToData(Collections.singletonMap("one", "1".getBytes(StandardCharsets.UTF_8)))
.build();
// is not taken, since "profileSpecificSources=false" for the above
V1Secret colorSecretK8s = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("color-secret-k8s").withNamespace("spring-k8s")
.withLabels(Map.of("color", "not-blue")).build())
.addToData(Collections.singletonMap("five", "5".getBytes(StandardCharsets.UTF_8))).build();
.withMetadata(new V1ObjectMetaBuilder().withName("color-secret-k8s")
.withNamespace("spring-k8s")
.withLabels(Map.of("color", "not-blue"))
.build())
.addToData(Collections.singletonMap("five", "5".getBytes(StandardCharsets.UTF_8)))
.build();
// is found by labels
V1Secret greenSecret = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("green-secret").withNamespace("spring-k8s")
.withLabels(Map.of("color", "green")).build())
.addToData(Collections.singletonMap("two", "2".getBytes(StandardCharsets.UTF_8))).build();
.withMetadata(new V1ObjectMetaBuilder().withName("green-secret")
.withNamespace("spring-k8s")
.withLabels(Map.of("color", "green"))
.build())
.addToData(Collections.singletonMap("two", "2".getBytes(StandardCharsets.UTF_8)))
.build();
V1Secret greenSecretK8s = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("green-secret-k8s").withNamespace("spring-k8s")
.withLabels(Map.of("color", "green-k8s")).build())
.addToData(Collections.singletonMap("six", "6".getBytes(StandardCharsets.UTF_8))).build();
.withMetadata(new V1ObjectMetaBuilder().withName("green-secret-k8s")
.withNamespace("spring-k8s")
.withLabels(Map.of("color", "green-k8s"))
.build())
.addToData(Collections.singletonMap("six", "6".getBytes(StandardCharsets.UTF_8)))
.build();
// is taken because prod profile is active and "profileSpecificSources=true"
V1Secret shapeSecretProd = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("green-secret-prod").withNamespace("spring-k8s")
.withLabels(Map.of("color", "green-prod")).build())
.addToData(Collections.singletonMap("seven", "7".getBytes(StandardCharsets.UTF_8))).build();
.withMetadata(new V1ObjectMetaBuilder().withName("green-secret-prod")
.withNamespace("spring-k8s")
.withLabels(Map.of("color", "green-prod"))
.build())
.addToData(Collections.singletonMap("seven", "7".getBytes(StandardCharsets.UTF_8)))
.build();
// not taken
V1Secret redSecret = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("red-secret").withNamespace("spring-k8s")
.withLabels(Map.of("color", "not-red")).build())
.addToData(Collections.singletonMap("three", "3".getBytes(StandardCharsets.UTF_8))).build();
.withMetadata(new V1ObjectMetaBuilder().withName("red-secret")
.withNamespace("spring-k8s")
.withLabels(Map.of("color", "not-red"))
.build())
.addToData(Collections.singletonMap("three", "3".getBytes(StandardCharsets.UTF_8)))
.build();
// not taken
V1Secret yellowSecret = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("yellow-secret").withNamespace("spring-k8s")
.withLabels(Map.of("color", "not-yellow")).build())
.addToData(Collections.singletonMap("four", "4".getBytes(StandardCharsets.UTF_8))).build();
.withMetadata(new V1ObjectMetaBuilder().withName("yellow-secret")
.withNamespace("spring-k8s")
.withLabels(Map.of("color", "not-yellow"))
.build())
.addToData(Collections.singletonMap("four", "4".getBytes(StandardCharsets.UTF_8)))
.build();
// is found by labels
V1Secret greenPurpleSecret = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("green-purple-secret").withNamespace("spring-k8s")
.withLabels(Map.of("color", "green", "shape", "round")).build())
.addToData(Collections.singletonMap("eight", "8".getBytes(StandardCharsets.UTF_8))).build();
.withMetadata(new V1ObjectMetaBuilder().withName("green-purple-secret")
.withNamespace("spring-k8s")
.withLabels(Map.of("color", "green", "shape", "round"))
.build())
.addToData(Collections.singletonMap("eight", "8".getBytes(StandardCharsets.UTF_8)))
.build();
// is taken and thus overrides the above
V1Secret greenPurpleSecretK8s = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("green-purple-secret-k8s").withNamespace("spring-k8s")
.withLabels(Map.of("color", "black")).build())
.addToData(Collections.singletonMap("eight", "eight-ish".getBytes(StandardCharsets.UTF_8))).build();
.withMetadata(new V1ObjectMetaBuilder().withName("green-purple-secret-k8s")
.withNamespace("spring-k8s")
.withLabels(Map.of("color", "black"))
.build())
.addToData(Collections.singletonMap("eight", "eight-ish".getBytes(StandardCharsets.UTF_8)))
.build();
// the actual stub for CoreV1Api calls
V1SecretList secrets = new V1SecretList();
@@ -149,7 +176,7 @@ public class LabeledSecretWithProfileConfigurationStub {
secrets.addItemsItem(greenPurpleSecretK8s);
WireMock.stubFor(WireMock.get("/api/v1/namespaces/spring-k8s/secrets")
.willReturn(WireMock.aResponse().withStatus(200).withBody(new JSON().serialize(secrets))));
.willReturn(WireMock.aResponse().withStatus(200).withBody(new JSON().serialize(secrets))));
}
}

View File

@@ -66,26 +66,35 @@ public class NamedConfigMapWithPrefixConfigurationStub {
public static void stubData() {
V1ConfigMap one = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("config-map-one").withNamespace("spring-k8s")
.withResourceVersion("1").build())
.addToData(Collections.singletonMap("one.property", "one")).build();
.withMetadata(new V1ObjectMetaBuilder().withName("config-map-one")
.withNamespace("spring-k8s")
.withResourceVersion("1")
.build())
.addToData(Collections.singletonMap("one.property", "one"))
.build();
V1ConfigMap two = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("config-map-two").withNamespace("spring-k8s")
.withResourceVersion("1").build())
.addToData(Collections.singletonMap("property", "two")).build();
.withMetadata(new V1ObjectMetaBuilder().withName("config-map-two")
.withNamespace("spring-k8s")
.withResourceVersion("1")
.build())
.addToData(Collections.singletonMap("property", "two"))
.build();
V1ConfigMap three = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("config-map-three").withNamespace("spring-k8s")
.withResourceVersion("1").build())
.addToData(Collections.singletonMap("property", "three")).build();
.withMetadata(new V1ObjectMetaBuilder().withName("config-map-three")
.withNamespace("spring-k8s")
.withResourceVersion("1")
.build())
.addToData(Collections.singletonMap("property", "three"))
.build();
V1ConfigMapList allConfigMaps = new V1ConfigMapList();
allConfigMaps.setItems(Arrays.asList(one, two, three));
// the actual stub for CoreV1Api calls
WireMock.stubFor(WireMock.get("/api/v1/namespaces/spring-k8s/configmaps")
.willReturn(WireMock.aResponse().withStatus(200).withBody(new JSON().serialize(allConfigMaps))));
.willReturn(WireMock.aResponse().withStatus(200).withBody(new JSON().serialize(allConfigMaps))));
}
}

View File

@@ -72,38 +72,41 @@ public class NamedConfigMapWithProfileConfigurationStub {
// overridden by the ones from "oneFromK8s".
// We have a test that asserts this.
V1ConfigMap one = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("configmap-one").withNamespace("spring-k8s").build())
.addToData(Collections.singletonMap("one.property", "one")).build();
.withMetadata(new V1ObjectMetaBuilder().withName("configmap-one").withNamespace("spring-k8s").build())
.addToData(Collections.singletonMap("one.property", "one"))
.build();
V1ConfigMap oneFromK8s = new V1ConfigMapBuilder()
.withMetadata(
new V1ObjectMetaBuilder().withName("configmap-one-k8s").withNamespace("spring-k8s").build())
.addToData(Collections.singletonMap("one.property", "one-from-k8s")).build();
.withMetadata(new V1ObjectMetaBuilder().withName("configmap-one-k8s").withNamespace("spring-k8s").build())
.addToData(Collections.singletonMap("one.property", "one-from-k8s"))
.build();
V1ConfigMap two = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("configmap-two").withNamespace("spring-k8s").build())
.addToData(Collections.singletonMap("property", "two")).build();
.withMetadata(new V1ObjectMetaBuilder().withName("configmap-two").withNamespace("spring-k8s").build())
.addToData(Collections.singletonMap("property", "two"))
.build();
V1ConfigMap twoFromK8s = new V1ConfigMapBuilder()
.withMetadata(
new V1ObjectMetaBuilder().withName("configmap-two-k8s").withNamespace("spring-k8s").build())
.addToData(Collections.singletonMap("property", "two-from-k8s")).build();
.withMetadata(new V1ObjectMetaBuilder().withName("configmap-two-k8s").withNamespace("spring-k8s").build())
.addToData(Collections.singletonMap("property", "two-from-k8s"))
.build();
V1ConfigMap three = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("configmap-three").withNamespace("spring-k8s").build())
.addToData(Collections.singletonMap("property", "three")).build();
.withMetadata(new V1ObjectMetaBuilder().withName("configmap-three").withNamespace("spring-k8s").build())
.addToData(Collections.singletonMap("property", "three"))
.build();
V1ConfigMap threeFromK8s = new V1ConfigMapBuilder()
.withMetadata(
new V1ObjectMetaBuilder().withName("configmap-three-k8s").withNamespace("spring-k8s").build())
.addToData(Collections.singletonMap("property", "three-from-k8s")).build();
.withMetadata(new V1ObjectMetaBuilder().withName("configmap-three-k8s").withNamespace("spring-k8s").build())
.addToData(Collections.singletonMap("property", "three-from-k8s"))
.build();
V1ConfigMapList allConfigMaps = new V1ConfigMapList();
allConfigMaps.setItems(Arrays.asList(one, oneFromK8s, two, twoFromK8s, three, threeFromK8s));
// the actual stub for CoreV1Api calls
WireMock.stubFor(WireMock.get("/api/v1/namespaces/spring-k8s/configmaps")
.willReturn(WireMock.aResponse().withStatus(200).withBody(new JSON().serialize(allConfigMaps))));
.willReturn(WireMock.aResponse().withStatus(200).withBody(new JSON().serialize(allConfigMaps))));
}
}

View File

@@ -65,26 +65,35 @@ public class NamedSecretWithPrefixConfigurationStub {
public static void stubData() {
V1Secret one = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("secret-one").withNamespace("spring-k8s")
.withResourceVersion("1").build())
.addToData(Collections.singletonMap("one.property", "one".getBytes())).build();
.withMetadata(new V1ObjectMetaBuilder().withName("secret-one")
.withNamespace("spring-k8s")
.withResourceVersion("1")
.build())
.addToData(Collections.singletonMap("one.property", "one".getBytes()))
.build();
V1Secret two = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("secret-two").withNamespace("spring-k8s")
.withResourceVersion("1").build())
.addToData(Collections.singletonMap("property", "two".getBytes())).build();
.withMetadata(new V1ObjectMetaBuilder().withName("secret-two")
.withNamespace("spring-k8s")
.withResourceVersion("1")
.build())
.addToData(Collections.singletonMap("property", "two".getBytes()))
.build();
V1Secret three = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("secret-three").withNamespace("spring-k8s")
.withResourceVersion("1").build())
.addToData(Collections.singletonMap("property", "three".getBytes())).build();
.withMetadata(new V1ObjectMetaBuilder().withName("secret-three")
.withNamespace("spring-k8s")
.withResourceVersion("1")
.build())
.addToData(Collections.singletonMap("property", "three".getBytes()))
.build();
V1SecretList allSecrets = new V1SecretList();
allSecrets.setItems(Arrays.asList(one, two, three));
// the actual stub for CoreV1Api calls
WireMock.stubFor(WireMock.get("/api/v1/namespaces/spring-k8s/secrets")
.willReturn(WireMock.aResponse().withStatus(200).withBody(new JSON().serialize(allSecrets))));
.willReturn(WireMock.aResponse().withStatus(200).withBody(new JSON().serialize(allSecrets))));
}
}

View File

@@ -71,41 +71,59 @@ public class NamedSecretWithProfileConfigurationStub {
// overridden by the ones from "oneWithProfile".
// We have a test that asserts this.
V1Secret one = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("secret-one").withNamespace("spring-k8s")
.withResourceVersion("1").build())
.addToData(Collections.singletonMap("one.property", "one".getBytes())).build();
.withMetadata(new V1ObjectMetaBuilder().withName("secret-one")
.withNamespace("spring-k8s")
.withResourceVersion("1")
.build())
.addToData(Collections.singletonMap("one.property", "one".getBytes()))
.build();
V1Secret oneWithProfile = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("secret-one-k8s").withNamespace("spring-k8s")
.withResourceVersion("1").build())
.addToData(Collections.singletonMap("one.property", "one-from-k8s".getBytes())).build();
.withMetadata(new V1ObjectMetaBuilder().withName("secret-one-k8s")
.withNamespace("spring-k8s")
.withResourceVersion("1")
.build())
.addToData(Collections.singletonMap("one.property", "one-from-k8s".getBytes()))
.build();
V1Secret two = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("secret-two").withNamespace("spring-k8s")
.withResourceVersion("1").build())
.addToData(Collections.singletonMap("property", "two".getBytes())).build();
.withMetadata(new V1ObjectMetaBuilder().withName("secret-two")
.withNamespace("spring-k8s")
.withResourceVersion("1")
.build())
.addToData(Collections.singletonMap("property", "two".getBytes()))
.build();
V1Secret twoWithProfile = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("secret-two-k8s").withNamespace("spring-k8s")
.withResourceVersion("1").build())
.addToData(Collections.singletonMap("property", "two-from-k8s".getBytes())).build();
.withMetadata(new V1ObjectMetaBuilder().withName("secret-two-k8s")
.withNamespace("spring-k8s")
.withResourceVersion("1")
.build())
.addToData(Collections.singletonMap("property", "two-from-k8s".getBytes()))
.build();
V1Secret three = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("secret-three").withNamespace("spring-k8s")
.withResourceVersion("1").build())
.addToData(Collections.singletonMap("property", "three".getBytes())).build();
.withMetadata(new V1ObjectMetaBuilder().withName("secret-three")
.withNamespace("spring-k8s")
.withResourceVersion("1")
.build())
.addToData(Collections.singletonMap("property", "three".getBytes()))
.build();
V1Secret threeFromProfile = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("secret-three-k8s").withNamespace("spring-k8s")
.withResourceVersion("1").build())
.addToData(Collections.singletonMap("property", "three-from-k8s".getBytes())).build();
.withMetadata(new V1ObjectMetaBuilder().withName("secret-three-k8s")
.withNamespace("spring-k8s")
.withResourceVersion("1")
.build())
.addToData(Collections.singletonMap("property", "three-from-k8s".getBytes()))
.build();
V1SecretList allSecrets = new V1SecretList();
allSecrets.setItems(Arrays.asList(one, oneWithProfile, two, twoWithProfile, three, threeFromProfile));
// the actual stub for CoreV1Api calls
WireMock.stubFor(WireMock.get("/api/v1/namespaces/spring-k8s/secrets")
.willReturn(WireMock.aResponse().withStatus(200).withBody(new JSON().serialize(allSecrets))));
.willReturn(WireMock.aResponse().withStatus(200).withBody(new JSON().serialize(allSecrets))));
}
}

View File

@@ -74,15 +74,16 @@ public class SingleSourceMultipleFilesConfigurationStub {
one.put("fruit-shape.properties", "shape.when.raw=small-sphere\nshape.when.ripe=bigger-sphere");
V1ConfigMap configMap = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("my-configmap").withNamespace("spring-k8s").build())
.addToData(one).build();
.withMetadata(new V1ObjectMetaBuilder().withName("my-configmap").withNamespace("spring-k8s").build())
.addToData(one)
.build();
V1ConfigMapList allConfigMaps = new V1ConfigMapList();
allConfigMaps.addItemsItem(configMap);
// the actual stub for CoreV1Api calls
WireMock.stubFor(WireMock.get("/api/v1/namespaces/spring-k8s/configmaps")
.willReturn(WireMock.aResponse().withStatus(200).withBody(new JSON().serialize(allConfigMaps))));
.willReturn(WireMock.aResponse().withStatus(200).withBody(new JSON().serialize(allConfigMaps))));
}
}

View File

@@ -70,16 +70,20 @@ public class SourcesOrderConfigurationStub {
configMapData.put("my.key", "from-configmap");
configMapData.put("my.two", "two");
V1ConfigMap myConfigMap = new V1ConfigMapBuilder().withMetadata(new V1ObjectMetaBuilder()
.withName("my-configmap").withNamespace("spring-k8s").withResourceVersion("1").build())
.addToData(configMapData).build();
V1ConfigMap myConfigMap = new V1ConfigMapBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("my-configmap")
.withNamespace("spring-k8s")
.withResourceVersion("1")
.build())
.addToData(configMapData)
.build();
V1ConfigMapList allConfigMaps = new V1ConfigMapList();
allConfigMaps.setItems(Collections.singletonList(myConfigMap));
// the actual stub for CoreV1Api calls
WireMock.stubFor(WireMock.get("/api/v1/namespaces/spring-k8s/configmaps")
.willReturn(WireMock.aResponse().withStatus(200).withBody(new JSON().serialize(allConfigMaps))));
.willReturn(WireMock.aResponse().withStatus(200).withBody(new JSON().serialize(allConfigMaps))));
}
public static void stubSecretsData() {
@@ -88,15 +92,20 @@ public class SourcesOrderConfigurationStub {
secretData.put("my.key", "from-secret".getBytes(StandardCharsets.UTF_8));
secretData.put("my.one", "one".getBytes(StandardCharsets.UTF_8));
V1Secret mySecret = new V1SecretBuilder().withMetadata(new V1ObjectMetaBuilder().withName("my-secret")
.withNamespace("spring-k8s").withResourceVersion("1").build()).addToData(secretData).build();
V1Secret mySecret = new V1SecretBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("my-secret")
.withNamespace("spring-k8s")
.withResourceVersion("1")
.build())
.addToData(secretData)
.build();
V1SecretList allConfigMaps = new V1SecretList();
allConfigMaps.setItems(Collections.singletonList(mySecret));
// the actual stub for CoreV1Api calls
WireMock.stubFor(WireMock.get("/api/v1/namespaces/spring-k8s/secrets")
.willReturn(WireMock.aResponse().withStatus(200).withBody(new JSON().serialize(allConfigMaps))));
.willReturn(WireMock.aResponse().withStatus(200).withBody(new JSON().serialize(allConfigMaps))));
}
}

View File

@@ -62,7 +62,7 @@ abstract class ConfigFailFastDisabled {
clientUtilsMock = mockStatic(KubernetesClientUtils.class);
clientUtilsMock.when(KubernetesClientUtils::kubernetesApiClient)
.thenReturn(new ClientBuilder().setBasePath(wireMockServer.baseUrl()).build());
.thenReturn(new ClientBuilder().setBasePath(wireMockServer.baseUrl()).build());
stubConfigMapAndSecretsDefaults();
}

View File

@@ -65,10 +65,10 @@ abstract class ConfigFailFastEnabledButRetryDisabled {
clientUtilsMock = mockStatic(KubernetesClientUtils.class);
clientUtilsMock.when(KubernetesClientUtils::kubernetesApiClient)
.thenReturn(new ClientBuilder().setBasePath(wireMockServer.baseUrl()).build());
.thenReturn(new ClientBuilder().setBasePath(wireMockServer.baseUrl()).build());
clientUtilsMock
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn("default");
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn("default");
stubConfigMapAndSecretsDefaults();
}
@@ -102,7 +102,8 @@ abstract class ConfigFailFastEnabledButRetryDisabled {
assertThat(context.containsBean("kubernetesConfigRetryInterceptor")).isFalse();
assertThatThrownBy(() -> propertySourceLocator.locate(new MockEnvironment()))
.isInstanceOf(IllegalStateException.class).hasMessage("Internal Server Error");
.isInstanceOf(IllegalStateException.class)
.hasMessage("Internal Server Error");
// verify that propertySourceLocator.locate is called only once
verify(propertySourceLocator, times(1)).locate(any());

View File

@@ -79,7 +79,7 @@ public class ConfigMapEnableRetryWithoutFailFastTest {
clientUtilsMock = mockStatic(KubernetesClientUtils.class);
clientUtilsMock.when(KubernetesClientUtils::kubernetesApiClient)
.thenReturn(new ClientBuilder().setBasePath(wireMockServer.baseUrl()).build());
.thenReturn(new ClientBuilder().setBasePath(wireMockServer.baseUrl()).build());
stubConfigMapAndSecretsDefaults();
}
@@ -87,7 +87,7 @@ public class ConfigMapEnableRetryWithoutFailFastTest {
// return empty config map / secret list to not fail context creation
stubFor(get(API).willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(new V1ConfigMapList()))));
stubFor(get(SECRETS_API)
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(new V1SecretList()))));
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(new V1SecretList()))));
}
@AfterAll
@@ -108,7 +108,9 @@ public class ConfigMapEnableRetryWithoutFailFastTest {
ConfigurationPropertiesRebinderAutoConfiguration.class, KubernetesClientBootstrapConfiguration.class,
KubernetesClientRetryBootstrapConfiguration.class, KubernetesBootstrapConfiguration.class,
KubernetesClientConfigReloadAutoConfiguration.class)
.web(org.springframework.boot.WebApplicationType.NONE).properties(envArray).run();
.web(org.springframework.boot.WebApplicationType.NONE)
.properties(envArray)
.run();
}
@AfterEach

View File

@@ -67,10 +67,10 @@ abstract class ConfigRetryDisabledButSecretsRetryEnabled {
clientUtilsMock = mockStatic(KubernetesClientUtils.class);
clientUtilsMock.when(KubernetesClientUtils::kubernetesApiClient)
.thenReturn(new ClientBuilder().setBasePath(wireMockServer.baseUrl()).build());
.thenReturn(new ClientBuilder().setBasePath(wireMockServer.baseUrl()).build());
clientUtilsMock
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn("default");
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn("default");
stubConfigMapAndSecretsDefaults();
}
@@ -78,7 +78,7 @@ abstract class ConfigRetryDisabledButSecretsRetryEnabled {
// return empty config map / secret list to not fail context creation
stubFor(get(API).willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(new V1ConfigMapList()))));
stubFor(get(SECRETS_API)
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(new V1SecretList()))));
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(new V1SecretList()))));
}
@AfterAll
@@ -114,7 +114,8 @@ abstract class ConfigRetryDisabledButSecretsRetryEnabled {
// TODO not in bootstrap
// assertThat(context.containsBean("kubernetesConfigRetryInterceptor")).isTrue();
assertThatThrownBy(() -> propertySourceLocator.locate(new MockEnvironment()))
.isInstanceOf(IllegalStateException.class).hasMessage("Internal Server Error");
.isInstanceOf(IllegalStateException.class)
.hasMessage("Internal Server Error");
// verify that propertySourceLocator.locate is called only once
verify(propertySourceLocator, times(1)).locate(any());

View File

@@ -71,10 +71,10 @@ abstract class ConfigRetryEnabled {
clientUtilsMock = mockStatic(KubernetesClientUtils.class);
clientUtilsMock.when(KubernetesClientUtils::kubernetesApiClient)
.thenReturn(new ClientBuilder().setBasePath(wireMockServer.baseUrl()).build());
.thenReturn(new ClientBuilder().setBasePath(wireMockServer.baseUrl()).build());
clientUtilsMock
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn("default");
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn("default");
stubConfigMapAndSecretsDefaults();
}
@@ -106,12 +106,12 @@ abstract class ConfigRetryEnabled {
data.put("some.number", "0");
V1ConfigMapList configMapList = new V1ConfigMapList()
.addItemsItem(new V1ConfigMap().metadata(new V1ObjectMeta().name("application")).data(data));
.addItemsItem(new V1ConfigMap().metadata(new V1ObjectMeta().name("application")).data(data));
stubFor(get(API).willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(configMapList))));
PropertySource<?> propertySource = Assertions
.assertDoesNotThrow(() -> propertySourceLocator.locate(new MockEnvironment()));
.assertDoesNotThrow(() -> propertySourceLocator.locate(new MockEnvironment()));
// verify locate is called only once
WireMock.verify(1, getRequestedFor(urlEqualTo(API)));
@@ -129,24 +129,31 @@ abstract class ConfigRetryEnabled {
data.put("some.number", "0");
V1ConfigMapList configMapList = new V1ConfigMapList()
.addItemsItem(new V1ConfigMap().metadata(new V1ObjectMeta().name("application")).data(data));
.addItemsItem(new V1ConfigMap().metadata(new V1ObjectMeta().name("application")).data(data));
// fail 3 times
stubFor(get(API).inScenario("Retry and Recover").whenScenarioStateIs(STARTED)
.willReturn(aResponse().withStatus(500)).willSetStateTo("Failed once"));
stubFor(get(API).inScenario("Retry and Recover")
.whenScenarioStateIs(STARTED)
.willReturn(aResponse().withStatus(500))
.willSetStateTo("Failed once"));
stubFor(get(API).inScenario("Retry and Recover").whenScenarioStateIs("Failed once")
.willReturn(aResponse().withStatus(500)).willSetStateTo("Failed twice"));
stubFor(get(API).inScenario("Retry and Recover")
.whenScenarioStateIs("Failed once")
.willReturn(aResponse().withStatus(500))
.willSetStateTo("Failed twice"));
stubFor(get(API).inScenario("Retry and Recover").whenScenarioStateIs("Failed twice")
.willReturn(aResponse().withStatus(500)).willSetStateTo("Failed thrice"));
stubFor(get(API).inScenario("Retry and Recover")
.whenScenarioStateIs("Failed twice")
.willReturn(aResponse().withStatus(500))
.willSetStateTo("Failed thrice"));
// then succeed
stubFor(get(API).inScenario("Retry and Recover").whenScenarioStateIs("Failed thrice")
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(configMapList))));
stubFor(get(API).inScenario("Retry and Recover")
.whenScenarioStateIs("Failed thrice")
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(configMapList))));
PropertySource<?> propertySource = Assertions
.assertDoesNotThrow(() -> propertySourceLocator.locate(new MockEnvironment()));
.assertDoesNotThrow(() -> propertySourceLocator.locate(new MockEnvironment()));
// verify the request was retried 4 times, 5 total request
WireMock.verify(5, getRequestedFor(urlEqualTo(API)));
@@ -163,7 +170,8 @@ abstract class ConfigRetryEnabled {
stubFor(get(API).willReturn(aResponse().withStatus(500).withBody("Internal Server Error")));
assertThatThrownBy(() -> propertySourceLocator.locate(new MockEnvironment()))
.isInstanceOf(IllegalStateException.class).hasMessage("Internal Server Error");
.isInstanceOf(IllegalStateException.class)
.hasMessage("Internal Server Error");
// verify the request was retried 5 times
WireMock.verify(5, getRequestedFor(urlEqualTo(API)));

View File

@@ -95,7 +95,7 @@ class KubernetesClientEventBasedConfigMapChangeDetectorTests {
void watch() {
GsonBuilder builder = new GsonBuilder();
builder.excludeFieldsWithModifiers(Modifier.STATIC, Modifier.TRANSIENT, Modifier.VOLATILE)
.registerTypeAdapter(OffsetDateTime.class, new GsonOffsetDateTimeAdapter());
.registerTypeAdapter(OffsetDateTime.class, new GsonOffsetDateTimeAdapter());
Gson gson = builder.create();
Map<String, String> data = new HashMap<>();
@@ -105,41 +105,50 @@ class KubernetesClientEventBasedConfigMapChangeDetectorTests {
updateData.put("application.properties", "spring.cloud.kubernetes.configuration.watcher.refreshDelay=1\n"
+ "logging.level.org.springframework.cloud.kubernetes=TRACE");
V1ConfigMap applicationConfig = new V1ConfigMap().kind("ConfigMap")
.metadata(new V1ObjectMeta().namespace("default").name("bar1")).data(data);
.metadata(new V1ObjectMeta().namespace("default").name("bar1"))
.data(data);
V1ConfigMapList configMapList = new V1ConfigMapList().metadata(new V1ListMeta().resourceVersion("0"))
.items(List.of(applicationConfig));
.items(List.of(applicationConfig));
stubFor(get(urlMatching("^/api/v1/namespaces/default/configmaps.*")).inScenario("watch")
.whenScenarioStateIs(STARTED).withQueryParam("watch", equalTo("false"))
.willReturn(aResponse().withStatus(200).withBody(gson.toJson(configMapList))).willSetStateTo("update"));
.whenScenarioStateIs(STARTED)
.withQueryParam("watch", equalTo("false"))
.willReturn(aResponse().withStatus(200).withBody(gson.toJson(configMapList)))
.willSetStateTo("update"));
Watch.Response<V1ConfigMap> watchResponse = new Watch.Response<>(EventType.MODIFIED.name(), new V1ConfigMap()
.kind("ConfigMap").metadata(new V1ObjectMeta().namespace("default").name("bar1")).data(updateData));
Watch.Response<V1ConfigMap> watchResponse = new Watch.Response<>(EventType.MODIFIED.name(),
new V1ConfigMap().kind("ConfigMap")
.metadata(new V1ObjectMeta().namespace("default").name("bar1"))
.data(updateData));
stubFor(get(urlMatching("^/api/v1/namespaces/default/configmaps.*")).inScenario("watch")
.whenScenarioStateIs("update").withQueryParam("watch", equalTo("true"))
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(watchResponse)))
.willSetStateTo("add"));
.whenScenarioStateIs("update")
.withQueryParam("watch", equalTo("true"))
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(watchResponse)))
.willSetStateTo("add"));
stubFor(get(urlMatching("^/api/v1/namespaces/default/configmaps.*")).inScenario("watch")
.whenScenarioStateIs("add").withQueryParam("watch", equalTo("true"))
.willReturn(aResponse().withStatus(200)
.withBody(new JSON().serialize(new Watch.Response<>(EventType.ADDED.name(),
new V1ConfigMap().kind("ConfigMap")
.metadata(new V1ObjectMeta().namespace("default").name("bar3"))
.putDataItem("application.properties", "debug=true")))))
.willSetStateTo("delete"));
.whenScenarioStateIs("add")
.withQueryParam("watch", equalTo("true"))
.willReturn(aResponse().withStatus(200)
.withBody(new JSON().serialize(new Watch.Response<>(EventType.ADDED.name(),
new V1ConfigMap().kind("ConfigMap")
.metadata(new V1ObjectMeta().namespace("default").name("bar3"))
.putDataItem("application.properties", "debug=true")))))
.willSetStateTo("delete"));
stubFor(get(urlMatching("^/api/v1/namespaces/default/configmaps.*")).inScenario("watch")
.whenScenarioStateIs("delete").withQueryParam("watch", equalTo("true"))
.willReturn(aResponse().withStatus(200)
.withBody(new JSON().serialize(new Watch.Response<>(EventType.DELETED.name(),
new V1ConfigMap().kind("ConfigMap")
.metadata(new V1ObjectMeta().namespace("default").name("bar1"))
.putDataItem("application.properties", "debug=true")))))
.willSetStateTo("done"));
.whenScenarioStateIs("delete")
.withQueryParam("watch", equalTo("true"))
.willReturn(aResponse().withStatus(200)
.withBody(new JSON().serialize(new Watch.Response<>(EventType.DELETED.name(),
new V1ConfigMap().kind("ConfigMap")
.metadata(new V1ObjectMeta().namespace("default").name("bar1"))
.putDataItem("application.properties", "debug=true")))))
.willSetStateTo("done"));
stubFor(get(urlMatching("^/api/v1/namespaces/default/configmaps.*")).inScenario("watch")
.whenScenarioStateIs("done").withQueryParam("watch", equalTo("true"))
.willReturn(aResponse().withStatus(200)));
.whenScenarioStateIs("done")
.withQueryParam("watch", equalTo("true"))
.willReturn(aResponse().withStatus(200)));
ApiClient apiClient = new ClientBuilder().setBasePath("http://localhost:" + wireMockServer.port()).build();
OkHttpClient httpClient = apiClient.getHttpClient().newBuilder().readTimeout(0, TimeUnit.SECONDS).build();
apiClient.setHttpClient(httpClient);
@@ -152,7 +161,8 @@ class KubernetesClientEventBasedConfigMapChangeDetectorTests {
ConfigurationUpdateStrategy strategy = new ConfigurationUpdateStrategy("strategy", run);
KubernetesMockEnvironment environment = new KubernetesMockEnvironment(
mock(KubernetesClientConfigMapPropertySource.class)).withProperty("debug", "true");
mock(KubernetesClientConfigMapPropertySource.class))
.withProperty("debug", "true");
KubernetesClientConfigMapPropertySourceLocator locator = mock(
KubernetesClientConfigMapPropertySourceLocator.class);
when(locator.locate(environment)).thenAnswer(x -> new MockPropertySource().withProperty("debug", "false"));

View File

@@ -96,48 +96,54 @@ class KubernetesClientEventBasedSecretsChangeDetectorTests {
void watch() {
V1Secret dbPassword = new V1Secret().metadata(new V1ObjectMeta().name("db-password"))
.putStringDataItem("password", Base64.getEncoder().encodeToString("p455w0rd".getBytes()))
.putDataItem("password", Base64.getEncoder().encode("p455w0rd".getBytes()))
.putStringDataItem("username", Base64.getEncoder().encodeToString("user".getBytes()))
.putDataItem("username", Base64.getEncoder().encode("user".getBytes()));
.putStringDataItem("password", Base64.getEncoder().encodeToString("p455w0rd".getBytes()))
.putDataItem("password", Base64.getEncoder().encode("p455w0rd".getBytes()))
.putStringDataItem("username", Base64.getEncoder().encodeToString("user".getBytes()))
.putDataItem("username", Base64.getEncoder().encode("user".getBytes()));
V1SecretList secretList = new V1SecretList().metadata(new V1ListMeta().resourceVersion("0"))
.items(List.of(dbPassword));
.items(List.of(dbPassword));
V1Secret dbPasswordUpdated = new V1Secret().metadata(new V1ObjectMeta().name("db-password"))
.putStringDataItem("password", Base64.getEncoder().encodeToString("p455w0rd2".getBytes()))
.putDataItem("password", Base64.getEncoder().encode("p455w0rd2".getBytes()))
.putStringDataItem("username", Base64.getEncoder().encodeToString("user".getBytes()))
.putDataItem("username", Base64.getEncoder().encode("user".getBytes()));
.putStringDataItem("password", Base64.getEncoder().encodeToString("p455w0rd2".getBytes()))
.putDataItem("password", Base64.getEncoder().encode("p455w0rd2".getBytes()))
.putStringDataItem("username", Base64.getEncoder().encodeToString("user".getBytes()))
.putDataItem("username", Base64.getEncoder().encode("user".getBytes()));
Watch.Response<V1Secret> watchResponse = new Watch.Response<>(EventType.MODIFIED.name(), dbPasswordUpdated);
stubFor(get(urlMatching("/api/v1/namespaces/default/secrets.*")).inScenario(SCENARIO)
.whenScenarioStateIs(STARTED).withQueryParams(WATCH_FALSE)
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(secretList)))
.willSetStateTo("update"));
.whenScenarioStateIs(STARTED)
.withQueryParams(WATCH_FALSE)
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(secretList)))
.willSetStateTo("update"));
stubFor(get(urlMatching("/api/v1/namespaces/default/secrets.*")).inScenario(SCENARIO)
.whenScenarioStateIs("update").withQueryParams(WATCH_TRUE)
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(watchResponse)))
.willSetStateTo("add"));
stubFor(get(urlMatching("/api/v1/namespaces/default/secrets.*")).inScenario(SCENARIO).whenScenarioStateIs("add")
.withQueryParams(WATCH_TRUE)
.willReturn(aResponse().withStatus(200)
.withBody(new JSON().serialize(new Watch.Response<>(EventType.ADDED.name(),
new V1Secret().metadata(new V1ObjectMeta().name("rabbit-password"))
.putDataItem("rabbit-pw", Base64.getEncoder().encode("password".getBytes()))))))
.willSetStateTo("delete"));
.whenScenarioStateIs("update")
.withQueryParams(WATCH_TRUE)
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(watchResponse)))
.willSetStateTo("add"));
stubFor(get(urlMatching("/api/v1/namespaces/default/secrets.*")).inScenario(SCENARIO)
.whenScenarioStateIs("delete").withQueryParams(WATCH_TRUE)
.willReturn(aResponse().withStatus(200)
.withBody(new JSON().serialize(new Watch.Response<>(EventType.DELETED.name(),
new V1Secret().metadata(new V1ObjectMeta().name("rabbit-password"))
.putDataItem("rabbit-pw", Base64.getEncoder().encode("password".getBytes()))))))
.willSetStateTo("done"));
.whenScenarioStateIs("add")
.withQueryParams(WATCH_TRUE)
.willReturn(aResponse().withStatus(200)
.withBody(new JSON().serialize(new Watch.Response<>(EventType.ADDED.name(),
new V1Secret().metadata(new V1ObjectMeta().name("rabbit-password"))
.putDataItem("rabbit-pw", Base64.getEncoder().encode("password".getBytes()))))))
.willSetStateTo("delete"));
stubFor(get(urlMatching("/api/v1/namespaces/default/secrets.*")).inScenario("watch").whenScenarioStateIs("done")
.withQueryParam("watch", equalTo("true")).willReturn(aResponse().withStatus(200)));
stubFor(get(urlMatching("/api/v1/namespaces/default/secrets.*")).inScenario(SCENARIO)
.whenScenarioStateIs("delete")
.withQueryParams(WATCH_TRUE)
.willReturn(aResponse().withStatus(200)
.withBody(new JSON().serialize(new Watch.Response<>(EventType.DELETED.name(),
new V1Secret().metadata(new V1ObjectMeta().name("rabbit-password"))
.putDataItem("rabbit-pw", Base64.getEncoder().encode("password".getBytes()))))))
.willSetStateTo("done"));
stubFor(get(urlMatching("/api/v1/namespaces/default/secrets.*")).inScenario("watch")
.whenScenarioStateIs("done")
.withQueryParam("watch", equalTo("true"))
.willReturn(aResponse().withStatus(200)));
ApiClient apiClient = new ClientBuilder().setBasePath("http://localhost:" + wireMockServer.port()).build();
OkHttpClient httpClient = apiClient.getHttpClient().newBuilder().readTimeout(0, TimeUnit.SECONDS).build();
@@ -151,10 +157,11 @@ class KubernetesClientEventBasedSecretsChangeDetectorTests {
ConfigurationUpdateStrategy strategy = new ConfigurationUpdateStrategy("strategy", run);
KubernetesMockEnvironment environment = new KubernetesMockEnvironment(
mock(KubernetesClientSecretsPropertySource.class)).withProperty("db-password", "p455w0rd");
mock(KubernetesClientSecretsPropertySource.class))
.withProperty("db-password", "p455w0rd");
KubernetesClientSecretsPropertySourceLocator locator = mock(KubernetesClientSecretsPropertySourceLocator.class);
when(locator.locate(environment))
.thenAnswer(ignoreMe -> new MockPropertySource().withProperty("db-password", "p455w0rd2"));
.thenAnswer(ignoreMe -> new MockPropertySource().withProperty("db-password", "p455w0rd2"));
ConfigReloadProperties properties = new ConfigReloadProperties(false, false, true,
ConfigReloadProperties.ReloadStrategy.REFRESH, ConfigReloadProperties.ReloadDetectionMode.EVENT,
Duration.ofMillis(15000), Set.of(), false, Duration.ofSeconds(2));

View File

@@ -47,24 +47,42 @@ class BootstrapKubernetesClientSanitizeConfigpropsEndpointTests {
@Test
void test() {
// configmap is sanitized
webClient.get().uri("http://localhost:{port}/actuator/configprops", this.port)
.accept(MediaType.APPLICATION_JSON).exchange().expectBody()
.jsonPath("contexts.['sanitize-1'].beans.[*].properties.sanitizeConfigMapName")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
webClient.get()
.uri("http://localhost:{port}/actuator/configprops", this.port)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectBody()
.jsonPath("contexts.['sanitize-1'].beans.[*].properties.sanitizeConfigMapName")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
// secret is sanitized
webClient.get().uri("http://localhost:{port}/actuator/configprops", this.port)
.accept(MediaType.APPLICATION_JSON).exchange().expectBody()
.jsonPath("contexts.['sanitize-1'].beans.[*].properties.sanitizeSecretName")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
webClient.get()
.uri("http://localhost:{port}/actuator/configprops", this.port)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectBody()
.jsonPath("contexts.['sanitize-1'].beans.[*].properties.sanitizeSecretName")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
// secret is usable from configuration properties
webClient.get().uri("http://localhost:{port}/secret", this.port).exchange().expectStatus().isOk()
.expectBody().jsonPath("$").isEqualTo("sanitizeSecretValue");
webClient.get()
.uri("http://localhost:{port}/secret", this.port)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("$")
.isEqualTo("sanitizeSecretValue");
// configmap is usable from configuration properties
webClient.get().uri("http://localhost:{port}/configmap", this.port).exchange().expectStatus().isOk()
.expectBody().jsonPath("$").isEqualTo("sanitizeConfigMapValue");
webClient.get()
.uri("http://localhost:{port}/configmap", this.port)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("$")
.isEqualTo("sanitizeConfigMapValue");
}
}
@@ -87,24 +105,46 @@ class BootstrapKubernetesClientSanitizeConfigpropsEndpointTests {
@Test
void test() {
// configmap is sanitized
webClient.get().uri("http://localhost:{port}/actuator/configprops", this.port)
.accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody()
.jsonPath("contexts.['sanitize-1'].beans.[*].properties.sanitizeConfigMapName")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
webClient.get()
.uri("http://localhost:{port}/actuator/configprops", this.port)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("contexts.['sanitize-1'].beans.[*].properties.sanitizeConfigMapName")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
// secret is sanitized
webClient.get().uri("http://localhost:{port}/actuator/configprops", this.port)
.accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody()
.jsonPath("contexts.['sanitize-1'].beans.[*].properties.sanitizeSecretName")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
webClient.get()
.uri("http://localhost:{port}/actuator/configprops", this.port)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("contexts.['sanitize-1'].beans.[*].properties.sanitizeSecretName")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
// secret is usable from configuration properties
webClient.get().uri("http://localhost:{port}/secret", this.port).exchange().expectStatus().isOk()
.expectBody().jsonPath("$").isEqualTo("sanitizeSecretValue");
webClient.get()
.uri("http://localhost:{port}/secret", this.port)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("$")
.isEqualTo("sanitizeSecretValue");
// configmap is usable from configuration properties
webClient.get().uri("http://localhost:{port}/configmap", this.port).exchange().expectStatus().isOk()
.expectBody().jsonPath("$").isEqualTo("sanitizeConfigMapValue");
webClient.get()
.uri("http://localhost:{port}/configmap", this.port)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("$")
.isEqualTo("sanitizeConfigMapValue");
}
}
@@ -137,24 +177,46 @@ class BootstrapKubernetesClientSanitizeConfigpropsEndpointTests {
@Test
void test() {
// configmap is not sanitized
webClient.get().uri("http://localhost:{port}/actuator/configprops", this.port)
.accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody()
.jsonPath("contexts.['sanitize-1'].beans.[*].properties.sanitizeConfigMapName")
.isEqualTo("sanitizeConfigMapValue");
webClient.get()
.uri("http://localhost:{port}/actuator/configprops", this.port)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("contexts.['sanitize-1'].beans.[*].properties.sanitizeConfigMapName")
.isEqualTo("sanitizeConfigMapValue");
// secret is not sanitized
webClient.get().uri("http://localhost:{port}/actuator/configprops", this.port)
.accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody()
.jsonPath("contexts.['sanitize-1'].beans.[*].properties.sanitizeSecretName")
.isEqualTo("sanitizeSecretValue");
webClient.get()
.uri("http://localhost:{port}/actuator/configprops", this.port)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("contexts.['sanitize-1'].beans.[*].properties.sanitizeSecretName")
.isEqualTo("sanitizeSecretValue");
// secret is usable from configuration properties
webClient.get().uri("http://localhost:{port}/secret", this.port).exchange().expectStatus().isOk()
.expectBody().jsonPath("$").isEqualTo("sanitizeSecretValue");
webClient.get()
.uri("http://localhost:{port}/secret", this.port)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("$")
.isEqualTo("sanitizeSecretValue");
// configmap is usable from configuration properties
webClient.get().uri("http://localhost:{port}/configmap", this.port).exchange().expectStatus().isOk()
.expectBody().jsonPath("$").isEqualTo("sanitizeConfigMapValue");
webClient.get()
.uri("http://localhost:{port}/configmap", this.port)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("$")
.isEqualTo("sanitizeConfigMapValue");
}
}
@@ -187,30 +249,57 @@ class BootstrapKubernetesClientSanitizeConfigpropsEndpointTests {
@Test
void test() {
// configmap is not sanitized
webClient.get().uri("http://localhost:{port}/actuator/configprops", this.port)
.accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody()
.jsonPath("contexts.['sanitize-1'].beans.[*].properties.sanitizeConfigMapName")
.isEqualTo("sanitizeConfigMapValue");
webClient.get()
.uri("http://localhost:{port}/actuator/configprops", this.port)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("contexts.['sanitize-1'].beans.[*].properties.sanitizeConfigMapName")
.isEqualTo("sanitizeConfigMapValue");
// first secret is sanitized
webClient.get().uri("http://localhost:{port}/actuator/configprops", this.port)
.accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody()
.jsonPath("contexts.['sanitize-1'].beans.[*].properties.sanitizeSecretName")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
webClient.get()
.uri("http://localhost:{port}/actuator/configprops", this.port)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("contexts.['sanitize-1'].beans.[*].properties.sanitizeSecretName")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
// second secret is sanitized
webClient.get().uri("http://localhost:{port}/actuator/configprops", this.port)
.accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody()
.jsonPath("contexts.['sanitize-1'].beans.[*].properties.sanitizeSecretNameTwo")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
webClient.get()
.uri("http://localhost:{port}/actuator/configprops", this.port)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("contexts.['sanitize-1'].beans.[*].properties.sanitizeSecretNameTwo")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
// secret is usable from configuration properties
webClient.get().uri("http://localhost:{port}/secret", this.port).exchange().expectStatus().isOk()
.expectBody().jsonPath("$").isEqualTo("sanitizeSecretValue");
webClient.get()
.uri("http://localhost:{port}/secret", this.port)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("$")
.isEqualTo("sanitizeSecretValue");
// configmap is usable from configuration properties
webClient.get().uri("http://localhost:{port}/configmap", this.port).exchange().expectStatus().isOk()
.expectBody().jsonPath("$").isEqualTo("sanitizeConfigMapValue");
webClient.get()
.uri("http://localhost:{port}/configmap", this.port)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("$")
.isEqualTo("sanitizeConfigMapValue");
}
}

View File

@@ -47,24 +47,46 @@ class BootstrapKubernetesClientSanitizeEnvEndpointTests {
@Test
void test() {
// configmap is sanitized
webClient.get().uri("http://localhost:{port}/actuator/env", this.port).accept(MediaType.APPLICATION_JSON)
.exchange().expectStatus().isOk().expectBody()
.jsonPath("propertySources.[*].properties.['sanitize.sanitizeConfigMapName'].value")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
webClient.get()
.uri("http://localhost:{port}/actuator/env", this.port)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("propertySources.[*].properties.['sanitize.sanitizeConfigMapName'].value")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
// secret is sanitized
webClient.get().uri("http://localhost:{port}/actuator/env", this.port).accept(MediaType.APPLICATION_JSON)
.exchange().expectStatus().isOk().expectBody()
.jsonPath("propertySources.[*].properties.['sanitize.sanitizeSecretName'].value")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
webClient.get()
.uri("http://localhost:{port}/actuator/env", this.port)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("propertySources.[*].properties.['sanitize.sanitizeSecretName'].value")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
// secret is usable from configuration properties
webClient.get().uri("http://localhost:{port}/secret", this.port).exchange().expectStatus().isOk()
.expectBody().jsonPath("$").isEqualTo("sanitizeSecretValue");
webClient.get()
.uri("http://localhost:{port}/secret", this.port)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("$")
.isEqualTo("sanitizeSecretValue");
// configmap is usable from configuration properties
webClient.get().uri("http://localhost:{port}/configmap", this.port).exchange().expectStatus().isOk()
.expectBody().jsonPath("$").isEqualTo("sanitizeConfigMapValue");
webClient.get()
.uri("http://localhost:{port}/configmap", this.port)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("$")
.isEqualTo("sanitizeConfigMapValue");
}
}
@@ -87,24 +109,46 @@ class BootstrapKubernetesClientSanitizeEnvEndpointTests {
@Test
void test() {
// configmap is sanitized
webClient.get().uri("http://localhost:{port}/actuator/env", this.port).accept(MediaType.APPLICATION_JSON)
.exchange().expectStatus().isOk().expectBody()
.jsonPath("propertySources.[*].properties.['sanitize.sanitizeConfigMapName'].value")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
webClient.get()
.uri("http://localhost:{port}/actuator/env", this.port)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("propertySources.[*].properties.['sanitize.sanitizeConfigMapName'].value")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
// secret is sanitized
webClient.get().uri("http://localhost:{port}/actuator/env", this.port).accept(MediaType.APPLICATION_JSON)
.exchange().expectStatus().isOk().expectBody()
.jsonPath("propertySources.[*].properties.['sanitize.sanitizeSecretName'].value")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
webClient.get()
.uri("http://localhost:{port}/actuator/env", this.port)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("propertySources.[*].properties.['sanitize.sanitizeSecretName'].value")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
// secret is usable from configuration properties
webClient.get().uri("http://localhost:{port}/secret", this.port).exchange().expectStatus().isOk()
.expectBody().jsonPath("$").isEqualTo("sanitizeSecretValue");
webClient.get()
.uri("http://localhost:{port}/secret", this.port)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("$")
.isEqualTo("sanitizeSecretValue");
// configmap is usable from configuration properties
webClient.get().uri("http://localhost:{port}/configmap", this.port).exchange().expectStatus().isOk()
.expectBody().jsonPath("$").isEqualTo("sanitizeConfigMapValue");
webClient.get()
.uri("http://localhost:{port}/configmap", this.port)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("$")
.isEqualTo("sanitizeConfigMapValue");
}
}
@@ -136,24 +180,46 @@ class BootstrapKubernetesClientSanitizeEnvEndpointTests {
@Test
void test() {
// configmap is not sanitized
webClient.get().uri("http://localhost:{port}/actuator/env", this.port).accept(MediaType.APPLICATION_JSON)
.exchange().expectStatus().isOk().expectBody()
.jsonPath("propertySources.[*].properties.['sanitize.sanitizeConfigMapName'].value")
.isEqualTo("sanitizeConfigMapValue");
webClient.get()
.uri("http://localhost:{port}/actuator/env", this.port)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("propertySources.[*].properties.['sanitize.sanitizeConfigMapName'].value")
.isEqualTo("sanitizeConfigMapValue");
// secret is not sanitized
webClient.get().uri("http://localhost:{port}/actuator/env", this.port).accept(MediaType.APPLICATION_JSON)
.exchange().expectStatus().isOk().expectBody()
.jsonPath("propertySources.[*].properties.['sanitize.sanitizeSecretName'].value")
.isEqualTo("sanitizeSecretValue");
webClient.get()
.uri("http://localhost:{port}/actuator/env", this.port)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("propertySources.[*].properties.['sanitize.sanitizeSecretName'].value")
.isEqualTo("sanitizeSecretValue");
// secret is usable from configuration properties
webClient.get().uri("http://localhost:{port}/secret", this.port).exchange().expectStatus().isOk()
.expectBody().jsonPath("$").isEqualTo("sanitizeSecretValue");
webClient.get()
.uri("http://localhost:{port}/secret", this.port)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("$")
.isEqualTo("sanitizeSecretValue");
// configmap is usable from configuration properties
webClient.get().uri("http://localhost:{port}/configmap", this.port).exchange().expectStatus().isOk()
.expectBody().jsonPath("$").isEqualTo("sanitizeConfigMapValue");
webClient.get()
.uri("http://localhost:{port}/configmap", this.port)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("$")
.isEqualTo("sanitizeConfigMapValue");
}
}
@@ -185,30 +251,57 @@ class BootstrapKubernetesClientSanitizeEnvEndpointTests {
@Test
void test() {
// configmap is not sanitized
webClient.get().uri("http://localhost:{port}/actuator/env", this.port).accept(MediaType.APPLICATION_JSON)
.exchange().expectStatus().isOk().expectBody()
.jsonPath("propertySources.[*].properties.['sanitize.sanitizeConfigMapName'].value")
.isEqualTo("sanitizeConfigMapValue");
webClient.get()
.uri("http://localhost:{port}/actuator/env", this.port)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("propertySources.[*].properties.['sanitize.sanitizeConfigMapName'].value")
.isEqualTo("sanitizeConfigMapValue");
// first secret is sanitized
webClient.get().uri("http://localhost:{port}/actuator/env", this.port).accept(MediaType.APPLICATION_JSON)
.exchange().expectStatus().isOk().expectBody()
.jsonPath("propertySources.[*].properties.['sanitize.sanitizeSecretName'].value")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
webClient.get()
.uri("http://localhost:{port}/actuator/env", this.port)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("propertySources.[*].properties.['sanitize.sanitizeSecretName'].value")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
// second secret is sanitized
webClient.get().uri("http://localhost:{port}/actuator/env", this.port).accept(MediaType.APPLICATION_JSON)
.exchange().expectStatus().isOk().expectBody()
.jsonPath("propertySources.[*].properties.['sanitize.sanitizeSecretNameTwo'].value")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
webClient.get()
.uri("http://localhost:{port}/actuator/env", this.port)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("propertySources.[*].properties.['sanitize.sanitizeSecretNameTwo'].value")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
// secret is usable from configuration properties
webClient.get().uri("http://localhost:{port}/secret", this.port).exchange().expectStatus().isOk()
.expectBody().jsonPath("$").isEqualTo("sanitizeSecretValue");
webClient.get()
.uri("http://localhost:{port}/secret", this.port)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("$")
.isEqualTo("sanitizeSecretValue");
// configmap is usable from configuration properties
webClient.get().uri("http://localhost:{port}/configmap", this.port).exchange().expectStatus().isOk()
.expectBody().jsonPath("$").isEqualTo("sanitizeConfigMapValue");
webClient.get()
.uri("http://localhost:{port}/configmap", this.port)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("$")
.isEqualTo("sanitizeConfigMapValue");
}
}

View File

@@ -46,24 +46,42 @@ class ConfigDataFabric8ConfigpropsEndpointTests {
@Test
void test() {
// configmap is sanitized
webClient.get().uri("http://localhost:{port}/actuator/configprops", this.port)
.accept(MediaType.APPLICATION_JSON).exchange().expectBody()
.jsonPath("contexts.sanitize.beans.[*].properties.sanitizeConfigMapName")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
webClient.get()
.uri("http://localhost:{port}/actuator/configprops", this.port)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectBody()
.jsonPath("contexts.sanitize.beans.[*].properties.sanitizeConfigMapName")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
// secret is sanitized
webClient.get().uri("http://localhost:{port}/actuator/configprops", this.port)
.accept(MediaType.APPLICATION_JSON).exchange().expectBody()
.jsonPath("contexts.sanitize.beans.[*].properties.sanitizeSecretName")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
webClient.get()
.uri("http://localhost:{port}/actuator/configprops", this.port)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectBody()
.jsonPath("contexts.sanitize.beans.[*].properties.sanitizeSecretName")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
// secret is usable from configuration properties
webClient.get().uri("http://localhost:{port}/secret", this.port).exchange().expectStatus().isOk()
.expectBody().jsonPath("$").isEqualTo("sanitizeSecretValue");
webClient.get()
.uri("http://localhost:{port}/secret", this.port)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("$")
.isEqualTo("sanitizeSecretValue");
// configmap is usable from configuration properties
webClient.get().uri("http://localhost:{port}/configmap", this.port).exchange().expectStatus().isOk()
.expectBody().jsonPath("$").isEqualTo("sanitizeConfigMapValue");
webClient.get()
.uri("http://localhost:{port}/configmap", this.port)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("$")
.isEqualTo("sanitizeConfigMapValue");
}
}
@@ -85,24 +103,46 @@ class ConfigDataFabric8ConfigpropsEndpointTests {
@Test
void test() {
// configmap is sanitized
webClient.get().uri("http://localhost:{port}/actuator/configprops", this.port)
.accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody()
.jsonPath("contexts.sanitize.beans.[*].properties.sanitizeConfigMapName")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
webClient.get()
.uri("http://localhost:{port}/actuator/configprops", this.port)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("contexts.sanitize.beans.[*].properties.sanitizeConfigMapName")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
// secret is sanitized
webClient.get().uri("http://localhost:{port}/actuator/configprops", this.port)
.accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody()
.jsonPath("contexts.sanitize.beans.[*].properties.sanitizeSecretName")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
webClient.get()
.uri("http://localhost:{port}/actuator/configprops", this.port)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("contexts.sanitize.beans.[*].properties.sanitizeSecretName")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
// secret is usable from configuration properties
webClient.get().uri("http://localhost:{port}/secret", this.port).exchange().expectStatus().isOk()
.expectBody().jsonPath("$").isEqualTo("sanitizeSecretValue");
webClient.get()
.uri("http://localhost:{port}/secret", this.port)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("$")
.isEqualTo("sanitizeSecretValue");
// configmap is usable from configuration properties
webClient.get().uri("http://localhost:{port}/configmap", this.port).exchange().expectStatus().isOk()
.expectBody().jsonPath("$").isEqualTo("sanitizeConfigMapValue");
webClient.get()
.uri("http://localhost:{port}/configmap", this.port)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("$")
.isEqualTo("sanitizeConfigMapValue");
}
}
@@ -134,24 +174,46 @@ class ConfigDataFabric8ConfigpropsEndpointTests {
@Test
void test() {
// configmap is not sanitized
webClient.get().uri("http://localhost:{port}/actuator/configprops", this.port)
.accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody()
.jsonPath("contexts.sanitize.beans.[*].properties.sanitizeConfigMapName")
.isEqualTo("sanitizeConfigMapValue");
webClient.get()
.uri("http://localhost:{port}/actuator/configprops", this.port)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("contexts.sanitize.beans.[*].properties.sanitizeConfigMapName")
.isEqualTo("sanitizeConfigMapValue");
// secret is not sanitized
webClient.get().uri("http://localhost:{port}/actuator/configprops", this.port)
.accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody()
.jsonPath("contexts.sanitize.beans.[*].properties.sanitizeSecretName")
.isEqualTo("sanitizeSecretValue");
webClient.get()
.uri("http://localhost:{port}/actuator/configprops", this.port)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("contexts.sanitize.beans.[*].properties.sanitizeSecretName")
.isEqualTo("sanitizeSecretValue");
// secret is usable from configuration properties
webClient.get().uri("http://localhost:{port}/secret", this.port).exchange().expectStatus().isOk()
.expectBody().jsonPath("$").isEqualTo("sanitizeSecretValue");
webClient.get()
.uri("http://localhost:{port}/secret", this.port)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("$")
.isEqualTo("sanitizeSecretValue");
// configmap is usable from configuration properties
webClient.get().uri("http://localhost:{port}/configmap", this.port).exchange().expectStatus().isOk()
.expectBody().jsonPath("$").isEqualTo("sanitizeConfigMapValue");
webClient.get()
.uri("http://localhost:{port}/configmap", this.port)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("$")
.isEqualTo("sanitizeConfigMapValue");
}
}
@@ -183,30 +245,57 @@ class ConfigDataFabric8ConfigpropsEndpointTests {
@Test
void test() {
// configmap is not sanitized
webClient.get().uri("http://localhost:{port}/actuator/configprops", this.port)
.accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody()
.jsonPath("contexts.sanitize.beans.[*].properties.sanitizeConfigMapName")
.isEqualTo("sanitizeConfigMapValue");
webClient.get()
.uri("http://localhost:{port}/actuator/configprops", this.port)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("contexts.sanitize.beans.[*].properties.sanitizeConfigMapName")
.isEqualTo("sanitizeConfigMapValue");
// first secret is sanitized
webClient.get().uri("http://localhost:{port}/actuator/configprops", this.port)
.accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody()
.jsonPath("contexts.sanitize.beans.[*].properties.sanitizeSecretName")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
webClient.get()
.uri("http://localhost:{port}/actuator/configprops", this.port)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("contexts.sanitize.beans.[*].properties.sanitizeSecretName")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
// second secret is sanitized
webClient.get().uri("http://localhost:{port}/actuator/configprops", this.port)
.accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody()
.jsonPath("contexts.sanitize.beans.[*].properties.sanitizeSecretNameTwo")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
webClient.get()
.uri("http://localhost:{port}/actuator/configprops", this.port)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("contexts.sanitize.beans.[*].properties.sanitizeSecretNameTwo")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
// secret is usable from configuration properties
webClient.get().uri("http://localhost:{port}/secret", this.port).exchange().expectStatus().isOk()
.expectBody().jsonPath("$").isEqualTo("sanitizeSecretValue");
webClient.get()
.uri("http://localhost:{port}/secret", this.port)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("$")
.isEqualTo("sanitizeSecretValue");
// configmap is usable from configuration properties
webClient.get().uri("http://localhost:{port}/configmap", this.port).exchange().expectStatus().isOk()
.expectBody().jsonPath("$").isEqualTo("sanitizeConfigMapValue");
webClient.get()
.uri("http://localhost:{port}/configmap", this.port)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("$")
.isEqualTo("sanitizeConfigMapValue");
}
}

View File

@@ -47,24 +47,46 @@ class ConfigDataKubernetesClientSanitizeEnvEndpointTests {
@Test
void test() {
// configmap is sanitized
webClient.get().uri("http://localhost:{port}/actuator/env", this.port).accept(MediaType.APPLICATION_JSON)
.exchange().expectStatus().isOk().expectBody()
.jsonPath("propertySources.[*].properties.['sanitize.sanitizeConfigMapName'].value")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
webClient.get()
.uri("http://localhost:{port}/actuator/env", this.port)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("propertySources.[*].properties.['sanitize.sanitizeConfigMapName'].value")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
// secret is sanitized
webClient.get().uri("http://localhost:{port}/actuator/env", this.port).accept(MediaType.APPLICATION_JSON)
.exchange().expectStatus().isOk().expectBody()
.jsonPath("propertySources.[*].properties.['sanitize.sanitizeSecretName'].value")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
webClient.get()
.uri("http://localhost:{port}/actuator/env", this.port)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("propertySources.[*].properties.['sanitize.sanitizeSecretName'].value")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
// secret is usable from configuration properties
webClient.get().uri("http://localhost:{port}/secret", this.port).exchange().expectStatus().isOk()
.expectBody().jsonPath("$").isEqualTo("sanitizeSecretValue");
webClient.get()
.uri("http://localhost:{port}/secret", this.port)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("$")
.isEqualTo("sanitizeSecretValue");
// configmap is usable from configuration properties
webClient.get().uri("http://localhost:{port}/configmap", this.port).exchange().expectStatus().isOk()
.expectBody().jsonPath("$").isEqualTo("sanitizeConfigMapValue");
webClient.get()
.uri("http://localhost:{port}/configmap", this.port)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("$")
.isEqualTo("sanitizeConfigMapValue");
}
}
@@ -86,24 +108,46 @@ class ConfigDataKubernetesClientSanitizeEnvEndpointTests {
@Test
void test() {
// configmap is sanitized
webClient.get().uri("http://localhost:{port}/actuator/env", this.port).accept(MediaType.APPLICATION_JSON)
.exchange().expectStatus().isOk().expectBody()
.jsonPath("propertySources.[*].properties.['sanitize.sanitizeConfigMapName'].value")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
webClient.get()
.uri("http://localhost:{port}/actuator/env", this.port)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("propertySources.[*].properties.['sanitize.sanitizeConfigMapName'].value")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
// secret is sanitized
webClient.get().uri("http://localhost:{port}/actuator/env", this.port).accept(MediaType.APPLICATION_JSON)
.exchange().expectStatus().isOk().expectBody()
.jsonPath("propertySources.[*].properties.['sanitize.sanitizeSecretName'].value")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
webClient.get()
.uri("http://localhost:{port}/actuator/env", this.port)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("propertySources.[*].properties.['sanitize.sanitizeSecretName'].value")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
// secret is usable from configuration properties
webClient.get().uri("http://localhost:{port}/secret", this.port).exchange().expectStatus().isOk()
.expectBody().jsonPath("$").isEqualTo("sanitizeSecretValue");
webClient.get()
.uri("http://localhost:{port}/secret", this.port)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("$")
.isEqualTo("sanitizeSecretValue");
// configmap is usable from configuration properties
webClient.get().uri("http://localhost:{port}/configmap", this.port).exchange().expectStatus().isOk()
.expectBody().jsonPath("$").isEqualTo("sanitizeConfigMapValue");
webClient.get()
.uri("http://localhost:{port}/configmap", this.port)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("$")
.isEqualTo("sanitizeConfigMapValue");
}
}
@@ -135,24 +179,46 @@ class ConfigDataKubernetesClientSanitizeEnvEndpointTests {
@Test
void test() {
// configmap is not sanitized
webClient.get().uri("http://localhost:{port}/actuator/env", this.port).accept(MediaType.APPLICATION_JSON)
.exchange().expectStatus().isOk().expectBody()
.jsonPath("propertySources.[*].properties.['sanitize.sanitizeConfigMapName'].value")
.isEqualTo("sanitizeConfigMapValue");
webClient.get()
.uri("http://localhost:{port}/actuator/env", this.port)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("propertySources.[*].properties.['sanitize.sanitizeConfigMapName'].value")
.isEqualTo("sanitizeConfigMapValue");
// secret is not sanitized
webClient.get().uri("http://localhost:{port}/actuator/env", this.port).accept(MediaType.APPLICATION_JSON)
.exchange().expectStatus().isOk().expectBody()
.jsonPath("propertySources.[*].properties.['sanitize.sanitizeSecretName'].value")
.isEqualTo("sanitizeSecretValue");
webClient.get()
.uri("http://localhost:{port}/actuator/env", this.port)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("propertySources.[*].properties.['sanitize.sanitizeSecretName'].value")
.isEqualTo("sanitizeSecretValue");
// secret is usable from configuration properties
webClient.get().uri("http://localhost:{port}/secret", this.port).exchange().expectStatus().isOk()
.expectBody().jsonPath("$").isEqualTo("sanitizeSecretValue");
webClient.get()
.uri("http://localhost:{port}/secret", this.port)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("$")
.isEqualTo("sanitizeSecretValue");
// configmap is usable from configuration properties
webClient.get().uri("http://localhost:{port}/configmap", this.port).exchange().expectStatus().isOk()
.expectBody().jsonPath("$").isEqualTo("sanitizeConfigMapValue");
webClient.get()
.uri("http://localhost:{port}/configmap", this.port)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("$")
.isEqualTo("sanitizeConfigMapValue");
}
}
@@ -184,30 +250,57 @@ class ConfigDataKubernetesClientSanitizeEnvEndpointTests {
@Test
void test() {
// configmap is not sanitized
webClient.get().uri("http://localhost:{port}/actuator/env", this.port).accept(MediaType.APPLICATION_JSON)
.exchange().expectStatus().isOk().expectBody()
.jsonPath("propertySources.[*].properties.['sanitize.sanitizeConfigMapName'].value")
.isEqualTo("sanitizeConfigMapValue");
webClient.get()
.uri("http://localhost:{port}/actuator/env", this.port)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("propertySources.[*].properties.['sanitize.sanitizeConfigMapName'].value")
.isEqualTo("sanitizeConfigMapValue");
// first secret is sanitized
webClient.get().uri("http://localhost:{port}/actuator/env", this.port).accept(MediaType.APPLICATION_JSON)
.exchange().expectStatus().isOk().expectBody()
.jsonPath("propertySources.[*].properties.['sanitize.sanitizeSecretName'].value")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
webClient.get()
.uri("http://localhost:{port}/actuator/env", this.port)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("propertySources.[*].properties.['sanitize.sanitizeSecretName'].value")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
// second secret is sanitized
webClient.get().uri("http://localhost:{port}/actuator/env", this.port).accept(MediaType.APPLICATION_JSON)
.exchange().expectStatus().isOk().expectBody()
.jsonPath("propertySources.[*].properties.['sanitize.sanitizeSecretNameTwo'].value")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
webClient.get()
.uri("http://localhost:{port}/actuator/env", this.port)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("propertySources.[*].properties.['sanitize.sanitizeSecretNameTwo'].value")
.isEqualTo(SanitizableData.SANITIZED_VALUE);
// secret is usable from configuration properties
webClient.get().uri("http://localhost:{port}/secret", this.port).exchange().expectStatus().isOk()
.expectBody().jsonPath("$").isEqualTo("sanitizeSecretValue");
webClient.get()
.uri("http://localhost:{port}/secret", this.port)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("$")
.isEqualTo("sanitizeSecretValue");
// configmap is usable from configuration properties
webClient.get().uri("http://localhost:{port}/configmap", this.port).exchange().expectStatus().isOk()
.expectBody().jsonPath("$").isEqualTo("sanitizeConfigMapValue");
webClient.get()
.uri("http://localhost:{port}/configmap", this.port)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("$")
.isEqualTo("sanitizeConfigMapValue");
}
}

View File

@@ -44,10 +44,10 @@ abstract class ConfigDataSanitize {
WireMock.configureFor("localhost", server.port());
clientUtilsMock = mockStatic(KubernetesClientUtils.class);
clientUtilsMock.when(KubernetesClientUtils::kubernetesApiClient)
.thenReturn(new ClientBuilder().setBasePath(server.baseUrl()).build());
.thenReturn(new ClientBuilder().setBasePath(server.baseUrl()).build());
clientUtilsMock
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn("test");
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn("test");
stubData();
}

View File

@@ -79,7 +79,7 @@ public class SecretsEnableRetryWithoutFailFastTest {
clientUtilsMock = mockStatic(KubernetesClientUtils.class);
clientUtilsMock.when(KubernetesClientUtils::kubernetesApiClient)
.thenReturn(new ClientBuilder().setBasePath(wireMockServer.baseUrl()).build());
.thenReturn(new ClientBuilder().setBasePath(wireMockServer.baseUrl()).build());
stubConfigMapAndSecretsDefaults();
}
@@ -87,7 +87,7 @@ public class SecretsEnableRetryWithoutFailFastTest {
// return empty config map / secret list to not fail context creation
stubFor(get(API).willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(new V1ConfigMapList()))));
stubFor(get(SECRETS_API)
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(new V1SecretList()))));
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(new V1SecretList()))));
}
@AfterAll
@@ -108,7 +108,9 @@ public class SecretsEnableRetryWithoutFailFastTest {
ConfigurationPropertiesRebinderAutoConfiguration.class, KubernetesClientBootstrapConfiguration.class,
KubernetesClientRetryBootstrapConfiguration.class, KubernetesBootstrapConfiguration.class,
KubernetesClientConfigReloadAutoConfiguration.class)
.web(org.springframework.boot.WebApplicationType.NONE).properties(envArray).run();
.web(org.springframework.boot.WebApplicationType.NONE)
.properties(envArray)
.run();
}
@AfterEach

View File

@@ -68,7 +68,7 @@ class SecretsFailFastDisabled {
clientUtilsMock = mockStatic(KubernetesClientUtils.class);
clientUtilsMock.when(KubernetesClientUtils::kubernetesApiClient)
.thenReturn(new ClientBuilder().setBasePath(wireMockServer.baseUrl()).build());
.thenReturn(new ClientBuilder().setBasePath(wireMockServer.baseUrl()).build());
stubConfigMapAndSecretsDefaults();
}

View File

@@ -75,10 +75,10 @@ class SecretsFailFastEnabledButRetryDisabled {
clientUtilsMock = mockStatic(KubernetesClientUtils.class);
clientUtilsMock.when(KubernetesClientUtils::kubernetesApiClient)
.thenReturn(new ClientBuilder().setBasePath(wireMockServer.baseUrl()).build());
.thenReturn(new ClientBuilder().setBasePath(wireMockServer.baseUrl()).build());
clientUtilsMock
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn("default");
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn("default");
stubConfigMapAndSecretsDefaults();
}
@@ -86,7 +86,7 @@ class SecretsFailFastEnabledButRetryDisabled {
// return empty config map / secret list to not fail context creation
stubFor(get(API).willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(new V1SecretList()))));
stubFor(get(CONFIG_MAPS_API)
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(new V1ConfigMapList()))));
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(new V1ConfigMapList()))));
}
@AfterAll
@@ -114,7 +114,8 @@ class SecretsFailFastEnabledButRetryDisabled {
assertThat(context.containsBean("kubernetesSecretsRetryInterceptor")).isFalse();
assertThatThrownBy(() -> propertySourceLocator.locate(new MockEnvironment()))
.isInstanceOf(IllegalStateException.class).hasMessage("Internal Server Error");
.isInstanceOf(IllegalStateException.class)
.hasMessage("Internal Server Error");
// verify that propertySourceLocator.locate is called only once
verify(propertySourceLocator, times(1)).locate(any());

View File

@@ -74,10 +74,10 @@ class SecretsRetryDisabledButConfigRetryEnabled {
clientUtilsMock = mockStatic(KubernetesClientUtils.class);
clientUtilsMock.when(KubernetesClientUtils::kubernetesApiClient)
.thenReturn(new ClientBuilder().setBasePath(wireMockServer.baseUrl()).build());
.thenReturn(new ClientBuilder().setBasePath(wireMockServer.baseUrl()).build());
clientUtilsMock
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn("default");
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn("default");
stubConfigMapAndSecretsDefaults();
}
@@ -85,7 +85,7 @@ class SecretsRetryDisabledButConfigRetryEnabled {
// return empty config map / secret list to not fail context creation
stubFor(get(API).willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(new V1SecretList()))));
stubFor(get(CONFIG_MAPS_API)
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(new V1ConfigMapList()))));
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(new V1ConfigMapList()))));
}
@AfterAll
@@ -121,7 +121,8 @@ class SecretsRetryDisabledButConfigRetryEnabled {
// TODO not in bootstrap
// assertThat(context.containsBean("kubernetesSecretsRetryInterceptor")).isTrue();
assertThatThrownBy(() -> propertySourceLocator.locate(new MockEnvironment()))
.isInstanceOf(IllegalStateException.class).hasMessage("Internal Server Error");
.isInstanceOf(IllegalStateException.class)
.hasMessage("Internal Server Error");
// verify that propertySourceLocator.locate is called only once
verify(propertySourceLocator, times(1)).locate(any());

View File

@@ -78,10 +78,10 @@ class SecretsRetryEnabled {
clientUtilsMock = mockStatic(KubernetesClientUtils.class);
clientUtilsMock.when(KubernetesClientUtils::kubernetesApiClient)
.thenReturn(new ClientBuilder().setBasePath(wireMockServer.baseUrl()).build());
.thenReturn(new ClientBuilder().setBasePath(wireMockServer.baseUrl()).build());
clientUtilsMock
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn("default");
.when(() -> KubernetesClientUtils.getApplicationNamespace(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn("default");
stubConfigMapAndSecretsDefaults();
}
@@ -113,12 +113,12 @@ class SecretsRetryEnabled {
data.put("some.sensitive.number", "1".getBytes());
V1SecretList secretList = new V1SecretList()
.addItemsItem(new V1Secret().metadata(new V1ObjectMeta().name("my-secret")).data(data));
.addItemsItem(new V1Secret().metadata(new V1ObjectMeta().name("my-secret")).data(data));
stubFor(get(API).willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(secretList))));
PropertySource<?> propertySource = Assertions
.assertDoesNotThrow(() -> propertySourceLocator.locate(new MockEnvironment()));
.assertDoesNotThrow(() -> propertySourceLocator.locate(new MockEnvironment()));
// verify locate is called only once
WireMock.verify(1, getRequestedFor(urlEqualTo(API)));
@@ -136,24 +136,31 @@ class SecretsRetryEnabled {
data.put("some.sensitive.number", "1".getBytes());
V1SecretList secretList = new V1SecretList()
.addItemsItem(new V1Secret().metadata(new V1ObjectMeta().name("my-secret")).data(data));
.addItemsItem(new V1Secret().metadata(new V1ObjectMeta().name("my-secret")).data(data));
// fail 3 times
stubFor(get(API).inScenario("Retry and Recover").whenScenarioStateIs(STARTED)
.willReturn(aResponse().withStatus(500)).willSetStateTo("Failed once"));
stubFor(get(API).inScenario("Retry and Recover")
.whenScenarioStateIs(STARTED)
.willReturn(aResponse().withStatus(500))
.willSetStateTo("Failed once"));
stubFor(get(API).inScenario("Retry and Recover").whenScenarioStateIs("Failed once")
.willReturn(aResponse().withStatus(500)).willSetStateTo("Failed twice"));
stubFor(get(API).inScenario("Retry and Recover")
.whenScenarioStateIs("Failed once")
.willReturn(aResponse().withStatus(500))
.willSetStateTo("Failed twice"));
stubFor(get(API).inScenario("Retry and Recover").whenScenarioStateIs("Failed twice")
.willReturn(aResponse().withStatus(500)).willSetStateTo("Failed thrice"));
stubFor(get(API).inScenario("Retry and Recover")
.whenScenarioStateIs("Failed twice")
.willReturn(aResponse().withStatus(500))
.willSetStateTo("Failed thrice"));
// then succeed
stubFor(get(API).inScenario("Retry and Recover").whenScenarioStateIs("Failed thrice")
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(secretList))));
stubFor(get(API).inScenario("Retry and Recover")
.whenScenarioStateIs("Failed thrice")
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(secretList))));
PropertySource<?> propertySource = Assertions
.assertDoesNotThrow(() -> propertySourceLocator.locate(new MockEnvironment()));
.assertDoesNotThrow(() -> propertySourceLocator.locate(new MockEnvironment()));
// verify retried 4 times
WireMock.verify(4, getRequestedFor(urlEqualTo(API)));
@@ -170,7 +177,8 @@ class SecretsRetryEnabled {
stubFor(get(API).willReturn(aResponse().withStatus(500).withBody("Internal Server Error")));
assertThatThrownBy(() -> propertySourceLocator.locate(new MockEnvironment()))
.isInstanceOf(IllegalStateException.class).hasMessage("Internal Server Error");
.isInstanceOf(IllegalStateException.class)
.hasMessage("Internal Server Error");
// verify retried 5 times until failure
WireMock.verify(5, getRequestedFor(urlEqualTo(API)));

View File

@@ -33,8 +33,8 @@ import org.springframework.context.annotation.Conditional;
* Conditional that is resolved to active when either
* {@link ConditionalOnBlockingDiscoveryEnabled} or
* {@link ConditionalOnReactiveDiscoveryEnabled} matches.
* @deprecated in favor of {@link ConditionalOnBlockingOrReactiveDiscoveryEnabled}
*
* @deprecated in favor of {@link ConditionalOnBlockingOrReactiveDiscoveryEnabled}
* @author wind57
*/
@Target({ ElementType.TYPE, ElementType.METHOD })

View File

@@ -42,7 +42,8 @@ public final class ConditionalOnSelectiveNamespacesMissing implements Configurat
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
Set<String> selectiveNamespaces = Binder.get(context.getEnvironment())
.bind("spring.cloud.kubernetes.discovery.namespaces", Bindable.setOf(String.class)).orElse(Set.of());
.bind("spring.cloud.kubernetes.discovery.namespaces", Bindable.setOf(String.class))
.orElse(Set.of());
boolean selectiveNamespacesMissing = selectiveNamespaces.isEmpty();
if (selectiveNamespacesMissing) {
LOG.debug(() -> "selective namespaces not present");

View File

@@ -42,7 +42,8 @@ public final class ConditionalOnSelectiveNamespacesPresent implements Configurat
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
Set<String> selectiveNamespaces = Binder.get(context.getEnvironment())
.bind("spring.cloud.kubernetes.discovery.namespaces", Bindable.setOf(String.class)).orElse(Set.of());
.bind("spring.cloud.kubernetes.discovery.namespaces", Bindable.setOf(String.class))
.orElse(Set.of());
boolean selectiveNamespacesPresent = !selectiveNamespaces.isEmpty();
if (selectiveNamespacesPresent) {
LOG.debug(() -> "found selective namespaces : " + selectiveNamespaces.stream().sorted().toList());

View File

@@ -60,19 +60,24 @@ final class K8sInstanceIdHostPodNameSupplier implements Supplier<InstanceIdHostP
// instanceId is usually the pod-uid as seen in the .metadata.uid
private String instanceId() {
return Optional.ofNullable(endpointAddress).map(V1EndpointAddress::getTargetRef).map(V1ObjectReference::getUid)
.orElseGet(() -> service.getMetadata().getUid());
return Optional.ofNullable(endpointAddress)
.map(V1EndpointAddress::getTargetRef)
.map(V1ObjectReference::getUid)
.orElseGet(() -> service.getMetadata().getUid());
}
private String host() {
return Optional.ofNullable(endpointAddress).map(V1EndpointAddress::getIp)
.orElseGet(() -> service.getSpec().getExternalName());
return Optional.ofNullable(endpointAddress)
.map(V1EndpointAddress::getIp)
.orElseGet(() -> service.getSpec().getExternalName());
}
private String podName() {
return Optional.ofNullable(endpointAddress).map(V1EndpointAddress::getTargetRef)
.filter(objectReference -> "Pod".equals(objectReference.getKind())).map(V1ObjectReference::getName)
.orElse(null);
return Optional.ofNullable(endpointAddress)
.map(V1EndpointAddress::getTargetRef)
.filter(objectReference -> "Pod".equals(objectReference.getKind()))
.map(V1ObjectReference::getName)
.orElse(null);
}
}

View File

@@ -66,7 +66,7 @@ final class K8sPodLabelsAndAnnotationsSupplier implements Function<String, PodLa
try {
objectMeta = Optional.ofNullable(coreV1Api.readNamespacedPod(podName, namespace, null).getMetadata())
.orElse(new V1ObjectMetaBuilder().withLabels(Map.of()).withAnnotations(Map.of()).build());
.orElse(new V1ObjectMetaBuilder().withLabels(Map.of()).withAnnotations(Map.of()).build());
}
catch (ApiException e) {
LOG.warn(e, "Could not get pod metadata");

View File

@@ -81,19 +81,19 @@ class KubernetesClientConfigServerBootstrapper extends KubernetesConfigServerBoo
ApiClient apiClient = context.getOrElseSupply(ApiClient.class, () -> defaultApiClient);
KubernetesNamespaceProvider kubernetesNamespaceProvider = clientAutoConfiguration
.kubernetesNamespaceProvider(getNamespaceEnvironment(propertyResolver));
.kubernetesNamespaceProvider(getNamespaceEnvironment(propertyResolver));
KubernetesDiscoveryProperties discoveryProperties = context.get(KubernetesDiscoveryProperties.class);
String namespace = getInformerNamespace(kubernetesNamespaceProvider, discoveryProperties);
SharedInformerFactory sharedInformerFactory = new SharedInformerFactory(apiClient);
GenericKubernetesApi<V1Service, V1ServiceList> servicesApi = new GenericKubernetesApi<>(V1Service.class,
V1ServiceList.class, "", "v1", "services", apiClient);
SharedIndexInformer<V1Service> serviceSharedIndexInformer = sharedInformerFactory
.sharedIndexInformerFor(servicesApi, V1Service.class, 0L, namespace);
.sharedIndexInformerFor(servicesApi, V1Service.class, 0L, namespace);
Lister<V1Service> serviceLister = new Lister<>(serviceSharedIndexInformer.getIndexer());
GenericKubernetesApi<V1Endpoints, V1EndpointsList> endpointsApi = new GenericKubernetesApi<>(
V1Endpoints.class, V1EndpointsList.class, "", "v1", "endpoints", apiClient);
SharedIndexInformer<V1Endpoints> endpointsSharedIndexInformer = sharedInformerFactory
.sharedIndexInformerFor(endpointsApi, V1Endpoints.class, 0L, namespace);
.sharedIndexInformerFor(endpointsApi, V1Endpoints.class, 0L, namespace);
Lister<V1Endpoints> endpointsLister = new Lister<>(endpointsSharedIndexInformer.getIndexer());
KubernetesInformerDiscoveryClient discoveryClient = new KubernetesInformerDiscoveryClient(
sharedInformerFactory, serviceLister, endpointsLister, serviceSharedIndexInformer,

View File

@@ -101,7 +101,7 @@ public class KubernetesClientInformerSelectiveNamespacesAutoConfiguration {
GenericKubernetesApi<V1Service, V1ServiceList> servicesApi = new GenericKubernetesApi<>(V1Service.class,
V1ServiceList.class, "", "v1", "services", apiClient);
SharedIndexInformer<V1Service> sharedIndexInformer = sharedInformerFactories.get(i)
.sharedIndexInformerFor(servicesApi, V1Service.class, 0L, selectiveNamespaces.get(i));
.sharedIndexInformerFor(servicesApi, V1Service.class, 0L, selectiveNamespaces.get(i));
serviceSharedIndexedInformers.add(sharedIndexInformer);
}
return serviceSharedIndexedInformers;
@@ -138,7 +138,7 @@ public class KubernetesClientInformerSelectiveNamespacesAutoConfiguration {
GenericKubernetesApi<V1Endpoints, V1EndpointsList> endpointsApi = new GenericKubernetesApi<>(
V1Endpoints.class, V1EndpointsList.class, "", "v1", "endpoints", apiClient);
SharedIndexInformer<V1Endpoints> sharedIndexInformer = sharedInformerFactories.get(i)
.sharedIndexInformerFor(endpointsApi, V1Endpoints.class, 0L, selectiveNamespaces.get(i));
.sharedIndexInformerFor(endpointsApi, V1Endpoints.class, 0L, selectiveNamespaces.get(i));
endpointsSharedIndexedInformers.add(sharedIndexInformer);
}
return endpointsSharedIndexedInformers;

View File

@@ -57,7 +57,8 @@ final class KubernetesDiscoveryClientUtils {
private static final SpelExpressionParser PARSER = new SpelExpressionParser();
private static final SimpleEvaluationContext EVALUATION_CONTEXT = SimpleEvaluationContext.forReadOnlyDataBinding()
.withInstanceMethods().build();
.withInstanceMethods()
.build();
private KubernetesDiscoveryClientUtils() {
@@ -66,8 +67,9 @@ final class KubernetesDiscoveryClientUtils {
static boolean matchesServiceLabels(V1Service service, KubernetesDiscoveryProperties properties) {
Map<String, String> propertiesServiceLabels = properties.serviceLabels();
Map<String, String> serviceLabels = Optional.ofNullable(service.getMetadata()).map(V1ObjectMeta::getLabels)
.orElse(Map.of());
Map<String, String> serviceLabels = Optional.ofNullable(service.getMetadata())
.map(V1ObjectMeta::getLabels)
.orElse(Map.of());
if (propertiesServiceLabels.isEmpty()) {
LOG.debug(() -> "service labels from properties are empty, service with name : '"
@@ -142,16 +144,17 @@ final class KubernetesDiscoveryClientUtils {
*/
static Map<String, Integer> endpointSubsetsPortData(List<V1EndpointSubset> endpointSubsets) {
return endpointSubsets.stream()
.flatMap(endpointSubset -> Optional.ofNullable(endpointSubset.getPorts()).orElse(List.of()).stream())
.collect(Collectors.toMap(
endpointPort -> hasText(endpointPort.getName()) ? endpointPort.getName() : UNSET_PORT_NAME,
CoreV1EndpointPort::getPort));
.flatMap(endpointSubset -> Optional.ofNullable(endpointSubset.getPorts()).orElse(List.of()).stream())
.collect(Collectors.toMap(
endpointPort -> hasText(endpointPort.getName()) ? endpointPort.getName() : UNSET_PORT_NAME,
CoreV1EndpointPort::getPort));
}
static List<V1EndpointAddress> addresses(V1EndpointSubset endpointSubset,
KubernetesDiscoveryProperties properties) {
List<V1EndpointAddress> addresses = Optional.ofNullable(endpointSubset.getAddresses()).map(ArrayList::new)
.orElse(new ArrayList<>());
List<V1EndpointAddress> addresses = Optional.ofNullable(endpointSubset.getAddresses())
.map(ArrayList::new)
.orElse(new ArrayList<>());
if (properties.includeNotReadyAddresses()) {
List<V1EndpointAddress> notReadyAddresses = endpointSubset.getNotReadyAddresses();

View File

@@ -124,9 +124,13 @@ public class KubernetesInformerDiscoveryClient implements DiscoveryClient {
this.endpointsListers = endpointsListers;
this.informersReadyFunc = () -> {
boolean serviceInformersReady = serviceInformers.isEmpty() || serviceInformers.stream()
.map(SharedInformer::hasSynced).reduce(Boolean::logicalAnd).orElse(false);
.map(SharedInformer::hasSynced)
.reduce(Boolean::logicalAnd)
.orElse(false);
boolean endpointsInformersReady = endpointsInformers.isEmpty() || endpointsInformers.stream()
.map(SharedInformer::hasSynced).reduce(Boolean::logicalAnd).orElse(false);
.map(SharedInformer::hasSynced)
.reduce(Boolean::logicalAnd)
.orElse(false);
return serviceInformersReady && endpointsInformersReady;
};
@@ -144,18 +148,24 @@ public class KubernetesInformerDiscoveryClient implements DiscoveryClient {
public List<ServiceInstance> getInstances(String serviceId) {
Objects.requireNonNull(serviceId, "serviceId must be provided");
List<V1Service> allServices = serviceListers.stream().flatMap(x -> x.list().stream())
.filter(scv -> scv.getMetadata() != null).filter(svc -> serviceId.equals(svc.getMetadata().getName()))
.filter(scv -> matchesServiceLabels(scv, properties)).toList();
List<V1Service> allServices = serviceListers.stream()
.flatMap(x -> x.list().stream())
.filter(scv -> scv.getMetadata() != null)
.filter(svc -> serviceId.equals(svc.getMetadata().getName()))
.filter(scv -> matchesServiceLabels(scv, properties))
.toList();
List<ServiceInstance> serviceInstances = allServices.stream().filter(filter)
.flatMap(service -> serviceInstances(service, serviceId).stream())
.collect(Collectors.toCollection(ArrayList::new));
List<ServiceInstance> serviceInstances = allServices.stream()
.filter(filter)
.flatMap(service -> serviceInstances(service, serviceId).stream())
.collect(Collectors.toCollection(ArrayList::new));
if (properties.includeExternalNameServices()) {
LOG.debug(() -> "Searching for 'ExternalName' type of services with serviceId : " + serviceId);
List<V1Service> externalNameServices = allServices.stream().filter(s -> s.getSpec() != null)
.filter(s -> EXTERNAL_NAME.equals(s.getSpec().getType())).toList();
List<V1Service> externalNameServices = allServices.stream()
.filter(s -> s.getSpec() != null)
.filter(s -> EXTERNAL_NAME.equals(s.getSpec().getType()))
.toList();
for (V1Service service : externalNameServices) {
ServiceMetadata serviceMetadata = serviceMetadata(service);
Map<String, String> serviceInstanceMetadata = serviceInstanceMetadata(Map.of(), serviceMetadata,
@@ -178,8 +188,9 @@ public class KubernetesInformerDiscoveryClient implements DiscoveryClient {
List<ServiceInstance> instances = new ArrayList<>();
List<V1Endpoints> allEndpoints = endpointsListers.stream()
.map(endpointsLister -> endpointsLister.namespace(service.getMetadata().getNamespace()).get(serviceId))
.filter(Objects::nonNull).toList();
.map(endpointsLister -> endpointsLister.namespace(service.getMetadata().getNamespace()).get(serviceId))
.filter(Objects::nonNull)
.toList();
for (V1Endpoints endpoints : allEndpoints) {
List<V1EndpointSubset> subsets = endpoints.getSubsets();
@@ -218,9 +229,13 @@ public class KubernetesInformerDiscoveryClient implements DiscoveryClient {
@Override
public List<String> getServices() {
List<String> services = serviceListers.stream().flatMap(serviceLister -> serviceLister.list().stream())
.filter(service -> matchesServiceLabels(service, properties)).filter(filter)
.map(s -> s.getMetadata().getName()).distinct().toList();
List<String> services = serviceListers.stream()
.flatMap(serviceLister -> serviceLister.list().stream())
.filter(service -> matchesServiceLabels(service, properties))
.filter(filter)
.map(s -> s.getMetadata().getName())
.distinct()
.toList();
LOG.debug(() -> "will return services : " + services);
return services;
}

View File

@@ -101,7 +101,7 @@ class KubernetesCatalogWatch implements ApplicationEventPublisherAware {
CustomObjectsApi customObjectsApi = new CustomObjectsApi(apiClient);
try {
List<V1APIResource> resources = customObjectsApi.getAPIResources(DISCOVERY_GROUP, DISCOVERY_VERSION)
.getResources();
.getResources();
boolean found = resources.stream().map(V1APIResource::getKind).anyMatch(ENDPOINT_SLICE::equals);
if (!found) {
throw new IllegalArgumentException("EndpointSlices are not supported on the cluster");

View File

@@ -41,8 +41,10 @@ record KubernetesCatalogWatchContext(CoreV1Api coreV1Api, ApiClient apiClient, K
KubernetesNamespaceProvider namespaceProvider) {
static List<EndpointNameAndNamespace> state(Stream<V1ObjectReference> references) {
return references.filter(Objects::nonNull).map(x -> new EndpointNameAndNamespace(x.getName(), x.getNamespace()))
.sorted(Comparator.comparing(EndpointNameAndNamespace::endpointName, String::compareTo)).toList();
return references.filter(Objects::nonNull)
.map(x -> new EndpointNameAndNamespace(x.getName(), x.getNamespace()))
.sorted(Comparator.comparing(EndpointNameAndNamespace::endpointName, String::compareTo))
.toList();
}
static String labelSelector(Map<String, String> labels) {

View File

@@ -60,7 +60,9 @@ final class KubernetesEndpointSlicesCatalogWatch
else if (!context.properties().namespaces().isEmpty()) {
LOG.debug(() -> "discovering endpoint slices in " + context.properties().namespaces());
List<V1EndpointSlice> inner = new ArrayList<>(context.properties().namespaces().size());
context.properties().namespaces().forEach(namespace -> inner
context.properties()
.namespaces()
.forEach(namespace -> inner
.addAll(namespacedEndpointSlices(api, namespace, context.properties().serviceLabels())));
endpointSlices = inner;
}
@@ -71,8 +73,10 @@ final class KubernetesEndpointSlicesCatalogWatch
endpointSlices = namespacedEndpointSlices(api, namespace, context.properties().serviceLabels());
}
Stream<V1ObjectReference> references = endpointSlices.stream().map(V1EndpointSlice::getEndpoints)
.flatMap(List::stream).map(V1Endpoint::getTargetRef);
Stream<V1ObjectReference> references = endpointSlices.stream()
.map(V1EndpointSlice::getEndpoints)
.flatMap(List::stream)
.map(V1Endpoint::getTargetRef);
return KubernetesCatalogWatchContext.state(references);
@@ -80,8 +84,10 @@ final class KubernetesEndpointSlicesCatalogWatch
private List<V1EndpointSlice> endpointSlices(DiscoveryV1Api api, Map<String, String> labels) {
try {
return api.listEndpointSliceForAllNamespaces(null, null, null, labelSelector(labels), null, null, null,
null, null, null, null).getItems();
return api
.listEndpointSliceForAllNamespaces(null, null, null, labelSelector(labels), null, null, null, null,
null, null, null)
.getItems();
}
catch (ApiException e) {
LOG.warn(e, () -> "can not list endpoint slices in all namespaces");
@@ -92,8 +98,10 @@ final class KubernetesEndpointSlicesCatalogWatch
private List<V1EndpointSlice> namespacedEndpointSlices(DiscoveryV1Api api, String namespace,
Map<String, String> labels) {
try {
return api.listNamespacedEndpointSlice(namespace, null, null, null, null, labelSelector(labels), null, null,
null, null, null, null).getItems();
return api
.listNamespacedEndpointSlice(namespace, null, null, null, null, labelSelector(labels), null, null, null,
null, null, null)
.getItems();
}
catch (ApiException e) {
LOG.warn(e, () -> "can not list endpoint slices in namespace " + namespace);

View File

@@ -59,7 +59,9 @@ final class KubernetesEndpointsCatalogWatch
else if (!context.properties().namespaces().isEmpty()) {
LOG.debug(() -> "discovering endpoints in " + context.properties().namespaces());
List<V1Endpoints> inner = new ArrayList<>(context.properties().namespaces().size());
context.properties().namespaces().forEach(namespace -> inner
context.properties()
.namespaces()
.forEach(namespace -> inner
.addAll(namespacedEndpoints(coreV1Api, namespace, context.properties().serviceLabels())));
endpoints = inner;
}
@@ -80,9 +82,14 @@ final class KubernetesEndpointsCatalogWatch
* V1EndpointSubset::getAddresses and V1EndpointSubset::getPorts (each is a List)
* </pre>
*/
Stream<V1ObjectReference> references = endpoints.stream().map(V1Endpoints::getSubsets).filter(Objects::nonNull)
.flatMap(List::stream).map(V1EndpointSubset::getAddresses).filter(Objects::nonNull)
.flatMap(List::stream).map(V1EndpointAddress::getTargetRef);
Stream<V1ObjectReference> references = endpoints.stream()
.map(V1Endpoints::getSubsets)
.filter(Objects::nonNull)
.flatMap(List::stream)
.map(V1EndpointSubset::getAddresses)
.filter(Objects::nonNull)
.flatMap(List::stream)
.map(V1EndpointAddress::getTargetRef);
return KubernetesCatalogWatchContext.state(references);
@@ -90,8 +97,10 @@ final class KubernetesEndpointsCatalogWatch
private List<V1Endpoints> endpoints(CoreV1Api client, Map<String, String> labels) {
try {
return client.listEndpointsForAllNamespaces(null, null, null, labelSelector(labels), null, null, null, null,
null, null, null).getItems();
return client
.listEndpointsForAllNamespaces(null, null, null, labelSelector(labels), null, null, null, null, null,
null, null)
.getItems();
}
catch (ApiException e) {
LOG.warn(e, () -> "can not list endpoints in all namespaces");
@@ -101,8 +110,10 @@ final class KubernetesEndpointsCatalogWatch
private List<V1Endpoints> namespacedEndpoints(CoreV1Api client, String namespace, Map<String, String> labels) {
try {
return client.listNamespacedEndpoints(namespace, null, null, null, null, labelSelector(labels), null, null,
null, null, null, null).getItems();
return client
.listNamespacedEndpoints(namespace, null, null, null, null, labelSelector(labels), null, null, null,
null, null, null)
.getItems();
}
catch (ApiException e) {
LOG.warn(e, () -> "can not list endpoints in namespace " + namespace);

View File

@@ -64,13 +64,13 @@ public class KubernetesInformerReactiveDiscoveryClient implements ReactiveDiscov
public Flux<ServiceInstance> getInstances(String serviceId) {
Objects.requireNonNull(serviceId, "serviceId must be provided");
return Flux.defer(() -> Flux.fromIterable(kubernetesDiscoveryClient.getInstances(serviceId)))
.subscribeOn(Schedulers.boundedElastic());
.subscribeOn(Schedulers.boundedElastic());
}
@Override
public Flux<String> getServices() {
return Flux.defer(() -> Flux.fromIterable(kubernetesDiscoveryClient.getServices()))
.subscribeOn(Schedulers.boundedElastic());
.subscribeOn(Schedulers.boundedElastic());
}
}

View File

@@ -37,7 +37,8 @@ class K8sInstanceIdHostPodNameSupplierTests {
@Test
void instanceIdNoEndpointAddress() {
V1Service service = new V1ServiceBuilder().withSpec(new V1ServiceSpecBuilder().build())
.withMetadata(new V1ObjectMetaBuilder().withUid("123").build()).build();
.withMetadata(new V1ObjectMetaBuilder().withUid("123").build())
.build();
K8sInstanceIdHostPodNameSupplier supplier = K8sInstanceIdHostPodNameSupplier.externalName(service);
InstanceIdHostPodName result = supplier.get();
@@ -49,9 +50,11 @@ class K8sInstanceIdHostPodNameSupplierTests {
@Test
void instanceIdWithEndpointAddress() {
V1EndpointAddress endpointAddress = new V1EndpointAddressBuilder()
.withTargetRef(new V1ObjectReferenceBuilder().withUid("456").build()).build();
.withTargetRef(new V1ObjectReferenceBuilder().withUid("456").build())
.build();
V1Service service = new V1ServiceBuilder().withSpec(new V1ServiceSpecBuilder().build())
.withMetadata(new V1ObjectMetaBuilder().withUid("123").build()).build();
.withMetadata(new V1ObjectMetaBuilder().withUid("123").build())
.build();
K8sInstanceIdHostPodNameSupplier supplier = K8sInstanceIdHostPodNameSupplier.nonExternalName(endpointAddress,
service);
@@ -64,8 +67,9 @@ class K8sInstanceIdHostPodNameSupplierTests {
@Test
void hostNoEndpointAddress() {
V1Service service = new V1ServiceBuilder()
.withSpec(new V1ServiceSpecBuilder().withExternalName("external-name").build())
.withMetadata(new V1ObjectMeta()).build();
.withSpec(new V1ServiceSpecBuilder().withExternalName("external-name").build())
.withMetadata(new V1ObjectMeta())
.build();
K8sInstanceIdHostPodNameSupplier supplier = K8sInstanceIdHostPodNameSupplier.externalName(service);
InstanceIdHostPodName result = supplier.get();
@@ -78,8 +82,9 @@ class K8sInstanceIdHostPodNameSupplierTests {
void hostWithEndpointAddress() {
V1EndpointAddress endpointAddress = new V1EndpointAddressBuilder().withIp("127.0.0.1").build();
V1Service service = new V1ServiceBuilder()
.withSpec(new V1ServiceSpecBuilder().withExternalName("external-name").build())
.withMetadata(new V1ObjectMeta()).build();
.withSpec(new V1ServiceSpecBuilder().withExternalName("external-name").build())
.withMetadata(new V1ObjectMeta())
.build();
K8sInstanceIdHostPodNameSupplier supplier = K8sInstanceIdHostPodNameSupplier.nonExternalName(endpointAddress,
service);
@@ -92,7 +97,8 @@ class K8sInstanceIdHostPodNameSupplierTests {
@Test
void testPodNameIsNull() {
V1Service service = new V1ServiceBuilder().withMetadata(new V1ObjectMetaBuilder().withUid("123").build())
.withSpec(new V1ServiceSpecBuilder().withExternalName("external-name").build()).build();
.withSpec(new V1ServiceSpecBuilder().withExternalName("external-name").build())
.build();
K8sInstanceIdHostPodNameSupplier supplier = K8sInstanceIdHostPodNameSupplier.externalName(service);
InstanceIdHostPodName result = supplier.get();
@@ -103,10 +109,12 @@ class K8sInstanceIdHostPodNameSupplierTests {
@Test
void podNameKindNotPod() {
V1EndpointAddress endpointAddress = new V1EndpointAddressBuilder()
.withTargetRef(new V1ObjectReferenceBuilder().withKind("Service").build()).build();
.withTargetRef(new V1ObjectReferenceBuilder().withKind("Service").build())
.build();
V1Service service = new V1ServiceBuilder()
.withSpec(new V1ServiceSpecBuilder().withExternalName("external-name").build())
.withMetadata(new V1ObjectMeta()).build();
.withSpec(new V1ServiceSpecBuilder().withExternalName("external-name").build())
.withMetadata(new V1ObjectMeta())
.build();
K8sInstanceIdHostPodNameSupplier supplier = K8sInstanceIdHostPodNameSupplier.nonExternalName(endpointAddress,
service);
@@ -119,10 +127,12 @@ class K8sInstanceIdHostPodNameSupplierTests {
@Test
void podNameKindIsPod() {
V1EndpointAddress endpointAddress = new V1EndpointAddressBuilder()
.withTargetRef(new V1ObjectReferenceBuilder().withKind("Pod").withName("my-pod").build()).build();
.withTargetRef(new V1ObjectReferenceBuilder().withKind("Pod").withName("my-pod").build())
.build();
V1Service service = new V1ServiceBuilder()
.withSpec(new V1ServiceSpecBuilder().withExternalName("external-name").build())
.withMetadata(new V1ObjectMeta()).build();
.withSpec(new V1ServiceSpecBuilder().withExternalName("external-name").build())
.withMetadata(new V1ObjectMeta())
.build();
K8sInstanceIdHostPodNameSupplier supplier = K8sInstanceIdHostPodNameSupplier.nonExternalName(endpointAddress,
service);

View File

@@ -47,11 +47,11 @@ class K8sPodLabelsAndAnnotationsSupplierTests {
@Test
void noObjetMeta() throws Exception {
Mockito.when(coreV1Api.readNamespacedPod(POD_NAME, NAMESPACE, null)).thenReturn(
new V1PodBuilder().withMetadata(new V1ObjectMetaBuilder().withName(POD_NAME).build()).build());
Mockito.when(coreV1Api.readNamespacedPod(POD_NAME, NAMESPACE, null))
.thenReturn(new V1PodBuilder().withMetadata(new V1ObjectMetaBuilder().withName(POD_NAME).build()).build());
PodLabelsAndAnnotations result = K8sPodLabelsAndAnnotationsSupplier.nonExternalName(coreV1Api, NAMESPACE)
.apply(POD_NAME);
.apply(POD_NAME);
Assertions.assertNotNull(result);
Assertions.assertTrue(result.labels().isEmpty());
Assertions.assertTrue(result.annotations().isEmpty());
@@ -61,11 +61,15 @@ class K8sPodLabelsAndAnnotationsSupplierTests {
void labelsAndAnnotationsPresent() throws Exception {
Mockito.when(coreV1Api.readNamespacedPod(POD_NAME, NAMESPACE, null))
.thenReturn(new V1PodBuilder().withMetadata(new V1ObjectMetaBuilder().withName(POD_NAME)
.withLabels(Map.of("a", "b")).withAnnotations(Map.of("c", "d")).build()).build());
.thenReturn(new V1PodBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName(POD_NAME)
.withLabels(Map.of("a", "b"))
.withAnnotations(Map.of("c", "d"))
.build())
.build());
PodLabelsAndAnnotations result = K8sPodLabelsAndAnnotationsSupplier.nonExternalName(coreV1Api, NAMESPACE)
.apply(POD_NAME);
.apply(POD_NAME);
Assertions.assertNotNull(result);
Assertions.assertEquals(result.labels(), Map.of("a", "b"));
Assertions.assertEquals(result.annotations(), Map.of("c", "d"));

View File

@@ -83,29 +83,37 @@ class KubernetesClientConfigServerBootstrapperTests {
WireMock.configureFor(wireMockServer.port());
V1ServiceList SERVICE_LIST = new V1ServiceListBuilder()
.withMetadata(new V1ListMetaBuilder().withResourceVersion("1").build())
.addToItems(new V1ServiceBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("spring-cloud-kubernetes-configserver")
.withNamespace("default").withResourceVersion("0").addToLabels("beta", "true")
.addToAnnotations("org.springframework.cloud", "true").withUid("0").build())
.withSpec(new V1ServiceSpecBuilder().withClusterIP("localhost").withSessionAffinity("None")
.withType("ClusterIP")
.addToPorts(new V1ServicePortBuilder().withPort(wireMockServer.port()).withName("http")
.withProtocol("TCP").withNewTargetPort(wireMockServer.port()).build())
.build())
.withMetadata(new V1ListMetaBuilder().withResourceVersion("1").build())
.addToItems(new V1ServiceBuilder()
.withMetadata(new V1ObjectMetaBuilder().withName("spring-cloud-kubernetes-configserver")
.withNamespace("default")
.withResourceVersion("0")
.addToLabels("beta", "true")
.addToAnnotations("org.springframework.cloud", "true")
.withUid("0")
.build())
.withSpec(new V1ServiceSpecBuilder().withClusterIP("localhost")
.withSessionAffinity("None")
.withType("ClusterIP")
.addToPorts(new V1ServicePortBuilder().withPort(wireMockServer.port())
.withName("http")
.withProtocol("TCP")
.withNewTargetPort(wireMockServer.port())
.build())
.build();
.build())
.build())
.build();
V1EndpointsList ENDPOINTS_LIST = new V1EndpointsListBuilder()
.withMetadata(new V1ListMetaBuilder().withResourceVersion("0").build())
.addToItems(new V1Endpoints()
.metadata(new V1ObjectMeta().name("spring-cloud-kubernetes-configserver").namespace("default"))
.addSubsetsItem(
new V1EndpointSubset()
.addPortsItem(new CoreV1EndpointPort().port(wireMockServer.port()).name("http"))
.addAddressesItem(new V1EndpointAddress().hostname("localhost").ip("localhost")
.targetRef(new V1ObjectReferenceBuilder().withUid("uid1").build()))))
.build();
.withMetadata(new V1ListMetaBuilder().withResourceVersion("0").build())
.addToItems(new V1Endpoints()
.metadata(new V1ObjectMeta().name("spring-cloud-kubernetes-configserver").namespace("default"))
.addSubsetsItem(new V1EndpointSubset()
.addPortsItem(new CoreV1EndpointPort().port(wireMockServer.port()).name("http"))
.addAddressesItem(new V1EndpointAddress().hostname("localhost")
.ip("localhost")
.targetRef(new V1ObjectReferenceBuilder().withUid("uid1").build()))))
.build();
Environment environment = new Environment("test", "default");
Map<String, Object> properties = new HashMap<>();
@@ -113,19 +121,21 @@ class KubernetesClientConfigServerBootstrapperTests {
org.springframework.cloud.config.environment.PropertySource p = new PropertySource("p1", properties);
environment.add(p);
ObjectMapper objectMapper = new ObjectMapper();
stubFor(get("/application/default")
.willReturn(aResponse().withStatus(200).withBody(objectMapper.writeValueAsString(environment))
.withHeader("content-type", "application/json")));
stubFor(get("/application/default").willReturn(aResponse().withStatus(200)
.withBody(objectMapper.writeValueAsString(environment))
.withHeader("content-type", "application/json")));
stubFor(get("/api/v1/namespaces/default/endpoints?resourceVersion=0&watch=false")
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(ENDPOINTS_LIST))
.withHeader("content-type", "application/json")));
.willReturn(aResponse().withStatus(200)
.withBody(new JSON().serialize(ENDPOINTS_LIST))
.withHeader("content-type", "application/json")));
stubFor(get("/api/v1/namespaces/default/services?resourceVersion=0&watch=false")
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(SERVICE_LIST))
.withHeader("content-type", "application/json")));
.willReturn(aResponse().withStatus(200)
.withBody(new JSON().serialize(SERVICE_LIST))
.withHeader("content-type", "application/json")));
stubFor(get(urlMatching("/api/v1/namespaces/default/services.*.watch=true"))
.willReturn(aResponse().withStatus(200)));
.willReturn(aResponse().withStatus(200)));
stubFor(get(urlMatching("/api/v1/namespaces/default/endpoints.*.watch=true"))
.willReturn(aResponse().withStatus(200)));
.willReturn(aResponse().withStatus(200)));
}
@AfterEach
@@ -143,9 +153,10 @@ class KubernetesClientConfigServerBootstrapperTests {
SpringApplicationBuilder setup(String... env) {
SpringApplicationBuilder builder = new SpringApplicationBuilder(TestConfig.class)
.properties(addDefaultEnv(env));
.properties(addDefaultEnv(env));
ApiClient apiClient = new ClientBuilder().setBasePath("http://localhost:" + wireMockServer.port())
.setReadTimeout(Duration.ZERO).build();
.setReadTimeout(Duration.ZERO)
.build();
builder.addBootstrapRegistryInitializer(registry -> registry.register(ApiClient.class, (context) -> apiClient));
builder.addBootstrapRegistryInitializer(new KubernetesClientConfigServerBootstrapper());
return builder;

View File

@@ -54,44 +54,44 @@ class KubernetesClientInformerSelectiveNamespacesAutoConfigurationTests {
void testBeansCreates(CapturedOutput output) {
new ApplicationContextRunner()
.withPropertyValues("spring.cloud.discovery.enabled=true",
"spring.cloud.kubernetes.discovery.enabled=true",
"spring.cloud.kubernetes.discovery.namespaces[0]=" + NAMESPACE_A,
"spring.cloud.kubernetes.discovery.namespaces[1]=" + NAMESPACE_B,
"spring.main.cloud-platform=kubernetes")
.withConfiguration(
AutoConfigurations.of(KubernetesClientInformerSelectiveNamespacesAutoConfiguration.class))
.withUserConfiguration(Config.class).run(context -> {
assertThat(context.getBean("selectiveNamespaces")).isNotNull();
.withPropertyValues("spring.cloud.discovery.enabled=true", "spring.cloud.kubernetes.discovery.enabled=true",
"spring.cloud.kubernetes.discovery.namespaces[0]=" + NAMESPACE_A,
"spring.cloud.kubernetes.discovery.namespaces[1]=" + NAMESPACE_B,
"spring.main.cloud-platform=kubernetes")
.withConfiguration(
AutoConfigurations.of(KubernetesClientInformerSelectiveNamespacesAutoConfiguration.class))
.withUserConfiguration(Config.class)
.run(context -> {
assertThat(context.getBean("selectiveNamespaces")).isNotNull();
@SuppressWarnings("unchecked")
Set<String> selectiveNamespaces = context.getBean("selectiveNamespaces", Set.class);
Assertions.assertEquals(selectiveNamespaces, Set.of("a", "b"));
@SuppressWarnings("unchecked")
Set<String> selectiveNamespaces = context.getBean("selectiveNamespaces", Set.class);
Assertions.assertEquals(selectiveNamespaces, Set.of("a", "b"));
@SuppressWarnings("unchecked")
Set<String> namespaces = context.getBean("namespaces", Set.class);
Assertions.assertEquals(namespaces, Set.of("c", "d"));
});
@SuppressWarnings("unchecked")
Set<String> namespaces = context.getBean("namespaces", Set.class);
Assertions.assertEquals(namespaces, Set.of("c", "d"));
});
assertThat(output.getOut().contains("registering lister (for services) in namespace : " + NAMESPACE_A))
.isTrue();
.isTrue();
assertThat(output.getOut().contains("registering lister (for services) in namespace : " + NAMESPACE_B))
.isTrue();
.isTrue();
assertThat(output.getOut().contains("registering lister (for services) in namespace : " + NAMESPACE_C))
.isFalse();
.isFalse();
assertThat(output.getOut().contains("registering lister (for services) in namespace : " + NAMESPACE_D))
.isFalse();
.isFalse();
assertThat(output.getOut().contains("registering lister (for endpoints) in namespace : " + NAMESPACE_A))
.isTrue();
.isTrue();
assertThat(output.getOut().contains("registering lister (for endpoints) in namespace : " + NAMESPACE_B))
.isTrue();
.isTrue();
assertThat(output.getOut().contains("registering lister (for endpoints) in namespace : " + NAMESPACE_C))
.isFalse();
.isFalse();
assertThat(output.getOut().contains("registering lister (for endpoints) in namespace : " + NAMESPACE_D))
.isFalse();
.isFalse();
}
@Configuration

View File

@@ -70,8 +70,9 @@ class KubernetesDiscoveryClientAutoConfigurationTests {
assertThat(this.discoveryClient).isNotNull().isInstanceOf(CompositeDiscoveryClient.class);
CompositeDiscoveryClient composite = (CompositeDiscoveryClient) this.discoveryClient;
assertThat(composite.getDiscoveryClients().stream()
.anyMatch(dc -> dc instanceof KubernetesInformerDiscoveryClient)).isTrue();
assertThat(composite.getDiscoveryClients()
.stream()
.anyMatch(dc -> dc instanceof KubernetesInformerDiscoveryClient)).isTrue();
}
@SpringBootApplication
@@ -90,11 +91,15 @@ class KubernetesDiscoveryClientAutoConfigurationTests {
wireMockServer.start();
WireMock.configureFor(wireMockServer.port());
stubFor(get("/api/v1/namespaces/test/endpoints?resourceVersion=0&watch=false")
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(new V1EndpointsListBuilder()
.withMetadata(new V1ListMetaBuilder().withResourceVersion("0").build()).build()))));
.willReturn(aResponse().withStatus(200)
.withBody(new JSON().serialize(new V1EndpointsListBuilder()
.withMetadata(new V1ListMetaBuilder().withResourceVersion("0").build())
.build()))));
stubFor(get("/api/v1/namespaces/test/services?resourceVersion=0&watch=false")
.willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(new V1ServiceListBuilder()
.withMetadata(new V1ListMetaBuilder().withResourceVersion("0").build()).build()))));
.willReturn(aResponse().withStatus(200)
.withBody(new JSON().serialize(new V1ServiceListBuilder()
.withMetadata(new V1ListMetaBuilder().withResourceVersion("0").build())
.build()))));
return new ClientBuilder().setBasePath(wireMockServer.baseUrl()).build();
}

View File

@@ -235,9 +235,14 @@ class KubernetesDiscoveryClientFilterMetadataTest {
Map<Integer, String> ports) {
V1Service service = new V1ServiceBuilder()
.withSpec(new V1ServiceSpecBuilder().withType("ClusterIP").withPorts(getServicePorts(ports)).build())
.withNewMetadata().withName(serviceId).withNamespace(namespace).withLabels(labels)
.withAnnotations(annotations).endMetadata().build();
.withSpec(new V1ServiceSpecBuilder().withType("ClusterIP").withPorts(getServicePorts(ports)).build())
.withNewMetadata()
.withName(serviceId)
.withNamespace(namespace)
.withLabels(labels)
.withAnnotations(annotations)
.endMetadata()
.build();
servicesCache.add(service);
@@ -245,8 +250,13 @@ class KubernetesDiscoveryClientFilterMetadataTest {
objectMeta.setNamespace(namespace);
objectMeta.setName(serviceId);
V1Endpoints endpoints = new V1EndpointsBuilder().withMetadata(objectMeta).addNewSubset()
.addAllToPorts(getEndpointPorts(ports)).addNewAddress().endAddress().endSubset().build();
V1Endpoints endpoints = new V1EndpointsBuilder().withMetadata(objectMeta)
.addNewSubset()
.addAllToPorts(getEndpointPorts(ports))
.addNewAddress()
.endAddress()
.endSubset()
.build();
endpointsCache.add(endpoints);

View File

@@ -76,8 +76,10 @@ class KubernetesDiscoveryClientFilterTests {
List<V1Service> unfiltered = List.of(a, b);
Predicate<V1Service> predicate = KubernetesDiscoveryClientUtils.filter(properties);
List<V1Service> filtered = unfiltered.stream().filter(predicate)
.sorted(Comparator.comparing(service -> service.getMetadata().getName())).toList();
List<V1Service> filtered = unfiltered.stream()
.filter(predicate)
.sorted(Comparator.comparing(service -> service.getMetadata().getName()))
.toList();
Assertions.assertEquals(filtered.get(0).getMetadata().getName(), "a");
Assertions.assertEquals(filtered.get(1).getMetadata().getName(), "a");
}
@@ -96,8 +98,10 @@ class KubernetesDiscoveryClientFilterTests {
List<V1Service> unfiltered = List.of(a, b);
Predicate<V1Service> predicate = KubernetesDiscoveryClientUtils.filter(properties);
List<V1Service> filtered = unfiltered.stream().filter(predicate)
.sorted(Comparator.comparing(service -> service.getMetadata().getName())).toList();
List<V1Service> filtered = unfiltered.stream()
.filter(predicate)
.sorted(Comparator.comparing(service -> service.getMetadata().getName()))
.toList();
Assertions.assertEquals(filtered.size(), 0);
}
@@ -115,8 +119,10 @@ class KubernetesDiscoveryClientFilterTests {
List<V1Service> unfiltered = List.of(a, b);
Predicate<V1Service> predicate = KubernetesDiscoveryClientUtils.filter(properties);
List<V1Service> filtered = unfiltered.stream().filter(predicate)
.sorted(Comparator.comparing(service -> service.getMetadata().getName())).toList();
List<V1Service> filtered = unfiltered.stream()
.filter(predicate)
.sorted(Comparator.comparing(service -> service.getMetadata().getName()))
.toList();
Assertions.assertEquals(filtered.size(), 0);
}

View File

@@ -73,20 +73,18 @@ class KubernetesDiscoveryClientServiceWithoutPortNameTests {
void testDiscoveryWithoutAServicePortName() {
V1Endpoints endpoints = new V1EndpointsBuilder()
.withSubsets(
new V1EndpointSubsetBuilder().withPorts(new CoreV1EndpointPortBuilder().withPort(8080).build())
.withAddresses(new V1EndpointAddressBuilder().withIp("127.0.0.1").build()).build())
.withMetadata(
new V1ObjectMetaBuilder().withName("no-port-name-service").withNamespace(NAMESPACE).build())
.build();
.withSubsets(new V1EndpointSubsetBuilder().withPorts(new CoreV1EndpointPortBuilder().withPort(8080).build())
.withAddresses(new V1EndpointAddressBuilder().withIp("127.0.0.1").build())
.build())
.withMetadata(new V1ObjectMetaBuilder().withName("no-port-name-service").withNamespace(NAMESPACE).build())
.build();
endpointsCache.add(endpoints);
V1Service service = new V1ServiceBuilder()
.withSpec(
new V1ServiceSpecBuilder().withPorts(new V1ServicePortBuilder().withPort(8080).build()).build())
.withMetadata(
new V1ObjectMetaBuilder().withName("no-port-name-service").withNamespace(NAMESPACE).build())
.withSpec(new V1ServiceSpecBuilder().withType("ClusterIP").build()).build();
.withSpec(new V1ServiceSpecBuilder().withPorts(new V1ServicePortBuilder().withPort(8080).build()).build())
.withMetadata(new V1ObjectMetaBuilder().withName("no-port-name-service").withNamespace(NAMESPACE).build())
.withSpec(new V1ServiceSpecBuilder().withType("ClusterIP").build())
.build();
servicesCache.add(service);
KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, false, Set.of(NAMESPACE),

View File

@@ -97,8 +97,11 @@ class KubernetesDiscoveryClientTests {
List<ServiceInstance> instances = discoveryClient.getInstances("id");
assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && !s.isSecure()).hasSize(1)
.filteredOn(s -> s.getInstanceId().equals("10")).hasSize(1);
assertThat(instances).hasSize(1)
.filteredOn(s -> s.getHost().equals("ip1") && !s.isSecure())
.hasSize(1)
.filteredOn(s -> s.getInstanceId().equals("10"))
.hasSize(1);
}
@Test
@@ -124,9 +127,13 @@ class KubernetesDiscoveryClientTests {
List<ServiceInstance> instances = discoveryClient.getInstances("endpoint");
assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && !s.isSecure()).hasSize(1)
.filteredOn(s -> s.getInstanceId().equals("20")).hasSize(1).filteredOn(s -> 80 == s.getPort())
.hasSize(1);
assertThat(instances).hasSize(1)
.filteredOn(s -> s.getHost().equals("ip1") && !s.isSecure())
.hasSize(1)
.filteredOn(s -> s.getInstanceId().equals("20"))
.hasSize(1)
.filteredOn(s -> 80 == s.getPort())
.hasSize(1);
}
@Test
@@ -154,8 +161,10 @@ class KubernetesDiscoveryClientTests {
List<ServiceInstance> instances = discoveryClient.getInstances("endpoint");
assertThat(instances).hasSize(2).filteredOn(ServiceInstance::isSecure).extracting(ServiceInstance::getHost)
.containsOnly("ip1", "ip2");
assertThat(instances).hasSize(2)
.filteredOn(ServiceInstance::isSecure)
.extracting(ServiceInstance::getHost)
.containsOnly("ip1", "ip2");
}
@Test
@@ -191,22 +200,33 @@ class KubernetesDiscoveryClientTests {
assertThat(instances).hasSize(2);
assertThat(instances).filteredOn(s -> s.getHost().equals("ip1") && !s.isSecure()).hasSize(1);
assertThat(instances).filteredOn(s -> s.getHost().equals("ip2") && !s.isSecure()).hasSize(1);
assertThat(instances).filteredOn(s -> s.getServiceId().contains("endpoint")
&& ((KubernetesServiceInstance) s).getNamespace().equals("test")).hasSize(1);
assertThat(instances).filteredOn(s -> s.getServiceId().contains("endpoint")
&& ((KubernetesServiceInstance) s).getNamespace().equals("test2")).hasSize(1);
assertThat(instances)
.filteredOn(s -> s.getServiceId().contains("endpoint")
&& ((KubernetesServiceInstance) s).getNamespace().equals("test"))
.hasSize(1);
assertThat(instances)
.filteredOn(s -> s.getServiceId().contains("endpoint")
&& ((KubernetesServiceInstance) s).getNamespace().equals("test2"))
.hasSize(1);
assertThat(instances).filteredOn(s -> s.getInstanceId().equals("60")).hasSize(1);
assertThat(instances).filteredOn(s -> s.getInstanceId().equals("70")).hasSize(1);
}
@Test
void instanceWithoutSubsetsShouldBeSkipped() {
V1Endpoints endpoints = new V1EndpointsBuilder().withNewMetadata().withName("endpoint1").withNamespace("test")
.withLabels(Collections.emptyMap()).endMetadata().build();
V1Endpoints endpoints = new V1EndpointsBuilder().withNewMetadata()
.withName("endpoint1")
.withNamespace("test")
.withLabels(Collections.emptyMap())
.endMetadata()
.build();
endpointsCache.add(endpoints);
V1Service service = new V1ServiceBuilder().withNewMetadata().withName("endpoint1").withNamespace("test").and()
.build();
V1Service service = new V1ServiceBuilder().withNewMetadata()
.withName("endpoint1")
.withNamespace("test")
.and()
.build();
servicesCache.add(service);
KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60,
@@ -242,9 +262,13 @@ class KubernetesDiscoveryClientTests {
List<ServiceInstance> instances = discoveryClient.getInstances("endpoint2");
assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && s.isSecure()).hasSize(1)
.filteredOn(s -> s.getInstanceId().equals("80")).hasSize(1).filteredOn(s -> 443 == s.getPort())
.hasSize(1);
assertThat(instances).hasSize(1)
.filteredOn(s -> s.getHost().equals("ip1") && s.isSecure())
.hasSize(1)
.filteredOn(s -> s.getInstanceId().equals("80"))
.hasSize(1)
.filteredOn(s -> 443 == s.getPort())
.hasSize(1);
}
@Test
@@ -270,8 +294,12 @@ class KubernetesDiscoveryClientTests {
List<ServiceInstance> instances = discoveryClient.getInstances("endpoint3");
assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && s.isSecure()).hasSize(1)
.filteredOn(s -> s.getInstanceId().equals("90")).hasSize(1).hasSize(1);
assertThat(instances).hasSize(1)
.filteredOn(s -> s.getHost().equals("ip1") && s.isSecure())
.hasSize(1)
.filteredOn(s -> s.getInstanceId().equals("90"))
.hasSize(1)
.hasSize(1);
}
@Test
@@ -297,8 +325,12 @@ class KubernetesDiscoveryClientTests {
List<ServiceInstance> instances = discoveryClient.getInstances("endpoint4");
assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && s.isSecure()).hasSize(1)
.filteredOn(s -> s.getInstanceId().equals("100")).hasSize(1).hasSize(1);
assertThat(instances).hasSize(1)
.filteredOn(s -> s.getHost().equals("ip1") && s.isSecure())
.hasSize(1)
.filteredOn(s -> s.getInstanceId().equals("100"))
.hasSize(1)
.hasSize(1);
}
@Test
@@ -325,9 +357,13 @@ class KubernetesDiscoveryClientTests {
List<ServiceInstance> instances = discoveryClient.getInstances("endpoint5");
assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && s.isSecure()).hasSize(1)
.filteredOn(s -> s.getInstanceId().equals("110")).hasSize(1).filteredOn(s -> 443 == s.getPort())
.hasSize(1);
assertThat(instances).hasSize(1)
.filteredOn(s -> s.getHost().equals("ip1") && s.isSecure())
.hasSize(1)
.filteredOn(s -> s.getInstanceId().equals("110"))
.hasSize(1)
.filteredOn(s -> 443 == s.getPort())
.hasSize(1);
}
@Test
@@ -351,9 +387,13 @@ class KubernetesDiscoveryClientTests {
List<ServiceInstance> instances = discoveryClient.getInstances("endpoint5");
assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && !s.isSecure()).hasSize(1)
.filteredOn(s -> s.getInstanceId().equals("120")).hasSize(1).filteredOn(s -> 80 == s.getPort())
.hasSize(1);
assertThat(instances).hasSize(1)
.filteredOn(s -> s.getHost().equals("ip1") && !s.isSecure())
.hasSize(1)
.filteredOn(s -> s.getInstanceId().equals("120"))
.hasSize(1)
.filteredOn(s -> 80 == s.getPort())
.hasSize(1);
}
@Test
@@ -380,9 +420,13 @@ class KubernetesDiscoveryClientTests {
List<ServiceInstance> instances = discoveryClient.getInstances("endpoint5");
// We're returning the first discovered port to not change previous behaviour
assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && s.isSecure()).hasSize(1)
.filteredOn(s -> s.getInstanceId().equals("130")).hasSize(1).filteredOn(s -> 443 == s.getPort())
.hasSize(1);
assertThat(instances).hasSize(1)
.filteredOn(s -> s.getHost().equals("ip1") && s.isSecure())
.hasSize(1)
.filteredOn(s -> s.getInstanceId().equals("130"))
.hasSize(1)
.filteredOn(s -> 443 == s.getPort())
.hasSize(1);
}
@Test
@@ -408,10 +452,14 @@ class KubernetesDiscoveryClientTests {
List<ServiceInstance> instances = discoveryClient.getInstances("endpoint5");
// We're returning the first discovered port to not change previous behaviour
assertThat(instances).hasSize(1).filteredOn(s -> s.getHost().equals("ip1") && !s.isSecure()).hasSize(1)
.filteredOn(s -> s.getUri().toASCIIString().equals("http://ip1"))
.filteredOn(s -> s.getInstanceId().equals("130")).hasSize(1).filteredOn(s -> 0 == s.getPort())
.hasSize(1);
assertThat(instances).hasSize(1)
.filteredOn(s -> s.getHost().equals("ip1") && !s.isSecure())
.hasSize(1)
.filteredOn(s -> s.getUri().toASCIIString().equals("http://ip1"))
.filteredOn(s -> s.getInstanceId().equals("130"))
.hasSize(1)
.filteredOn(s -> 0 == s.getPort())
.hasSize(1);
}
private void setup(String serviceId, String serviceType, String namespace, Map<String, String> labels,
@@ -419,8 +467,12 @@ class KubernetesDiscoveryClientTests {
List<String> appProtocols) {
V1Service service = new V1ServiceBuilder().withSpec(new V1ServiceSpecBuilder().withType(serviceType).build())
.withNewMetadata().withName(serviceId).withNamespace(namespace).withLabels(labels).endMetadata()
.build();
.withNewMetadata()
.withName(serviceId)
.withNamespace(namespace)
.withLabels(labels)
.endMetadata()
.build();
servicesCache.add(service);
@@ -428,13 +480,20 @@ class KubernetesDiscoveryClientTests {
objectMeta.setNamespace(namespace);
objectMeta.setName(serviceId);
V1Endpoints endpoints = new V1EndpointsBuilder().withNewMetadata().withName(serviceId).withNamespace(namespace)
.withLabels(labels).endMetadata().build();
V1Endpoints endpoints = new V1EndpointsBuilder().withNewMetadata()
.withName(serviceId)
.withNamespace(namespace)
.withLabels(labels)
.endMetadata()
.build();
List<V1EndpointAddress> addresses = new ArrayList<>();
for (int i = 0; i < ips.size(); ++i) {
V1EndpointAddress address = new V1EndpointAddressBuilder().withIp(ips.get(i)).withNewTargetRef()
.withUid(uuids.get(i)).endTargetRef().build();
V1EndpointAddress address = new V1EndpointAddressBuilder().withIp(ips.get(i))
.withNewTargetRef()
.withUid(uuids.get(i))
.endTargetRef()
.build();
addresses.add(address);
}
@@ -444,7 +503,10 @@ class KubernetesDiscoveryClientTests {
List<CoreV1EndpointPort> corePorts = new ArrayList<>();
for (int i = 0; i < names.size(); ++i) {
CoreV1EndpointPort port = new CoreV1EndpointPortBuilder().withName(names.get(i))
.withProtocol(protocols.get(i)).withPort(ports.get(i)).withAppProtocol(appProtocols.get(i)).build();
.withProtocol(protocols.get(i))
.withPort(ports.get(i))
.withAppProtocol(appProtocols.get(i))
.build();
corePorts.add(port);
}
subset.setPorts(corePorts);

View File

@@ -58,7 +58,7 @@ class KubernetesDiscoveryClientUtilsTests {
boolean result = matchesServiceLabels(service, properties);
Assertions.assertTrue(result);
Assertions.assertTrue(output.getOut()
.contains("service labels from properties are empty, service with name : 'my-service' will match"));
.contains("service labels from properties are empty, service with name : 'my-service' will match"));
}
/**
@@ -91,7 +91,8 @@ class KubernetesDiscoveryClientUtilsTests {
KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L,
true, "", Set.of(), propertiesLabels, "", null, 0, false);
V1Service service = new V1ServiceBuilder()
.withMetadata(new V1ObjectMeta().labels(serviceLabels).name("my-service")).build();
.withMetadata(new V1ObjectMeta().labels(serviceLabels).name("my-service"))
.build();
boolean result = matchesServiceLabels(service, properties);
Assertions.assertTrue(result);
@@ -114,7 +115,8 @@ class KubernetesDiscoveryClientUtilsTests {
KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L,
true, "", Set.of(), propertiesLabels, "", null, 0, false);
V1Service service = new V1ServiceBuilder()
.withMetadata(new V1ObjectMeta().labels(serviceLabels).name("my-service")).build();
.withMetadata(new V1ObjectMeta().labels(serviceLabels).name("my-service"))
.build();
boolean result = matchesServiceLabels(service, properties);
Assertions.assertFalse(result);
@@ -137,7 +139,8 @@ class KubernetesDiscoveryClientUtilsTests {
KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L,
true, "", Set.of(), propertiesLabels, "", null, 0, false);
V1Service service = new V1ServiceBuilder()
.withMetadata(new V1ObjectMeta().labels(serviceLabels).name("my-service")).build();
.withMetadata(new V1ObjectMeta().labels(serviceLabels).name("my-service"))
.build();
boolean result = matchesServiceLabels(service, properties);
Assertions.assertTrue(result);
@@ -160,7 +163,8 @@ class KubernetesDiscoveryClientUtilsTests {
KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L,
true, "", Set.of(), propertiesLabels, "", null, 0, false);
V1Service service = new V1ServiceBuilder()
.withMetadata(new V1ObjectMeta().labels(serviceLabels).name("my-service")).build();
.withMetadata(new V1ObjectMeta().labels(serviceLabels).name("my-service"))
.build();
boolean result = matchesServiceLabels(service, properties);
Assertions.assertTrue(result);
@@ -172,9 +176,11 @@ class KubernetesDiscoveryClientUtilsTests {
void testPortsDataOne() {
List<V1EndpointSubset> endpointSubsets = List.of(
new V1EndpointSubsetBuilder()
.withPorts(new CoreV1EndpointPortBuilder().withPort(8081).withName("").build()).build(),
.withPorts(new CoreV1EndpointPortBuilder().withPort(8081).withName("").build())
.build(),
new V1EndpointSubsetBuilder()
.withPorts(new CoreV1EndpointPortBuilder().withPort(8080).withName("https").build()).build());
.withPorts(new CoreV1EndpointPortBuilder().withPort(8080).withName("https").build())
.build());
Map<String, Integer> portsData = endpointSubsetsPortData(endpointSubsets);
Assertions.assertEquals(portsData.size(), 2);
@@ -186,9 +192,11 @@ class KubernetesDiscoveryClientUtilsTests {
void testPortsDataTwo() {
List<V1EndpointSubset> endpointSubsets = List.of(
new V1EndpointSubsetBuilder()
.withPorts(new CoreV1EndpointPortBuilder().withPort(8081).withName("http").build()).build(),
.withPorts(new CoreV1EndpointPortBuilder().withPort(8081).withName("http").build())
.build(),
new V1EndpointSubsetBuilder()
.withPorts(new CoreV1EndpointPortBuilder().withPort(8080).withName("https").build()).build());
.withPorts(new CoreV1EndpointPortBuilder().withPort(8080).withName("https").build())
.build());
Map<String, Integer> portsData = endpointSubsetsPortData(endpointSubsets);
Assertions.assertEquals(portsData.size(), 2);
@@ -207,7 +215,8 @@ class KubernetesDiscoveryClientUtilsTests {
@Test
void endpointSubsetPortsDataSinglePort() {
V1EndpointSubset endpointSubset = new V1EndpointSubsetBuilder()
.withPorts(new CoreV1EndpointPortBuilder().withName("name").withPort(80).build()).build();
.withPorts(new CoreV1EndpointPortBuilder().withName("name").withPort(80).build())
.build();
Map<String, Integer> result = endpointSubsetsPortData(List.of(endpointSubset));
Assertions.assertEquals(result.size(), 1);
@@ -217,7 +226,8 @@ class KubernetesDiscoveryClientUtilsTests {
@Test
void endpointSubsetPortsDataSinglePortNoName() {
V1EndpointSubset endpointSubset = new V1EndpointSubsetBuilder()
.withPorts(new CoreV1EndpointPortBuilder().withPort(80).build()).build();
.withPorts(new CoreV1EndpointPortBuilder().withPort(80).build())
.build();
Map<String, Integer> result = endpointSubsetsPortData(List.of(endpointSubset));
Assertions.assertEquals(result.size(), 1);
@@ -252,9 +262,9 @@ class KubernetesDiscoveryClientUtilsTests {
KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L,
includeNotReadyAddresses, "", Set.of(), Map.of(), "", null, 0, false);
V1EndpointSubset endpointSubset = new V1EndpointSubsetBuilder()
.withAddresses(new V1EndpointAddressBuilder().withHostname("one").build(),
new V1EndpointAddressBuilder().withHostname("two").build())
.build();
.withAddresses(new V1EndpointAddressBuilder().withHostname("one").build(),
new V1EndpointAddressBuilder().withHostname("two").build())
.build();
List<V1EndpointAddress> addresses = KubernetesDiscoveryClientUtils.addresses(endpointSubset, properties);
Assertions.assertEquals(addresses.size(), 2);
}
@@ -271,9 +281,10 @@ class KubernetesDiscoveryClientUtilsTests {
KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L,
includeNotReadyAddresses, "", Set.of(), Map.of(), "", null, 0, false, false);
V1EndpointSubset endpointSubset = new V1EndpointSubsetBuilder()
.withAddresses(new V1EndpointAddressBuilder().withHostname("one").build(),
new V1EndpointAddressBuilder().withHostname("two").build())
.withNotReadyAddresses(new V1EndpointAddressBuilder().withHostname("three").build()).build();
.withAddresses(new V1EndpointAddressBuilder().withHostname("one").build(),
new V1EndpointAddressBuilder().withHostname("two").build())
.withNotReadyAddresses(new V1EndpointAddressBuilder().withHostname("three").build())
.build();
List<V1EndpointAddress> addresses = KubernetesDiscoveryClientUtils.addresses(endpointSubset, properties);
Assertions.assertEquals(addresses.size(), 2);
List<String> hostNames = addresses.stream().map(V1EndpointAddress::getHostname).sorted().toList();
@@ -292,9 +303,10 @@ class KubernetesDiscoveryClientUtilsTests {
KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties(true, true, Set.of(), true, 60L,
includeNotReadyAddresses, "", Set.of(), Map.of(), "", null, 0, false);
V1EndpointSubset endpointSubset = new V1EndpointSubsetBuilder()
.withAddresses(new V1EndpointAddressBuilder().withHostname("one").build(),
new V1EndpointAddressBuilder().withHostname("two").build())
.withNotReadyAddresses(new V1EndpointAddressBuilder().withHostname("three").build()).build();
.withAddresses(new V1EndpointAddressBuilder().withHostname("one").build(),
new V1EndpointAddressBuilder().withHostname("two").build())
.withNotReadyAddresses(new V1EndpointAddressBuilder().withHostname("three").build())
.build();
List<V1EndpointAddress> addresses = KubernetesDiscoveryClientUtils.addresses(endpointSubset, properties);
Assertions.assertEquals(addresses.size(), 3);
List<String> hostNames = addresses.stream().map(V1EndpointAddress::getHostname).sorted().toList();
@@ -303,8 +315,11 @@ class KubernetesDiscoveryClientUtilsTests {
// preserve order for testing reasons
private Map<String, String> ordered(Map<String, String> input) {
return input.entrySet().stream().sorted(Map.Entry.comparingByKey()).collect(
Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (left, right) -> left, LinkedHashMap::new));
return input.entrySet()
.stream()
.sorted(Map.Entry.comparingByKey())
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (left, right) -> left,
LinkedHashMap::new));
}
}

Some files were not shown because too many files have changed in this diff Show More