@@ -19,6 +19,8 @@ package org.springframework.cloud.kubernetes.client.config;
|
||||
import io.kubernetes.client.openapi.apis.CoreV1Api;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform;
|
||||
import org.springframework.boot.cloud.CloudPlatform;
|
||||
import org.springframework.cloud.kubernetes.client.KubernetesClientAutoConfiguration;
|
||||
import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesConfigEnabled;
|
||||
import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesEnabled;
|
||||
@@ -39,6 +41,7 @@ import org.springframework.context.annotation.Import;
|
||||
@ConditionalOnKubernetesEnabled
|
||||
@AutoConfigureAfter(KubernetesBootstrapConfiguration.class)
|
||||
@Import({ KubernetesCommonsAutoConfiguration.class, KubernetesClientAutoConfiguration.class })
|
||||
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
|
||||
public class KubernetesClientBootstrapConfiguration {
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -55,7 +55,7 @@ public class KubernetesClientBootstrapConfigurationTests {
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class,
|
||||
properties = { "spring.cloud.kubernetes.secrets.enabled=true",
|
||||
"spring.cloud.kubernetes.client.namespace=default" })
|
||||
"spring.cloud.kubernetes.client.namespace=default", "spring.main.cloud-platform=KUBERNETES" })
|
||||
@Nested
|
||||
class KubernetesEnabledOnPurpose {
|
||||
|
||||
@@ -71,7 +71,8 @@ public class KubernetesClientBootstrapConfigurationTests {
|
||||
}
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class,
|
||||
properties = "spring.cloud.kubernetes.client.namespace=default")
|
||||
properties = { "spring.cloud.kubernetes.client.namespace=default",
|
||||
"spring.main.cloud-platform=KUBERNETES" })
|
||||
@Nested
|
||||
class KubernetesEnabled {
|
||||
|
||||
@@ -87,7 +88,7 @@ public class KubernetesClientBootstrapConfigurationTests {
|
||||
}
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class,
|
||||
properties = "spring.cloud.kubernetes.config.enabled=false")
|
||||
properties = { "spring.cloud.kubernetes.config.enabled=false", "spring.main.cloud-platform=KUBERNETES" })
|
||||
@Nested
|
||||
class KubernetesEnabledConfigDisabled {
|
||||
|
||||
@@ -104,7 +105,7 @@ public class KubernetesClientBootstrapConfigurationTests {
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class,
|
||||
properties = { "spring.cloud.kubernetes.secrets.enabled=false",
|
||||
"spring.cloud.kubernetes.client.namespace=default" })
|
||||
"spring.cloud.kubernetes.client.namespace=default", "spring.main.cloud-platform=KUBERNETES" })
|
||||
@Nested
|
||||
class KubernetesEnabledSecretsDisabled {
|
||||
|
||||
@@ -136,4 +137,39 @@ public class KubernetesClientBootstrapConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
// tests that @ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES) has the desired
|
||||
// effect, meaning when it is enabled, both property sources are present
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class,
|
||||
properties = { "spring.main.cloud-platform=KUBERNETES", "spring.cloud.kubernetes.client.namespace=abc" })
|
||||
@Nested
|
||||
class KubernetesClientBootstrapConfigurationInsideK8s {
|
||||
|
||||
@Autowired
|
||||
ConfigurableApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void bothPresent() {
|
||||
assertThat(context.getBeanNamesForType(KubernetesClientConfigMapPropertySourceLocator.class)).hasSize(1);
|
||||
assertThat(context.getBeanNamesForType(KubernetesClientSecretsPropertySourceLocator.class)).hasSize(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// tests that @ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES) has the desired
|
||||
// effect, meaning when it is disabled, no property source bean is present
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class)
|
||||
@Nested
|
||||
class KubernetesClientBootstrapConfigurationNotInsideK8s {
|
||||
|
||||
@Autowired
|
||||
ConfigurableApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void bothMissing() {
|
||||
assertThat(context.getBeanNamesForType(KubernetesClientConfigMapPropertySourceLocator.class)).hasSize(0);
|
||||
assertThat(context.getBeanNamesForType(KubernetesClientSecretsPropertySourceLocator.class)).hasSize(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = IncludeProfileSpecificSourcesApp.class,
|
||||
properties = { "spring.cloud.bootstrap.name=include-profile-specific-sources",
|
||||
"include.profile.specific.sources=true" })
|
||||
"include.profile.specific.sources=true", "spring.main.cloud-platform=KUBERNETES" })
|
||||
@AutoConfigureWebTestClient
|
||||
@ActiveProfiles("dev")
|
||||
class KubernetesClientConfigMapIncludeProfileSpecificSourcesTests {
|
||||
|
||||
@@ -37,7 +37,8 @@ import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = WithPrefixApp.class,
|
||||
properties = { "spring.cloud.bootstrap.name=config-map-name-as-prefix", "config.map.name.as.prefix.stub=true" })
|
||||
properties = { "spring.cloud.bootstrap.name=config-map-name-as-prefix", "config.map.name.as.prefix.stub=true",
|
||||
"spring.main.cloud-platform=KUBERNETES" })
|
||||
@AutoConfigureWebTestClient
|
||||
public class KubernetesClientConfigMapNameAsPrefixTests {
|
||||
|
||||
|
||||
@@ -65,6 +65,8 @@ class KubernetesClientConfigMapPropertySourceLocatorTests {
|
||||
|
||||
private static WireMockServer wireMockServer;
|
||||
|
||||
private static final MockEnvironment ENV = new MockEnvironment();
|
||||
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
wireMockServer = new WireMockServer(options().dynamicPort());
|
||||
@@ -97,7 +99,7 @@ class KubernetesClientConfigMapPropertySourceLocatorTests {
|
||||
KubernetesClientProperties kubernetesClientProperties = new KubernetesClientProperties();
|
||||
kubernetesClientProperties.setNamespace("default");
|
||||
PropertySource<?> propertySource = new KubernetesClientConfigMapPropertySourceLocator(api,
|
||||
configMapConfigProperties, kubernetesClientProperties).locate(new MockEnvironment());
|
||||
configMapConfigProperties, kubernetesClientProperties).locate(ENV);
|
||||
assertThat(propertySource.containsProperty("spring.cloud.kubernetes.configuration.watcher.refreshDelay"))
|
||||
.isTrue();
|
||||
}
|
||||
@@ -117,7 +119,7 @@ class KubernetesClientConfigMapPropertySourceLocatorTests {
|
||||
KubernetesClientProperties kubernetesClientProperties = new KubernetesClientProperties();
|
||||
kubernetesClientProperties.setNamespace("dev");
|
||||
PropertySource<?> propertySource = new KubernetesClientConfigMapPropertySourceLocator(api,
|
||||
configMapConfigProperties, kubernetesClientProperties).locate(new MockEnvironment());
|
||||
configMapConfigProperties, kubernetesClientProperties).locate(ENV);
|
||||
assertThat(propertySource.containsProperty("spring.cloud.kubernetes.configuration.watcher.refreshDelay"))
|
||||
.isTrue();
|
||||
}
|
||||
@@ -140,8 +142,7 @@ class KubernetesClientConfigMapPropertySourceLocatorTests {
|
||||
KubernetesClientProperties kubernetesClientProperties = new KubernetesClientProperties();
|
||||
kubernetesClientProperties.setNamespace(""); // empty on purpose
|
||||
assertThatThrownBy(() -> new KubernetesClientConfigMapPropertySourceLocator(api, configMapConfigProperties,
|
||||
kubernetesClientProperties).locate(new MockEnvironment()))
|
||||
.isInstanceOf(NamespaceResolutionFailedException.class);
|
||||
kubernetesClientProperties).locate(ENV)).isInstanceOf(NamespaceResolutionFailedException.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -162,7 +163,7 @@ class KubernetesClientConfigMapPropertySourceLocatorTests {
|
||||
KubernetesClientProperties kubernetesClientProperties = new KubernetesClientProperties();
|
||||
kubernetesClientProperties.setNamespace(""); // empty on purpose
|
||||
assertThatThrownBy(() -> new KubernetesClientConfigMapPropertySourceLocator(api, configMapConfigProperties,
|
||||
new KubernetesNamespaceProvider(new MockEnvironment())).locate(new MockEnvironment()))
|
||||
new KubernetesNamespaceProvider(ENV)).locate(ENV))
|
||||
.isInstanceOf(NamespaceResolutionFailedException.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.cloud.kubernetes.commons.KubernetesClientProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
|
||||
import org.springframework.cloud.kubernetes.commons.config.NamespaceResolutionFailedException;
|
||||
import org.springframework.cloud.kubernetes.commons.config.SecretsConfigProperties;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
@@ -76,6 +75,8 @@ class KubernetesClientSecretsPropertySourceLocatorTests {
|
||||
|
||||
private static WireMockServer wireMockServer;
|
||||
|
||||
private static final MockEnvironment ENV = new MockEnvironment();
|
||||
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
wireMockServer = new WireMockServer(options().dynamicPort());
|
||||
@@ -117,7 +118,7 @@ class KubernetesClientSecretsPropertySourceLocatorTests {
|
||||
secretsConfigProperties.setSources(sources);
|
||||
secretsConfigProperties.setEnableApi(true);
|
||||
PropertySource<?> propertySource = new KubernetesClientSecretsPropertySourceLocator(api,
|
||||
new KubernetesClientProperties(), secretsConfigProperties).locate(new MockEnvironment());
|
||||
new KubernetesClientProperties(), secretsConfigProperties).locate(ENV);
|
||||
assertThat(propertySource.containsProperty("password")).isTrue();
|
||||
assertThat(propertySource.getProperty("password")).isEqualTo("p455w0rd");
|
||||
}
|
||||
@@ -131,7 +132,7 @@ class KubernetesClientSecretsPropertySourceLocatorTests {
|
||||
secretsConfigProperties.setNamespace("default");
|
||||
secretsConfigProperties.setEnableApi(true);
|
||||
PropertySource<?> propertySource = new KubernetesClientSecretsPropertySourceLocator(api,
|
||||
new KubernetesClientProperties(), secretsConfigProperties).locate(new MockEnvironment());
|
||||
new KubernetesClientProperties(), secretsConfigProperties).locate(ENV);
|
||||
assertThat(propertySource.containsProperty("password")).isTrue();
|
||||
assertThat(propertySource.getProperty("password")).isEqualTo("p455w0rd");
|
||||
}
|
||||
@@ -153,29 +154,7 @@ class KubernetesClientSecretsPropertySourceLocatorTests {
|
||||
secretsConfigProperties.setNamespace(""); // empty on purpose
|
||||
secretsConfigProperties.setEnableApi(true);
|
||||
assertThatThrownBy(() -> new KubernetesClientSecretsPropertySourceLocator(api, new KubernetesClientProperties(),
|
||||
secretsConfigProperties).locate(new MockEnvironment()))
|
||||
.isInstanceOf(NamespaceResolutionFailedException.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 1. using the non-deprecated constructor, and
|
||||
* 2. not providing the namespace
|
||||
* </pre>
|
||||
*
|
||||
* will result in an Exception
|
||||
*/
|
||||
@Test
|
||||
void testLocateWithoutNamespace() {
|
||||
CoreV1Api api = new CoreV1Api();
|
||||
stubFor(get(LIST_API).willReturn(aResponse().withStatus(200).withBody(LIST_BODY)));
|
||||
SecretsConfigProperties secretsConfigProperties = new SecretsConfigProperties();
|
||||
secretsConfigProperties.setName("db-secret");
|
||||
secretsConfigProperties.setNamespace(""); // empty on purpose
|
||||
secretsConfigProperties.setEnableApi(true);
|
||||
assertThatThrownBy(() -> new KubernetesClientSecretsPropertySourceLocator(api,
|
||||
new KubernetesNamespaceProvider(new MockEnvironment()), secretsConfigProperties)
|
||||
.locate(new MockEnvironment())).isInstanceOf(NamespaceResolutionFailedException.class);
|
||||
secretsConfigProperties).locate(ENV)).isInstanceOf(NamespaceResolutionFailedException.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -72,9 +72,9 @@ public class KubernetesClientConfigReloadAutoConfigurationTest {
|
||||
public static WireMockServer wireMockServer = new WireMockServer(options().dynamicPort());
|
||||
|
||||
protected void setup(String... env) {
|
||||
List<String> envList = (env != null) ? new ArrayList(Arrays.asList(env)) : new ArrayList<>();
|
||||
List<String> envList = (env != null) ? new ArrayList<>(Arrays.asList(env)) : new ArrayList<>();
|
||||
envList.add("spring.cloud.kubernetes.client.namespace=default");
|
||||
String[] envArray = envList.stream().toArray(String[]::new);
|
||||
String[] envArray = envList.toArray(new String[0]);
|
||||
|
||||
context = new SpringApplicationBuilder(PropertyPlaceholderAutoConfiguration.class, LocalTestConfig.class,
|
||||
ConfigReloadAutoConfiguration.class, RefreshAutoConfiguration.class, EndpointAutoConfiguration.class,
|
||||
@@ -152,7 +152,8 @@ public class KubernetesClientConfigReloadAutoConfigurationTest {
|
||||
|
||||
@Test
|
||||
public void kubernetesReloadEnabledWithPolling() throws Exception {
|
||||
setup("spring.cloud.kubernetes.reload.enabled=true", "spring.cloud.kubernetes.reload.mode=polling");
|
||||
setup("spring.cloud.kubernetes.reload.enabled=true", "spring.cloud.kubernetes.reload.mode=polling",
|
||||
"spring.main.cloud-platform=KUBERNETES");
|
||||
assertThat(context.containsBean("configMapPropertySourceLocator")).isTrue();
|
||||
assertThat(context.containsBean("secretsPropertySourceLocator")).isTrue();
|
||||
assertThat(context.containsBean("configMapPropertyChangePollingWatcher")).isTrue();
|
||||
@@ -163,7 +164,8 @@ public class KubernetesClientConfigReloadAutoConfigurationTest {
|
||||
|
||||
@Test
|
||||
public void kubernetesReloadEnabledWithEvent() throws Exception {
|
||||
setup("spring.cloud.kubernetes.reload.enabled=true", "spring.cloud.kubernetes.reload.mode=event");
|
||||
setup("spring.cloud.kubernetes.reload.enabled=true", "spring.cloud.kubernetes.reload.mode=event",
|
||||
"spring.main.cloud-platform=KUBERNETES");
|
||||
assertThat(context.containsBean("configMapPropertyChangePollingWatcher")).isFalse();
|
||||
assertThat(context.containsBean("secretsPropertyChangePollingWatcher")).isFalse();
|
||||
assertThat(context.containsBean("configMapPropertyChangeEventWatcher")).isTrue();
|
||||
@@ -174,21 +176,21 @@ public class KubernetesClientConfigReloadAutoConfigurationTest {
|
||||
|
||||
@Test
|
||||
public void kubernetesConfigAndSecretEnabledByDefault() throws Exception {
|
||||
setup();
|
||||
setup("spring.main.cloud-platform=KUBERNETES");
|
||||
assertThat(context.containsBean("configMapPropertySourceLocator")).isTrue();
|
||||
assertThat(context.containsBean("secretsPropertySourceLocator")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void kubernetesConfigEnabledButSecretDisabled() throws Exception {
|
||||
setup("spring.cloud.kubernetes.secrets.enabled=false");
|
||||
setup("spring.cloud.kubernetes.secrets.enabled=false", "spring.main.cloud-platform=KUBERNETES");
|
||||
assertThat(context.containsBean("configMapPropertySourceLocator")).isTrue();
|
||||
assertThat(context.containsBean("secretsPropertySourceLocator")).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void kubernetesSecretsEnabledButConfigDisabled() throws Exception {
|
||||
setup("spring.cloud.kubernetes.config.enabled=false");
|
||||
setup("spring.cloud.kubernetes.config.enabled=false", "spring.main.cloud-platform=KUBERNETES");
|
||||
assertThat(context.containsBean("configMapPropertySourceLocator")).isFalse();
|
||||
assertThat(context.containsBean("secretsPropertySourceLocator")).isTrue();
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ import io.fabric8.kubernetes.client.KubernetesClient;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform;
|
||||
import org.springframework.boot.cloud.CloudPlatform;
|
||||
import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesConfigEnabled;
|
||||
import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesEnabled;
|
||||
import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesSecretsEnabled;
|
||||
@@ -46,6 +48,7 @@ import org.springframework.core.env.Environment;
|
||||
@Import({ KubernetesCommonsAutoConfiguration.class, Fabric8AutoConfiguration.class })
|
||||
@ConditionalOnClass({ ConfigMap.class, Secret.class })
|
||||
@AutoConfigureAfter(KubernetesBootstrapConfiguration.class)
|
||||
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
|
||||
public class Fabric8BootstrapConfiguration {
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -41,7 +41,8 @@ import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = IncludeProfileSpecificSourcesApp.class,
|
||||
properties = { "spring.cloud.bootstrap.name=include-profile-specific-sources" })
|
||||
properties = { "spring.cloud.bootstrap.name=include-profile-specific-sources",
|
||||
"spring.main.cloud-platform=KUBERNETES" })
|
||||
@AutoConfigureWebTestClient
|
||||
@EnableKubernetesMockClient(crud = true, https = false)
|
||||
@ActiveProfiles("dev")
|
||||
|
||||
@@ -39,7 +39,8 @@ import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = WithPrefixApp.class,
|
||||
properties = { "spring.cloud.bootstrap.name=config-map-name-as-prefix" })
|
||||
properties = { "spring.cloud.bootstrap.name=config-map-name-as-prefix",
|
||||
"spring.main.cloud-platform=KUBERNETES" })
|
||||
@AutoConfigureWebTestClient
|
||||
@EnableKubernetesMockClient(crud = true, https = false)
|
||||
class ConfigMapWithPrefixTests {
|
||||
|
||||
@@ -42,7 +42,8 @@ import static org.assertj.core.util.Lists.newArrayList;
|
||||
"spring.cloud.kubernetes.config.enableApi=false",
|
||||
"spring.cloud.kubernetes.config.paths=" + ConfigMapsFromFilePathsTests.FIRST_FILE_NAME_FULL_PATH + ","
|
||||
+ ConfigMapsFromFilePathsTests.SECOND_FILE_NAME_FULL_PATH + ","
|
||||
+ ConfigMapsFromFilePathsTests.FIRST_FILE_NAME_DUPLICATED_FULL_PATH })
|
||||
+ ConfigMapsFromFilePathsTests.FIRST_FILE_NAME_DUPLICATED_FULL_PATH,
|
||||
"spring.main.cloud-platform=KUBERNETES" })
|
||||
@EnableKubernetesMockClient(crud = true, https = false)
|
||||
public class ConfigMapsFromFilePathsTests {
|
||||
|
||||
|
||||
@@ -43,7 +43,8 @@ import static org.assertj.core.util.Lists.newArrayList;
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
|
||||
properties = { "spring.application.name=" + ConfigMapsMixedTests.APPLICATION_NAME,
|
||||
"spring.cloud.kubernetes.config.enableApi=true",
|
||||
"spring.cloud.kubernetes.config.paths=" + ConfigMapsMixedTests.FILE_NAME_FULL_PATH })
|
||||
"spring.cloud.kubernetes.config.paths=" + ConfigMapsMixedTests.FILE_NAME_FULL_PATH,
|
||||
"spring.main.cloud-platform=KUBERNETES" })
|
||||
@EnableKubernetesMockClient(crud = true, https = false)
|
||||
public class ConfigMapsMixedTests {
|
||||
|
||||
|
||||
@@ -40,7 +40,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
|
||||
properties = { "spring.application.name=configmap-example", "spring.cloud.kubernetes.reload.enabled=false" })
|
||||
properties = { "spring.application.name=configmap-example", "spring.cloud.kubernetes.reload.enabled=false",
|
||||
"spring.main.cloud-platform=KUBERNETES" })
|
||||
@AutoConfigureWebTestClient
|
||||
@EnableKubernetesMockClient(crud = true, https = false)
|
||||
public class ConfigMapsTests {
|
||||
|
||||
@@ -42,7 +42,7 @@ import static org.springframework.cloud.kubernetes.fabric8.config.ConfigMapTestU
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(webEnvironment = RANDOM_PORT, classes = App.class,
|
||||
properties = { "spring.application.name=configmap-with-active-profile-name-example",
|
||||
"spring.cloud.kubernetes.reload.enabled=false" })
|
||||
"spring.cloud.kubernetes.reload.enabled=false", "spring.main.cloud-platform=KUBERNETES" })
|
||||
@ActiveProfiles("development")
|
||||
@AutoConfigureWebTestClient
|
||||
@EnableKubernetesMockClient(crud = true, https = false)
|
||||
|
||||
@@ -38,8 +38,9 @@ import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
*/
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class, properties = {
|
||||
"spring.application.name=configmap-with-profile-example", "spring.cloud.kubernetes.reload.enabled=false" })
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
|
||||
properties = { "spring.application.name=configmap-with-profile-example",
|
||||
"spring.cloud.kubernetes.reload.enabled=false", "spring.main.cloud-platform=KUBERNETES" })
|
||||
@ActiveProfiles({ "production", "us-east" })
|
||||
@AutoConfigureWebTestClient
|
||||
@EnableKubernetesMockClient(crud = true, https = false)
|
||||
|
||||
@@ -40,7 +40,7 @@ import static org.springframework.cloud.kubernetes.fabric8.config.ConfigMapTestU
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
|
||||
properties = { "spring.application.name=configmap-with-profile-no-active-profiles-example",
|
||||
"spring.cloud.kubernetes.reload.enabled=false" })
|
||||
"spring.cloud.kubernetes.reload.enabled=false", "spring.main.cloud-platform=KUBERNETES" })
|
||||
@AutoConfigureWebTestClient
|
||||
@EnableKubernetesMockClient(crud = true, https = false)
|
||||
public class ConfigMapsWithProfilesNoActiveProfileTests {
|
||||
|
||||
@@ -37,8 +37,9 @@ import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
* @author Charles Moulliard
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class, properties = {
|
||||
"spring.application.name=configmap-with-profile-example", "spring.cloud.kubernetes.reload.enabled=false" })
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
|
||||
properties = { "spring.application.name=configmap-with-profile-example",
|
||||
"spring.cloud.kubernetes.reload.enabled=false", "spring.main.cloud-platform=KUBERNETES" })
|
||||
@ActiveProfiles("development")
|
||||
@AutoConfigureWebTestClient
|
||||
@EnableKubernetesMockClient(crud = true, https = false)
|
||||
|
||||
@@ -34,8 +34,9 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class, properties = {
|
||||
"spring.application.name=configmap-without-profile-example", "spring.cloud.kubernetes.reload.enabled=false" })
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
|
||||
properties = { "spring.application.name=configmap-without-profile-example",
|
||||
"spring.cloud.kubernetes.reload.enabled=false", "spring.main.cloud-platform=KUBERNETES" })
|
||||
@ActiveProfiles("development")
|
||||
@AutoConfigureWebTestClient
|
||||
@EnableKubernetesMockClient(crud = true, https = false)
|
||||
|
||||
@@ -37,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@SpringBootTest(classes = TestApplication.class,
|
||||
properties = { "spring.application.name=testapp", "spring.cloud.kubernetes.client.namespace=testns",
|
||||
"spring.cloud.kubernetes.client.trustCerts=true", "spring.cloud.kubernetes.config.namespace=testns",
|
||||
"spring.cloud.kubernetes.secrets.enableApi=true" })
|
||||
"spring.cloud.kubernetes.secrets.enableApi=true", "spring.main.cloud-platform=KUBERNETES" })
|
||||
@EnableKubernetesMockClient(crud = true, https = false)
|
||||
public class CoreTest {
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ public class Fabric8BootstrapConfigurationTests {
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class,
|
||||
properties = { "spring.cloud.kubernetes.secrets.enabled=true",
|
||||
"spring.cloud.kubernetes.client.namespace=default" })
|
||||
"spring.cloud.kubernetes.client.namespace=default", "spring.main.cloud-platform=KUBERNETES" })
|
||||
@Nested
|
||||
class KubernetesEnabledOnPurpose {
|
||||
|
||||
@@ -64,7 +64,8 @@ public class Fabric8BootstrapConfigurationTests {
|
||||
}
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class,
|
||||
properties = "spring.cloud.kubernetes.client.namespace=default")
|
||||
properties = { "spring.cloud.kubernetes.client.namespace=default",
|
||||
"spring.main.cloud-platform=KUBERNETES" })
|
||||
@Nested
|
||||
class KubernetesEnabled {
|
||||
|
||||
@@ -80,7 +81,7 @@ public class Fabric8BootstrapConfigurationTests {
|
||||
}
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class,
|
||||
properties = "spring.cloud.kubernetes.config.enabled=false")
|
||||
properties = { "spring.cloud.kubernetes.config.enabled=false", "spring.main.cloud-platform=KUBERNETES" })
|
||||
@Nested
|
||||
class KubernetesEnabledConfigDisabled {
|
||||
|
||||
@@ -97,7 +98,7 @@ public class Fabric8BootstrapConfigurationTests {
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class,
|
||||
properties = { "spring.cloud.kubernetes.secrets.enabled=false",
|
||||
"spring.cloud.kubernetes.client.namespace=default" })
|
||||
"spring.cloud.kubernetes.client.namespace=default", "spring.main.cloud-platform=KUBERNETES" })
|
||||
@Nested
|
||||
class KubernetesEnabledSecretsDisabled {
|
||||
|
||||
@@ -129,4 +130,39 @@ public class Fabric8BootstrapConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
// tests that @ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES) has the desired
|
||||
// effect, meaning when it is enabled, both property sources are present
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class,
|
||||
properties = { "spring.main.cloud-platform=KUBERNETES", "spring.cloud.kubernetes.client.namespace=abc" })
|
||||
@Nested
|
||||
class Fabric8BootstrapConfigurationInsideK8s {
|
||||
|
||||
@Autowired
|
||||
ConfigurableApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void bothPresent() {
|
||||
assertThat(context.getBeanNamesForType(Fabric8ConfigMapPropertySourceLocator.class)).hasSize(1);
|
||||
assertThat(context.getBeanNamesForType(Fabric8SecretsPropertySourceLocator.class)).hasSize(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// tests that @ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES) has the desired
|
||||
// effect, meaning when it is disabled, no property source bean is present
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class)
|
||||
@Nested
|
||||
class Fabric8BootstrapConfigurationNotInsideK8s {
|
||||
|
||||
@Autowired
|
||||
ConfigurableApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void bothMissing() {
|
||||
assertThat(context.getBeanNamesForType(Fabric8ConfigMapPropertySourceLocator.class)).hasSize(0);
|
||||
assertThat(context.getBeanNamesForType(Fabric8SecretsPropertySourceLocator.class)).hasSize(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.kubernetes.fabric8.config.example.App;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
@@ -38,7 +39,8 @@ import static java.util.Collections.singletonMap;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
|
||||
properties = "spring.main.cloud-platform=KUBERNETES")
|
||||
@TestPropertySource("classpath:/application-secrets.properties")
|
||||
@EnableKubernetesMockClient(crud = true, https = false)
|
||||
public class Fabric8SecretsPropertySourceTest {
|
||||
@@ -73,9 +75,9 @@ public class Fabric8SecretsPropertySourceTest {
|
||||
|
||||
@Test
|
||||
public void toStringShouldNotExposeSecretValues() {
|
||||
String actual = this.propertySourceLocator.locate(this.environment).toString();
|
||||
|
||||
assertThat(actual).doesNotContain(SECRET_VALUE);
|
||||
PropertySource<?> propertySource = this.propertySourceLocator.locate(this.environment);
|
||||
assertThat(propertySource.toString()).doesNotContain(SECRET_VALUE);
|
||||
assertThat(propertySource.getProperty("secretName")).isEqualTo("secretValue");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public class KubernetesConfigConfigurationTest extends KubernetesConfigTestBase
|
||||
@Test
|
||||
public void kubernetesWhenKubernetesDefaultEnabled() {
|
||||
setup(KubernetesClientTestConfiguration.class, "spring.cloud.kubernetes.enabled=true",
|
||||
"spring.cloud.kubernetes.client.namespace=default");
|
||||
"spring.cloud.kubernetes.client.namespace=default", "spring.main.cloud-platform=KUBERNETES");
|
||||
assertThat(getContext().containsBean("configMapPropertySourceLocator")).isTrue();
|
||||
assertThat(getContext().containsBean("secretsPropertySourceLocator")).isTrue();
|
||||
}
|
||||
@@ -66,7 +66,8 @@ public class KubernetesConfigConfigurationTest extends KubernetesConfigTestBase
|
||||
@Test
|
||||
public void kubernetesWhenKubernetesConfigEnabledButSecretDisabled() {
|
||||
setup(KubernetesClientTestConfiguration.class, "spring.cloud.kubernetes.config.enabled=true",
|
||||
"spring.cloud.kubernetes.secrets.enabled=false", "spring.cloud.kubernetes.client.namespace=default");
|
||||
"spring.cloud.kubernetes.secrets.enabled=false", "spring.cloud.kubernetes.client.namespace=default",
|
||||
"spring.main.cloud-platform=KUBERNETES");
|
||||
assertThat(getContext().containsBean("configMapPropertySourceLocator")).isTrue();
|
||||
assertThat(getContext().containsBean("secretsPropertySourceLocator")).isFalse();
|
||||
}
|
||||
@@ -74,7 +75,7 @@ public class KubernetesConfigConfigurationTest extends KubernetesConfigTestBase
|
||||
@Test
|
||||
public void kubernetesWhenKubernetesConfigDisabledButSecretEnabled() {
|
||||
setup(KubernetesClientTestConfiguration.class, "spring.cloud.kubernetes.config.enabled=false",
|
||||
"spring.cloud.kubernetes.secrets.enabled=true");
|
||||
"spring.cloud.kubernetes.secrets.enabled=true", "spring.main.cloud-platform=KUBERNETES");
|
||||
assertThat(getContext().containsBean("configMapPropertySourceLocator")).isFalse();
|
||||
assertThat(getContext().containsBean("secretsPropertySourceLocator")).isTrue();
|
||||
}
|
||||
@@ -82,7 +83,8 @@ public class KubernetesConfigConfigurationTest extends KubernetesConfigTestBase
|
||||
@Test
|
||||
public void kubernetesConfigWhenKubernetesEnabledAndKubernetesConfigEnabled() {
|
||||
setup(KubernetesClientTestConfiguration.class, "spring.cloud.kubernetes.config.enabled=true",
|
||||
"spring.cloud.kubernetes.secrets.enabled=true", "spring.cloud.kubernetes.client.namespace=default");
|
||||
"spring.cloud.kubernetes.secrets.enabled=true", "spring.cloud.kubernetes.client.namespace=default",
|
||||
"spring.main.cloud-platform=KUBERNETES");
|
||||
assertThat(getContext().containsBean("configMapPropertySourceLocator")).isTrue();
|
||||
assertThat(getContext().containsBean("secretsPropertySourceLocator")).isTrue();
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = ExampleApp.class,
|
||||
properties = { "spring.cloud.bootstrap.name=multiplecms" })
|
||||
properties = { "spring.cloud.bootstrap.name=multiplecms", "spring.main.cloud-platform=KUBERNETES" })
|
||||
@AutoConfigureWebTestClient
|
||||
@EnableKubernetesMockClient(crud = true, https = false)
|
||||
public class MultipleConfigMapsTests {
|
||||
|
||||
@@ -41,7 +41,7 @@ import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = MultiSecretsApp.class,
|
||||
properties = { "spring.cloud.bootstrap.name=multiple-secrets" })
|
||||
properties = { "spring.cloud.bootstrap.name=multiple-secrets", "spring.main.cloud-platform=KUBERNETES" })
|
||||
@AutoConfigureWebTestClient
|
||||
@EnableKubernetesMockClient(crud = true, https = false)
|
||||
public class MultipleSecretsTests {
|
||||
|
||||
@@ -99,7 +99,7 @@ public class ConfigReloadAutoConfigurationTest extends KubernetesConfigTestBase
|
||||
public void kubernetesReloadEnabled() {
|
||||
setup(KubernetesClientTestConfiguration.class, "spring.cloud.kubernetes.enabled=true",
|
||||
"spring.cloud.kubernetes.config.enabled=true", "spring.cloud.kubernetes.secrets.enabled=true",
|
||||
"spring.cloud.kubernetes.reload.enabled=true");
|
||||
"spring.cloud.kubernetes.reload.enabled=true", "spring.main.cloud-platform=KUBERNETES");
|
||||
assertThat(this.getContext().containsBean("configMapPropertySourceLocator")).isTrue();
|
||||
assertThat(this.getContext().containsBean("secretsPropertySourceLocator")).isTrue();
|
||||
assertThat(this.getContext().containsBean("configMapPropertyChangeEventWatcher")).isTrue();
|
||||
@@ -110,7 +110,7 @@ public class ConfigReloadAutoConfigurationTest extends KubernetesConfigTestBase
|
||||
public void kubernetesReloadEnabledButSecretDisabled() {
|
||||
setup(KubernetesClientTestConfiguration.class, "spring.cloud.kubernetes.enabled=true",
|
||||
"spring.cloud.kubernetes.config.enabled=true", "spring.cloud.kubernetes.secrets.enabled=false",
|
||||
"spring.cloud.kubernetes.reload.enabled=true");
|
||||
"spring.cloud.kubernetes.reload.enabled=true", "spring.main.cloud-platform=KUBERNETES");
|
||||
assertThat(this.getContext().containsBean("configMapPropertySourceLocator")).isTrue();
|
||||
assertThat(this.getContext().containsBean("secretsPropertySourceLocator")).isFalse();
|
||||
assertThat(this.getContext().containsBean("configMapPropertyChangeEventWatcher")).isTrue();
|
||||
|
||||
Reference in New Issue
Block a user