Fix 893 (Use @ConditionalOnCloudPlatform) (#908)
* changes in common * fabric8-autoconfig * fabric8-config * k8s-autoconfig * k8s-config * fabric8-discovery * k8s-discovery * fabric8-lb * k8s-lb * fabric8-leader * fabric8-istio * controllers * integ tests * test before changes in docs * before documentation * revert formating * fix * documentation * document new awareness * review comments * review comments * trigger build * trigger build * build trigger * build trigger again * test * fix @Nested tests not running * test image * test image * test image * test image * newer ubuntu image * test * test * test * test * test * test * test * test * test * test * test * test * test * test * test * bump jacoco version to support jdk-17 * trigger again * clean-up
This commit is contained in:
15
README.adoc
15
README.adoc
@@ -1096,11 +1096,16 @@ as the code of the project relies on the
|
||||
https://github.com/fabric8io/kubernetes-client[Fabric8 Kubernetes Java client], which is a fluent DSL that can
|
||||
communicate by using `http` protocol to the REST API of the Kubernetes Server.
|
||||
|
||||
To disable the integration with Kubernetes you can set `spring.cloud.kubernetes.enabled` to `false`. Please be aware that when `spring-cloud-kubernetes-config` is on the classpath,
|
||||
`spring.cloud.kubernetes.enabled` should be set in `bootstrap.{properties|yml}` (or the profile specific one), otherwise it should be in `application.{properties|yml}` (or the profile specific one).
|
||||
Because of the way we set up a specific `EnvironmentPostProcessor` in `spring-cloud-kubernetes-config`, you also need to disable that processor via a system property (or an environment variable), for example you could start
|
||||
your application via `-DSPRING_CLOUD_KUBERNETES_ENABLED=false` (any form of relaxed binding will work too).
|
||||
Also note that these properties: `spring.cloud.kubernetes.config.enabled` and `spring.cloud.kubernetes.secrets.enabled` only take effect when set in `bootstrap.{properties|yml}`
|
||||
Kubernetes awareness is based on Spring Boot API, specifically on https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/autoconfigure/condition/ConditionalOnCloudPlatform.html[ConditionalOnCloudPlatform].
|
||||
That property will auto-detect if your application is currently deployed in kubernetes or not. It is possible to override
|
||||
that setting via `spring.main.cloud-platform`.
|
||||
|
||||
For example, if you need to test some features, but do not want to deploy to a cluster, it is enough to set the:
|
||||
`spring.main.cloud-platform=KUBERNETES`. This will make `spring-cloud-kubernetes` act as-if it is deployed in a real cluster.
|
||||
Be aware that when `spring-cloud-kubernetes-config` is on the classpath, `spring.main.cloud-platform` should be set in `bootstrap.{properties|yml}`
|
||||
(or the profile specific one), otherwise it should be in `application.{properties|yml}` (or the profile specific one).
|
||||
Also note that these properties: `spring.cloud.kubernetes.config.enabled` and `spring.cloud.kubernetes.secrets.enabled`
|
||||
only take effect when set in `bootstrap.{properties|yml}`.
|
||||
|
||||
=== Kubernetes Profile Autoconfiguration
|
||||
|
||||
|
||||
@@ -73,7 +73,6 @@
|
||||
|spring.cloud.kubernetes.discovery.primary-port-name | | If set then the port with a given name is used as primary when multiple ports are defined for a service.
|
||||
|spring.cloud.kubernetes.discovery.service-labels | | If set, then only the services matching these labels will be fetched from the Kubernetes API server.
|
||||
|spring.cloud.kubernetes.discovery.wait-cache-ready | `true` |
|
||||
|spring.cloud.kubernetes.enabled | `true` | Whether to enable Kubernetes integration.
|
||||
|spring.cloud.kubernetes.leader.auto-startup | `true` | Should leader election be started automatically on startup. Default: true
|
||||
|spring.cloud.kubernetes.leader.config-map-name | `leaders` | Kubernetes ConfigMap where leaders information will be stored. Default: leaders
|
||||
|spring.cloud.kubernetes.leader.enabled | `true` | Should leader election be enabled. Default: true
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
== Kubernetes Ecosystem Awareness
|
||||
|
||||
All of the features described earlier in this guide work equally well, regardless of whether your application is running inside
|
||||
All features described earlier in this guide work equally well, regardless of whether your application is running inside
|
||||
Kubernetes. This is really helpful for development and troubleshooting.
|
||||
From a development point of view, this lets you start your Spring Boot application and debug one
|
||||
of the modules that is part of this project. You need not deploy it in Kubernetes,
|
||||
@@ -8,11 +8,22 @@ as the code of the project relies on the
|
||||
https://github.com/fabric8io/kubernetes-client[Fabric8 Kubernetes Java client], which is a fluent DSL that can
|
||||
communicate by using `http` protocol to the REST API of the Kubernetes Server.
|
||||
|
||||
To disable the integration with Kubernetes you can set `spring.cloud.kubernetes.enabled` to `false`. Please be aware that when `spring-cloud-kubernetes-config` is on the classpath,
|
||||
`spring.cloud.kubernetes.enabled` should be set in `bootstrap.{properties|yml}` (or the profile specific one), otherwise it should be in `application.{properties|yml}` (or the profile specific one).
|
||||
Because of the way we set up a specific `EnvironmentPostProcessor` in `spring-cloud-kubernetes-config`, you also need to disable that processor via a system property (or an environment variable), for example you could start
|
||||
your application via `-DSPRING_CLOUD_KUBERNETES_ENABLED=false` (any form of relaxed binding will work too).
|
||||
Also note that these properties: `spring.cloud.kubernetes.config.enabled` and `spring.cloud.kubernetes.secrets.enabled` only take effect when set in `bootstrap.{properties|yml}`
|
||||
Kubernetes awareness is based on Spring Boot API, specifically on https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/autoconfigure/condition/ConditionalOnCloudPlatform.html[ConditionalOnCloudPlatform].
|
||||
That property will auto-detect if your application is currently deployed in kubernetes or not. It is possible to override
|
||||
that setting via `spring.main.cloud-platform`.
|
||||
|
||||
For example, if you need to test some features, but do not want to deploy to a cluster, it is enough to set the:
|
||||
`spring.main.cloud-platform=KUBERNETES`. This will make `spring-cloud-kubernetes` act as-if it is deployed in a real cluster.
|
||||
Be aware that when `spring-cloud-kubernetes-config` is on the classpath, `spring.main.cloud-platform` should be set in `bootstrap.{properties|yml}`
|
||||
(or the profile specific one), otherwise it should be in `application.{properties|yml}` (or the profile specific one).
|
||||
Also note that these properties: `spring.cloud.kubernetes.config.enabled` and `spring.cloud.kubernetes.secrets.enabled`
|
||||
only take effect when set in `bootstrap.{properties|yml}`.
|
||||
|
||||
=== Functional changes since 2.1.x version
|
||||
|
||||
In versions prior to `2.1.x`, Kubernetes awareness was implemented using `spring.cloud.kubernetes.enabled` property. This
|
||||
property was removed and is un-supported. Instead, we use Spring Boot API: https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/autoconfigure/condition/ConditionalOnCloudPlatform.html[ConditionalOnCloudPlatform].
|
||||
If it is needed to explicitly enable or disable this awareness, use `spring.main.cloud-platform=NONE/KUBERNETES`.
|
||||
|
||||
=== Kubernetes Profile Autoconfiguration
|
||||
|
||||
|
||||
@@ -22,7 +22,8 @@ import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnable
|
||||
import org.springframework.boot.actuate.autoconfigure.info.ConditionalOnEnabledInfoContributor;
|
||||
import org.springframework.boot.actuate.health.HealthIndicator;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesEnabled;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform;
|
||||
import org.springframework.boot.cloud.CloudPlatform;
|
||||
import org.springframework.cloud.kubernetes.commons.PodUtils;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -32,7 +33,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnClass(HealthIndicator.class)
|
||||
@ConditionalOnKubernetesEnabled
|
||||
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
|
||||
public class KubernetesClientActuatorConfiguration {
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -20,8 +20,9 @@ import io.kubernetes.client.openapi.ApiClient;
|
||||
import io.kubernetes.client.openapi.apis.CoreV1Api;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesEnabled;
|
||||
import org.springframework.boot.cloud.CloudPlatform;
|
||||
import org.springframework.cloud.kubernetes.commons.KubernetesClientProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.KubernetesCommonsAutoConfiguration;
|
||||
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
|
||||
@@ -35,7 +36,7 @@ import static org.springframework.cloud.kubernetes.client.KubernetesClientUtils.
|
||||
* @author Ryan Baxter
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnKubernetesEnabled
|
||||
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
|
||||
@AutoConfigureAfter(KubernetesCommonsAutoConfiguration.class)
|
||||
public class KubernetesClientAutoConfiguration {
|
||||
|
||||
|
||||
@@ -35,9 +35,11 @@ import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
public class KubernetesClientActuatorTests {
|
||||
|
||||
@Nested
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class, properties = {
|
||||
"management.health.kubernetes.enabled=false", "management.endpoint.health.show-details=always",
|
||||
"management.endpoint.health.show-components=always", "management.endpoints.web.exposure.include=health" })
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
|
||||
properties = { "spring.main.cloud-platform=KUBERNETES", "management.health.kubernetes.enabled=false",
|
||||
"management.endpoint.health.show-details=always",
|
||||
"management.endpoint.health.show-components=always",
|
||||
"management.endpoints.web.exposure.include=health" })
|
||||
public class DisabledHealthTest {
|
||||
|
||||
@Autowired
|
||||
@@ -62,9 +64,11 @@ public class KubernetesClientActuatorTests {
|
||||
}
|
||||
|
||||
@Nested
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class, properties = {
|
||||
"management.health.kubernetes.enabled=true", "management.endpoint.health.show-details=always",
|
||||
"management.endpoint.health.show-components=always", "management.endpoints.web.exposure.include=health" })
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
|
||||
properties = { "spring.main.cloud-platform=KUBERNETES", "management.health.kubernetes.enabled=true",
|
||||
"management.endpoint.health.show-details=always",
|
||||
"management.endpoint.health.show-components=always",
|
||||
"management.endpoints.web.exposure.include=health" })
|
||||
public class EnabledHealthTest {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -28,7 +28,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
/**
|
||||
* @author wind57
|
||||
*/
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
|
||||
properties = "spring.main.cloud-platform=KUBERNETES")
|
||||
public class KubernetesClientHealthIndicatorInsideTests {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -28,7 +28,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
/**
|
||||
* @author wind57
|
||||
*/
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
|
||||
properties = "spring.main.cloud-platform=KUBERNETES")
|
||||
public class KubernetesClientInfoContributorInsideTests {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -50,7 +50,10 @@ class KubernetesClientDefaultApiClientTests {
|
||||
|
||||
private static final String USER_AGENT = "spring.cloud.kubernetes.client.userAgent=non-default";
|
||||
|
||||
@SpringBootTest(classes = KubernetesClientDefaultApiClientTests.App.class, properties = DISABLE_INFORMER)
|
||||
private static final String ENABLED_K8S = "spring.main.cloud-platform=KUBERNETES";
|
||||
|
||||
@SpringBootTest(classes = KubernetesClientDefaultApiClientTests.App.class,
|
||||
properties = { DISABLE_INFORMER, ENABLED_K8S })
|
||||
@Nested
|
||||
class DefaultApiClientNotSameAsApiClient {
|
||||
|
||||
@@ -72,7 +75,8 @@ class KubernetesClientDefaultApiClientTests {
|
||||
|
||||
}
|
||||
|
||||
@SpringBootTest(classes = KubernetesClientDefaultApiClientTests.App.class, properties = DISABLE_INFORMER)
|
||||
@SpringBootTest(classes = KubernetesClientDefaultApiClientTests.App.class,
|
||||
properties = { DISABLE_INFORMER, ENABLED_K8S })
|
||||
@Nested
|
||||
class ApiClientUserAgentDefaultHeader {
|
||||
|
||||
@@ -94,7 +98,7 @@ class KubernetesClientDefaultApiClientTests {
|
||||
}
|
||||
|
||||
@SpringBootTest(classes = KubernetesClientDefaultApiClientTests.App.class,
|
||||
properties = { DISABLE_INFORMER, USER_AGENT })
|
||||
properties = { DISABLE_INFORMER, USER_AGENT, ENABLED_K8S })
|
||||
@Nested
|
||||
class ApiClientUserAgentNonDefaultHeader {
|
||||
|
||||
|
||||
@@ -31,7 +31,8 @@ import static org.springframework.cloud.kubernetes.commons.profile.AbstractKuber
|
||||
/**
|
||||
* @author Thomas Vitale
|
||||
*/
|
||||
@SpringBootTest(properties = { ENV_SERVICE_HOST + "=10.0.0.1", ENV_SERVICE_PORT + "=80" }, classes = { App.class })
|
||||
@SpringBootTest(properties = { ENV_SERVICE_HOST + "=10.0.0.1", ENV_SERVICE_PORT + "=80",
|
||||
"spring.main.cloud-platform=KUBERNETES" }, classes = { App.class })
|
||||
class KubernetesClientProfileEnvironmentPostProcessorTests {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -23,7 +23,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatfo
|
||||
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;
|
||||
import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesSecretsEnabled;
|
||||
import org.springframework.cloud.kubernetes.commons.KubernetesCommonsAutoConfiguration;
|
||||
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
|
||||
@@ -38,7 +37,6 @@ import org.springframework.context.annotation.Import;
|
||||
* @author Ryan Baxter
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnKubernetesEnabled
|
||||
@AutoConfigureAfter(KubernetesBootstrapConfiguration.class)
|
||||
@Import({ KubernetesCommonsAutoConfiguration.class, KubernetesClientAutoConfiguration.class })
|
||||
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
|
||||
|
||||
@@ -37,8 +37,7 @@ public class KubernetesClientBootstrapConfigurationTests {
|
||||
}
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class,
|
||||
properties = { "spring.cloud.kubernetes.enabled=false", "kubernetes.informer.enabled=false",
|
||||
"kubernetes.manifests.enabled=false" })
|
||||
properties = { "kubernetes.informer.enabled=false", "kubernetes.manifests.enabled=false" })
|
||||
@Nested
|
||||
class KubernetesDisabled {
|
||||
|
||||
@@ -158,7 +157,7 @@ public class KubernetesClientBootstrapConfigurationTests {
|
||||
// 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,
|
||||
properties = { "kubernetes.informer.enabled=false" })
|
||||
properties = { "kubernetes.manifests.enabled=false" })
|
||||
@Nested
|
||||
class KubernetesClientBootstrapConfigurationNotInsideK8s {
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ public class KubernetesClientConfigReloadAutoConfigurationTest {
|
||||
|
||||
@Test
|
||||
public void kubernetesWatchersWhenKubernetesDisabled() throws Exception {
|
||||
setup("spring.cloud.kubernetes.enabled=false");
|
||||
setup();
|
||||
assertThat(context.containsBean("configMapPropertySourceLocator")).isFalse();
|
||||
assertThat(context.containsBean("secretsPropertySourceLocator")).isFalse();
|
||||
assertThat(context.containsBean("configMapPropertyChangePollingWatcher")).isFalse();
|
||||
|
||||
@@ -33,7 +33,9 @@ import org.springframework.boot.actuate.health.HealthIndicator;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.cloud.CloudPlatform;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.client.CommonsClientAutoConfiguration;
|
||||
import org.springframework.cloud.client.ConditionalOnBlockingDiscoveryEnabled;
|
||||
@@ -41,7 +43,6 @@ import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled;
|
||||
import org.springframework.cloud.client.ConditionalOnDiscoveryHealthIndicatorEnabled;
|
||||
import org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClientAutoConfiguration;
|
||||
import org.springframework.cloud.kubernetes.client.KubernetesClientAutoConfiguration;
|
||||
import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesEnabled;
|
||||
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
|
||||
import org.springframework.cloud.kubernetes.commons.PodUtils;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryClientHealthIndicatorInitializer;
|
||||
@@ -53,7 +54,7 @@ import org.springframework.core.env.Environment;
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnKubernetesDiscoveryEnabled
|
||||
@ConditionalOnKubernetesEnabled
|
||||
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
|
||||
@AutoConfigureBefore({ SimpleDiscoveryClientAutoConfiguration.class, CommonsClientAutoConfiguration.class,
|
||||
// So that CatalogSharedInformerFactory can be processed in prior to the default
|
||||
// factory
|
||||
|
||||
@@ -30,7 +30,9 @@ import io.kubernetes.client.spring.extended.controller.annotation.KubernetesInfo
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.cloud.CloudPlatform;
|
||||
import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled;
|
||||
import org.springframework.cloud.client.ConditionalOnDiscoveryHealthIndicatorEnabled;
|
||||
import org.springframework.cloud.client.ConditionalOnReactiveDiscoveryEnabled;
|
||||
@@ -43,7 +45,6 @@ import org.springframework.cloud.client.discovery.simple.reactive.SimpleReactive
|
||||
import org.springframework.cloud.kubernetes.client.KubernetesClientPodUtils;
|
||||
import org.springframework.cloud.kubernetes.client.discovery.ConditionalOnKubernetesDiscoveryEnabled;
|
||||
import org.springframework.cloud.kubernetes.client.discovery.KubernetesDiscoveryClientAutoConfiguration;
|
||||
import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesEnabled;
|
||||
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -56,7 +57,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnDiscoveryEnabled
|
||||
@ConditionalOnReactiveDiscoveryEnabled
|
||||
@ConditionalOnKubernetesEnabled
|
||||
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
|
||||
@ConditionalOnKubernetesDiscoveryEnabled
|
||||
@AutoConfigureBefore({ SimpleReactiveDiscoveryClientAutoConfiguration.class,
|
||||
ReactiveCommonsClientAutoConfiguration.class })
|
||||
|
||||
@@ -48,8 +48,9 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
properties = { "spring.cloud.kubernetes.discovery.cacheLoadingTimeoutSeconds=5",
|
||||
"spring.cloud.config.enabled=false", "spring.cloud.kubernetes.discovery.waitCacheReady=false" })
|
||||
properties = { "spring.main.cloud-platform=KUBERNETES",
|
||||
"spring.cloud.kubernetes.discovery.cacheLoadingTimeoutSeconds=5", "spring.cloud.config.enabled=false",
|
||||
"spring.cloud.kubernetes.discovery.waitCacheReady=false" })
|
||||
public class KubernetesDiscoveryClientAutoConfigurationTests {
|
||||
|
||||
@Autowired(required = false)
|
||||
|
||||
@@ -68,8 +68,8 @@ public class KubernetesDiscoveryClientConfigClientBootstrapConfigurationTests {
|
||||
@Test
|
||||
public void onWhenRequested() throws Exception {
|
||||
setup("server.port=7000", "spring.cloud.config.discovery.enabled=true",
|
||||
"spring.cloud.kubernetes.discovery.enabled:true", "spring.cloud.kubernetes.enabled:true",
|
||||
"spring.application.name:test", "spring.cloud.config.discovery.service-id:configserver");
|
||||
"spring.cloud.kubernetes.discovery.enabled:true", "spring.application.name:test",
|
||||
"spring.cloud.config.discovery.service-id:configserver");
|
||||
assertEquals(1, this.context.getParent().getBeanNamesForType(DiscoveryClient.class).length);
|
||||
|
||||
DiscoveryClient client = this.context.getParent().getBean(DiscoveryClient.class);
|
||||
|
||||
@@ -51,9 +51,9 @@ import static org.mockito.Mockito.when;
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
properties = { "spring.cloud.kubernetes.discovery.cacheLoadingTimeoutSeconds=5",
|
||||
"spring.cloud.config.enabled=false", "spring.cloud.kubernetes.discovery.waitCacheReady=false",
|
||||
"spring.main.web-application-type=reactive" })
|
||||
properties = { "spring.main.cloud-platform=KUBERNETES",
|
||||
"spring.cloud.kubernetes.discovery.cacheLoadingTimeoutSeconds=5", "spring.cloud.config.enabled=false",
|
||||
"spring.cloud.kubernetes.discovery.waitCacheReady=false", "spring.main.web-application-type=reactive" })
|
||||
public class KubernetesInformerReactiveDiscoveryClientAutoConfigurationTests {
|
||||
|
||||
@Autowired(required = false)
|
||||
|
||||
@@ -16,9 +16,10 @@
|
||||
|
||||
package org.springframework.cloud.kubernetes.client.loadbalancer;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.cloud.CloudPlatform;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesEnabled;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.loadbalancer.KubernetesLoadBalancerProperties;
|
||||
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClients;
|
||||
@@ -30,7 +31,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@EnableConfigurationProperties(KubernetesLoadBalancerProperties.class)
|
||||
@ConditionalOnKubernetesEnabled
|
||||
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
|
||||
@ConditionalOnProperty(value = "spring.cloud.kubernetes.loadbalancer.enabled", matchIfMissing = true)
|
||||
@LoadBalancerClients(defaultConfiguration = KubernetesClientLoadBalancerClientConfiguration.class)
|
||||
public class KubernetesClientLoadBalancerAutoConfiguration {
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.kubernetes.commons;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Inherited;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
|
||||
/**
|
||||
* Provides a more succinct conditional <code>spring.cloud.kubernetes.enabled</code>.
|
||||
*
|
||||
* @author Tim Ysewyn
|
||||
* @since 2.2.0
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Inherited
|
||||
@ConditionalOnProperty(value = "spring.cloud.kubernetes.enabled", matchIfMissing = true)
|
||||
public @interface ConditionalOnKubernetesEnabled {
|
||||
|
||||
}
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.cloud.kubernetes.commons;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform;
|
||||
import org.springframework.boot.cloud.CloudPlatform;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@@ -23,7 +25,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
* @author Ryan Baxter
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnKubernetesEnabled
|
||||
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
|
||||
@EnableConfigurationProperties(KubernetesClientProperties.class)
|
||||
public class KubernetesCommonsAutoConfiguration {
|
||||
|
||||
|
||||
@@ -23,7 +23,9 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform;
|
||||
import org.springframework.boot.cloud.CloudPlatform;
|
||||
import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesConfigEnabled;
|
||||
|
||||
/**
|
||||
* @author Haytham Mohamed
|
||||
@@ -33,8 +35,8 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Inherited
|
||||
@ConditionalOnProperty(name = { "spring.cloud.kubernetes.config.enabled", "spring.cloud.kubernetes.enabled" },
|
||||
matchIfMissing = true)
|
||||
@ConditionalOnKubernetesConfigEnabled
|
||||
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
|
||||
public @interface ConditionalOnKubernetesAndConfigEnabled {
|
||||
|
||||
}
|
||||
|
||||
@@ -23,9 +23,10 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.cloud.CloudPlatform;
|
||||
import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesConfigEnabled;
|
||||
import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesEnabled;
|
||||
|
||||
/**
|
||||
* {@link org.springframework.context.annotation.Conditional @Conditional} that only
|
||||
@@ -38,7 +39,7 @@ import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesEnabl
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Inherited
|
||||
@ConditionalOnKubernetesEnabled
|
||||
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
|
||||
@ConditionalOnKubernetesConfigEnabled
|
||||
@ConditionalOnKubernetesConfigFailFastEnabled
|
||||
@ConditionalOnProperty(prefix = ConfigMapConfigProperties.PREFIX + ".retry", name = "enabled", havingValue = "true",
|
||||
|
||||
@@ -23,8 +23,9 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesEnabled;
|
||||
import org.springframework.boot.cloud.CloudPlatform;
|
||||
import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesSecretsEnabled;
|
||||
|
||||
/**
|
||||
@@ -38,7 +39,7 @@ import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesSecre
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Inherited
|
||||
@ConditionalOnKubernetesEnabled
|
||||
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
|
||||
@ConditionalOnKubernetesSecretsEnabled
|
||||
@ConditionalOnKubernetesSecretsFailFastEnabled
|
||||
@ConditionalOnProperty(prefix = SecretsConfigProperties.PREFIX + ".retry", name = "enabled", havingValue = "true",
|
||||
|
||||
@@ -20,8 +20,9 @@ import org.aspectj.lang.annotation.Aspect;
|
||||
|
||||
import org.springframework.boot.autoconfigure.aop.AopAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform;
|
||||
import org.springframework.boot.cloud.CloudPlatform;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesEnabled;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
@@ -36,7 +37,7 @@ import org.springframework.retry.policy.NeverRetryPolicy;
|
||||
* @author Isik Erhan
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnKubernetesEnabled
|
||||
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
|
||||
@EnableConfigurationProperties({ ConfigMapConfigProperties.class, SecretsConfigProperties.class })
|
||||
public class KubernetesBootstrapConfiguration {
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.cloud.CloudPlatform;
|
||||
import org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor;
|
||||
import org.springframework.boot.env.EnvironmentPostProcessor;
|
||||
import org.springframework.boot.logging.DeferredLog;
|
||||
@@ -58,12 +59,10 @@ public abstract class AbstractKubernetesProfileEnvironmentPostProcessor implemen
|
||||
|
||||
application.addInitializers(ctx -> LOG.replayTo(AbstractKubernetesProfileEnvironmentPostProcessor.class));
|
||||
|
||||
boolean kubernetesEnabled = environment.getProperty("spring.cloud.kubernetes.enabled", Boolean.class, true);
|
||||
if (!kubernetesEnabled) {
|
||||
return;
|
||||
if (CloudPlatform.KUBERNETES.isActive(environment)) {
|
||||
addNamespaceFromServiceAccountFile(environment);
|
||||
addKubernetesProfileIfMissing(environment);
|
||||
}
|
||||
addNamespaceFromServiceAccountFile(environment);
|
||||
addKubernetesProfileIfMissing(environment);
|
||||
}
|
||||
|
||||
protected abstract boolean isInsideKubernetes(Environment environment);
|
||||
|
||||
@@ -125,12 +125,6 @@
|
||||
"type": "java.time.Duration",
|
||||
"description": "Logging interval",
|
||||
"defaultValue": "20s"
|
||||
},
|
||||
{
|
||||
"name": "spring.cloud.kubernetes.enabled",
|
||||
"type": "java.lang.Boolean",
|
||||
"description": "Whether to enable Kubernetes integration.",
|
||||
"defaultValue": "true"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE,
|
||||
classes = KubernetesCommonsAutoConfigurationTests.App.class,
|
||||
properties = { "spring.cloud.kubernetes.client.password=mypassword",
|
||||
properties = { "spring.main.cloud-platform=KUBERNETES", "spring.cloud.kubernetes.client.password=mypassword",
|
||||
"spring.cloud.kubernetes.client.proxy-password=myproxypassword" })
|
||||
public class KubernetesCommonsAutoConfigurationTests {
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ public class KubernetesBootstrapConfigurationTests {
|
||||
}
|
||||
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.NONE, classes = App.class,
|
||||
properties = { "spring.cloud.kubernetes.config.fail-fast=true" })
|
||||
properties = { "spring.main.cloud-platform=KUBERNETES", "spring.cloud.kubernetes.config.fail-fast=true" })
|
||||
@Nested
|
||||
public class ConfigFailFastEnabled {
|
||||
|
||||
@@ -89,7 +89,7 @@ public class KubernetesBootstrapConfigurationTests {
|
||||
}
|
||||
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.NONE, classes = App.class,
|
||||
properties = { "spring.cloud.kubernetes.secrets.fail-fast=true" })
|
||||
properties = { "spring.main.cloud-platform=KUBERNETES", "spring.cloud.kubernetes.secrets.fail-fast=true" })
|
||||
@Nested
|
||||
public class SecretsFailFastEnabled {
|
||||
|
||||
@@ -120,8 +120,9 @@ public class KubernetesBootstrapConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.NONE, classes = App.class, properties = {
|
||||
"spring.cloud.kubernetes.config.fail-fast=true", "spring.cloud.kubernetes.secrets.fail-fast=true" })
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.NONE, classes = App.class,
|
||||
properties = { "spring.main.cloud-platform=KUBERNETES", "spring.cloud.kubernetes.config.fail-fast=true",
|
||||
"spring.cloud.kubernetes.secrets.fail-fast=true" })
|
||||
@Nested
|
||||
public class ConfigAndSecretsFailFastEnabledWithDefaultRetryConfiguration {
|
||||
|
||||
@@ -166,7 +167,7 @@ public class KubernetesBootstrapConfigurationTests {
|
||||
}
|
||||
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.NONE, classes = App.class,
|
||||
properties = { "spring.cloud.kubernetes.config.fail-fast=true",
|
||||
properties = { "spring.main.cloud-platform=KUBERNETES", "spring.cloud.kubernetes.config.fail-fast=true",
|
||||
"spring.cloud.kubernetes.config.retry.max-attempts=3",
|
||||
"spring.cloud.kubernetes.config.retry.initial-interval=1500",
|
||||
"spring.cloud.kubernetes.config.retry.max-interval=3000",
|
||||
@@ -190,7 +191,7 @@ public class KubernetesBootstrapConfigurationTests {
|
||||
}
|
||||
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.NONE, classes = App.class,
|
||||
properties = { "spring.cloud.kubernetes.secrets.fail-fast=true",
|
||||
properties = { "spring.main.cloud-platform=KUBERNETES", "spring.cloud.kubernetes.secrets.fail-fast=true",
|
||||
"spring.cloud.kubernetes.secrets.retry.max-attempts=3",
|
||||
"spring.cloud.kubernetes.secrets.retry.initial-interval=1500",
|
||||
"spring.cloud.kubernetes.secrets.retry.max-interval=3000",
|
||||
|
||||
@@ -81,12 +81,12 @@ public class AbstractKubernetesProfileEnvironmentPostProcessorTest {
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 1) "spring.cloud.kubernetes.enabled" is false; thus nothing happens
|
||||
* 1) not running on kubernetes
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
public void testKubernetesDisabled() {
|
||||
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(context, "spring.cloud.kubernetes.enabled=false");
|
||||
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(context);
|
||||
POST_PROCESSOR_INSIDE.postProcessEnvironment(context.getEnvironment(), springApplication);
|
||||
|
||||
assertKubernetesProfileNotPresent();
|
||||
@@ -96,13 +96,13 @@ public class AbstractKubernetesProfileEnvironmentPostProcessorTest {
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 1) "spring.cloud.kubernetes.enabled" is true
|
||||
* 1) "spring.main.cloud-platform=KUBERNETES"
|
||||
* 2) "spring.cloud.kubernetes.client.serviceAccountNamespacePath" is present, but does not resolve to an actual File
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
public void testKubernetesEnabledAndServiceAccountNamespacePathIsNotResolved() {
|
||||
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(context, "spring.cloud.kubernetes.enabled=true",
|
||||
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(context, "spring.main.cloud-platform=KUBERNETES",
|
||||
"spring.cloud.kubernetes.client.serviceAccountNamespacePath=" + PATH);
|
||||
serviceAccountFileResolved(false, PATH);
|
||||
POST_PROCESSOR_INSIDE.postProcessEnvironment(context.getEnvironment(), springApplication);
|
||||
@@ -114,13 +114,13 @@ public class AbstractKubernetesProfileEnvironmentPostProcessorTest {
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 1) "spring.cloud.kubernetes.enabled" is true
|
||||
* 1) "spring.main.cloud-platform=KUBERNETES"
|
||||
* 2) "spring.cloud.kubernetes.client.serviceAccountNamespacePath" is present and resolves to an actual File
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
public void testKubernetesEnabledAndServiceAccountNamespacePathIsResolved() {
|
||||
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(context, "spring.cloud.kubernetes.enabled=true",
|
||||
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(context, "spring.main.cloud-platform=KUBERNETES",
|
||||
"spring.cloud.kubernetes.client.serviceAccountNamespacePath=" + PATH);
|
||||
|
||||
Path path = serviceAccountFileResolved(true, PATH);
|
||||
@@ -135,14 +135,14 @@ public class AbstractKubernetesProfileEnvironmentPostProcessorTest {
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 1) "spring.cloud.kubernetes.enabled" is true
|
||||
* 1) "spring.main.cloud-platform=KUBERNETES"
|
||||
* 2) "spring.cloud.kubernetes.client.serviceAccountNamespacePath" is not present, as such:
|
||||
* 3) "/var/run/secrets/kubernetes.io/serviceaccount/namespace" is picked up, which is resolved and present
|
||||
* </pre>
|
||||
*/
|
||||
@Test
|
||||
public void testKubernetesEnabledAndServiceAccountNamespacePathIsResolvedViaDefaultLocation() {
|
||||
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(context, "spring.cloud.kubernetes.enabled=true");
|
||||
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(context, "spring.main.cloud-platform=KUBERNETES");
|
||||
|
||||
Path path = serviceAccountFileResolved(true, "/var/run/secrets/kubernetes.io/serviceaccount/namespace");
|
||||
mockServiceAccountNamespace(path);
|
||||
@@ -155,7 +155,7 @@ public class AbstractKubernetesProfileEnvironmentPostProcessorTest {
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 1) "spring.cloud.kubernetes.enabled" is true
|
||||
* 1) "spring.main.cloud-platform=KUBERNETES"
|
||||
* 2) isInsideKubernetes returns false
|
||||
* 3) "spring.cloud.kubernetes.client.serviceAccountNamespacePath" is not present, as such:
|
||||
* 4) "/var/run/secrets/kubernetes.io/serviceaccount/namespace" is picked up, which is resolved and present
|
||||
@@ -163,7 +163,7 @@ public class AbstractKubernetesProfileEnvironmentPostProcessorTest {
|
||||
*/
|
||||
@Test
|
||||
public void testOutsideKubernetes() {
|
||||
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(context, "spring.cloud.kubernetes.enabled=true");
|
||||
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(context, "spring.main.cloud-platform=KUBERNETES");
|
||||
|
||||
Path path = serviceAccountFileResolved(true, "/var/run/secrets/kubernetes.io/serviceaccount/namespace");
|
||||
mockServiceAccountNamespace(path);
|
||||
@@ -179,7 +179,7 @@ public class AbstractKubernetesProfileEnvironmentPostProcessorTest {
|
||||
*/
|
||||
private void assertKubernetesProfileNotPresent() {
|
||||
Assertions.assertFalse(kubernetesProfile().isPresent(),
|
||||
"'kubernetes' profile must not be present when 'spring.cloud.kubernetes.enabled' is false");
|
||||
"'kubernetes' profile must not be present when not running in kubernetes");
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -187,7 +187,7 @@ public class AbstractKubernetesProfileEnvironmentPostProcessorTest {
|
||||
*/
|
||||
private void assertKubernetesProfilePresent() {
|
||||
Assertions.assertTrue(kubernetesProfile().isPresent(),
|
||||
"'kubernetes' profile must be present when 'spring.cloud.kubernetes.enabled' is true");
|
||||
"'kubernetes' profile must be present when running in kubernetes");
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -197,7 +197,7 @@ public class AbstractKubernetesProfileEnvironmentPostProcessorTest {
|
||||
Optional<PropertySource<?>> kubernetesPropertySource = kubernetesPropertySource();
|
||||
|
||||
Assertions.assertFalse(kubernetesPropertySource.isPresent(),
|
||||
"'KUBERNETES_NAMESPACE_PROPERTY_SOURCE' source must not be present when 'spring.cloud.kubernetes.enabled' is false");
|
||||
"'KUBERNETES_NAMESPACE_PROPERTY_SOURCE' source must not be present when not running on kubernetes");
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -207,7 +207,7 @@ public class AbstractKubernetesProfileEnvironmentPostProcessorTest {
|
||||
|
||||
Optional<PropertySource<?>> kubernetesPropertySource = kubernetesPropertySource();
|
||||
Assertions.assertTrue(kubernetesPropertySource.isPresent(),
|
||||
"'KUBERNETES_NAMESPACE_PROPERTY_SOURCE' source must be present when 'spring.cloud.kubernetes.enabled' is true");
|
||||
"'KUBERNETES_NAMESPACE_PROPERTY_SOURCE' source must be present when running on kubernetes");
|
||||
|
||||
String property = (String) kubernetesPropertySource.get()
|
||||
.getProperty("spring.cloud.kubernetes.client.namespace");
|
||||
|
||||
@@ -24,7 +24,9 @@ import io.kubernetes.client.openapi.apis.CoreV1Api;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.cloud.CloudPlatform;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.config.server.config.ConfigServerAutoConfiguration;
|
||||
import org.springframework.cloud.config.server.environment.EnvironmentRepository;
|
||||
@@ -32,7 +34,6 @@ import org.springframework.cloud.kubernetes.client.KubernetesClientAutoConfigura
|
||||
import org.springframework.cloud.kubernetes.client.config.KubernetesClientConfigMapPropertySource;
|
||||
import org.springframework.cloud.kubernetes.client.config.KubernetesClientSecretsPropertySource;
|
||||
import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesConfigEnabled;
|
||||
import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesEnabled;
|
||||
import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesSecretsEnabled;
|
||||
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -48,7 +49,7 @@ import static org.springframework.cloud.kubernetes.configserver.KubernetesProper
|
||||
@Configuration
|
||||
@AutoConfigureAfter({ KubernetesClientAutoConfiguration.class })
|
||||
@AutoConfigureBefore({ ConfigServerAutoConfiguration.class })
|
||||
@ConditionalOnKubernetesEnabled
|
||||
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
|
||||
@EnableConfigurationProperties(KubernetesConfigServerProperties.class)
|
||||
public class KubernetesConfigServerAutoConfiguration {
|
||||
|
||||
|
||||
@@ -43,8 +43,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Ryan Baxter
|
||||
*/
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
properties = { "spring.cloud.kubernetes.client.namespace=default", "spring.profiles.include=kubernetes",
|
||||
"spring.cloud.kubernetes.secrets.enableApi=true", "debug=true" },
|
||||
properties = { "spring.main.cloud-platform=KUBERNETES", "spring.cloud.kubernetes.client.namespace=default",
|
||||
"spring.profiles.include=kubernetes", "spring.cloud.kubernetes.secrets.enableApi=true", "debug=true" },
|
||||
classes = { KubernetesConfigServerApplication.class })
|
||||
public class ConfigServerIntegrationTest {
|
||||
|
||||
|
||||
@@ -48,8 +48,7 @@ public class KubernetesConfigServerAutoConfigurationTests {
|
||||
|
||||
@Nested
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
properties = { "spring.profiles.include=kubernetes,kubernetesdisabled",
|
||||
"spring.cloud.kubernetes.enabled=false", "debug=true" },
|
||||
properties = { "spring.profiles.include=kubernetes,kubernetesdisabled", "debug=true" },
|
||||
classes = { KubernetesConfigServerApplication.class, MockConfig.class })
|
||||
public class KubernetesDisabled {
|
||||
|
||||
@@ -65,8 +64,7 @@ public class KubernetesConfigServerAutoConfigurationTests {
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = { KubernetesConfigServerApplication.class, MockConfig.class },
|
||||
properties = { "spring.cloud.kubernetes.enabled=false",
|
||||
"spring.profiles.include=kubernetes,kubernetesdisabled", "debug=true" })
|
||||
properties = { "spring.profiles.include=kubernetes,kubernetesdisabled", "debug=true" })
|
||||
@Nested
|
||||
class KubernetesProfileMissing {
|
||||
|
||||
@@ -81,8 +79,9 @@ public class KubernetesConfigServerAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = { KubernetesConfigServerApplication.class }, properties = { "spring.profiles.include=kubernetes",
|
||||
"debug=true", "spring.cloud.kubernetes.client.namespace=default" })
|
||||
classes = { KubernetesConfigServerApplication.class },
|
||||
properties = { "spring.main.cloud-platform=KUBERNETES", "spring.profiles.include=kubernetes", "debug=true",
|
||||
"spring.cloud.kubernetes.client.namespace=default" })
|
||||
@Nested
|
||||
class KubernetesEnabledProfileIncluded {
|
||||
|
||||
@@ -98,8 +97,10 @@ public class KubernetesConfigServerAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = { KubernetesConfigServerApplication.class }, properties = { "spring.profiles.include=kubernetes",
|
||||
"debug=true", "spring.cloud.kubernetes.config.enabled=false" })
|
||||
classes = { KubernetesConfigServerApplication.class },
|
||||
properties = { "spring.main.cloud-platform=KUBERNETES", // STOPSHIP: 11/10/21
|
||||
"spring.profiles.include=kubernetes", "debug=true",
|
||||
"spring.cloud.kubernetes.config.enabled=false" })
|
||||
@Nested
|
||||
class KubernetesEnabledProfileIncludedConfigMapDisabled {
|
||||
|
||||
@@ -115,8 +116,9 @@ public class KubernetesConfigServerAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = { KubernetesConfigServerApplication.class }, properties = { "spring.profiles.include=kubernetes",
|
||||
"debug=true", "spring.cloud.kubernetes.client.namespace=default" })
|
||||
classes = { KubernetesConfigServerApplication.class },
|
||||
properties = { "spring.main.cloud-platform=KUBERNETES", "spring.profiles.include=kubernetes", "debug=true",
|
||||
"spring.cloud.kubernetes.client.namespace=default" })
|
||||
@Nested
|
||||
class KubernetesEnabledProfileIncludedSecretsApiDisabled {
|
||||
|
||||
@@ -135,7 +137,7 @@ public class KubernetesConfigServerAutoConfigurationTests {
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = { KubernetesConfigServerApplication.class },
|
||||
properties = { "spring.profiles.include=kubernetes", "debug=true",
|
||||
properties = { "spring.main.cloud-platform=KUBERNETES", "spring.profiles.include=kubernetes", "debug=true",
|
||||
"spring.cloud.kubernetes.client.namespace=default",
|
||||
"spring.cloud.kubernetes.secrets.enableApi=true" })
|
||||
@Nested
|
||||
@@ -154,7 +156,7 @@ public class KubernetesConfigServerAutoConfigurationTests {
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = { KubernetesConfigServerApplication.class },
|
||||
properties = { "spring.profiles.include=kubernetes", "debug=true",
|
||||
properties = { "spring.main.cloud-platform=KUBERNETES", "spring.profiles.include=kubernetes", "debug=true",
|
||||
"spring.cloud.kubernetes.client.namespace=default",
|
||||
"spring.cloud.kubernetes.config.enableApi=false" })
|
||||
@Nested
|
||||
|
||||
@@ -19,9 +19,11 @@ package org.springframework.cloud.kubernetes.discovery;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.boot.actuate.health.HealthIndicator;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.cloud.CloudPlatform;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||
import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled;
|
||||
@@ -44,8 +46,8 @@ import org.springframework.web.reactive.function.client.WebClient;
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnDiscoveryEnabled
|
||||
@ConditionalOnProperty(value = { "spring.cloud.kubernetes.enabled", "spring.cloud.kubernetes.discovery.enabled" },
|
||||
matchIfMissing = true)
|
||||
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
|
||||
@ConditionalOnProperty(value = "spring.cloud.kubernetes.discovery.enabled", matchIfMissing = true)
|
||||
@EnableConfigurationProperties({ DiscoveryClientHealthIndicatorProperties.class,
|
||||
KubernetesDiscoveryClientProperties.class })
|
||||
public class KubernetesDiscoveryClientAutoConfiguration {
|
||||
|
||||
@@ -41,7 +41,8 @@ class KubernetesDiscoveryClientAutoConfigurationTests {
|
||||
@Test
|
||||
public void shouldWorkWithDefaults() {
|
||||
contextRunner
|
||||
.withPropertyValues("spring.cloud.kubernetes.discovery.discovery-server-url=http://k8sdiscoveryserver")
|
||||
.withPropertyValues("spring.main.cloud-platform=KUBERNETES",
|
||||
"spring.cloud.kubernetes.discovery.discovery-server-url=http://k8sdiscoveryserver")
|
||||
.withClassLoader(new FilteredClassLoader("org.springframework.web.reactive")).run(context -> {
|
||||
assertThat(context).hasSingleBean(DiscoveryClient.class);
|
||||
assertThat(context).doesNotHaveBean(ReactiveDiscoveryClient.class);
|
||||
@@ -76,7 +77,8 @@ class KubernetesDiscoveryClientAutoConfigurationTests {
|
||||
@Test
|
||||
public void shouldHaveReactiveDiscoveryClient() {
|
||||
contextRunner
|
||||
.withPropertyValues("spring.cloud.kubernetes.discovery.discovery-server-url=http://k8sdiscoveryserver")
|
||||
.withPropertyValues("spring.main.cloud-platform=KUBERNETES",
|
||||
"spring.cloud.kubernetes.discovery.discovery-server-url=http://k8sdiscoveryserver")
|
||||
.run(context -> {
|
||||
assertThat(context).hasSingleBean(ReactiveDiscoveryClient.class);
|
||||
assertThat(context).doesNotHaveBean(DiscoveryClient.class);
|
||||
@@ -94,7 +96,7 @@ class KubernetesDiscoveryClientAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void shouldNotHaveDiscoveryClientWhenKubernetesDisabled() {
|
||||
contextRunner.withPropertyValues("spring.cloud.kubernetes.enabled=false").run(context -> {
|
||||
contextRunner.run(context -> {
|
||||
assertThat(context).doesNotHaveBean(ReactiveDiscoveryClient.class);
|
||||
assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class);
|
||||
});
|
||||
@@ -103,7 +105,8 @@ class KubernetesDiscoveryClientAutoConfigurationTests {
|
||||
@Test
|
||||
public void worksWithoutActuator() {
|
||||
contextRunner
|
||||
.withPropertyValues("spring.cloud.kubernetes.discovery.discovery-server-url=http://k8sdiscoveryserver")
|
||||
.withPropertyValues("spring.main.cloud-platform=KUBERNETES",
|
||||
"spring.cloud.kubernetes.discovery.discovery-server-url=http://k8sdiscoveryserver")
|
||||
.withClassLoader(new FilteredClassLoader("org.springframework.boot.actuate")).run(context -> {
|
||||
assertThat(context).hasSingleBean(ReactiveDiscoveryClient.class);
|
||||
assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class);
|
||||
|
||||
@@ -22,7 +22,8 @@ import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnable
|
||||
import org.springframework.boot.actuate.autoconfigure.info.ConditionalOnEnabledInfoContributor;
|
||||
import org.springframework.boot.actuate.health.HealthIndicator;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesEnabled;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform;
|
||||
import org.springframework.boot.cloud.CloudPlatform;
|
||||
import org.springframework.cloud.kubernetes.commons.PodUtils;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -32,7 +33,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnClass(HealthIndicator.class)
|
||||
@ConditionalOnKubernetesEnabled
|
||||
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
|
||||
public class Fabric8ActuatorConfiguration {
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -26,8 +26,9 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesEnabled;
|
||||
import org.springframework.boot.cloud.CloudPlatform;
|
||||
import org.springframework.cloud.kubernetes.commons.KubernetesClientProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.KubernetesCommonsAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -41,7 +42,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
* @author Tim Ysewyn
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnKubernetesEnabled
|
||||
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
|
||||
@AutoConfigureAfter(KubernetesCommonsAutoConfiguration.class)
|
||||
public class Fabric8AutoConfiguration {
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
|
||||
properties = { "spring.cloud.kubernetes.client.password=mypassword",
|
||||
properties = { "spring.main.cloud-platform=KUBERNETES", "spring.cloud.kubernetes.client.password=mypassword",
|
||||
"spring.cloud.kubernetes.client.proxy-password=myproxypassword" })
|
||||
@EnableKubernetesMockClient(crud = true, https = false)
|
||||
public class Fabric8AutoConfigurationTests {
|
||||
|
||||
@@ -47,8 +47,8 @@ import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
*/
|
||||
@Import(Fabric8InsideInfoContributorTest.InfoContributorTestConfig.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
|
||||
properties = { "management.endpoints.web.exposure.include=info", "management.endpoint.info.show-details=always",
|
||||
"management.info.kubernetes.enabled=true" })
|
||||
properties = { "spring.main.cloud-platform=KUBERNETES", "management.endpoints.web.exposure.include=info",
|
||||
"management.endpoint.info.show-details=always", "management.info.kubernetes.enabled=true" })
|
||||
public class Fabric8InsideInfoContributorTest {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -37,7 +37,7 @@ import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
|
||||
properties = { "management.endpoint.health.show-details=always" })
|
||||
properties = { "spring.main.cloud-platform=KUBERNETES", "management.endpoint.health.show-details=always" })
|
||||
@EnableKubernetesMockClient(crud = true, https = false)
|
||||
public class Fabric8NotInsideHealthIndicatorTest {
|
||||
|
||||
|
||||
@@ -34,8 +34,8 @@ import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
|
||||
properties = { "management.endpoints.web.exposure.include=info", "management.endpoint.info.show-details=always",
|
||||
"management.info.kubernetes.enabled=true" })
|
||||
properties = { "spring.main.cloud-platform=KUBERNETES", "management.endpoints.web.exposure.include=info",
|
||||
"management.endpoint.info.show-details=always", "management.info.kubernetes.enabled=true" })
|
||||
@EnableKubernetesMockClient(crud = true, https = false)
|
||||
public class Fabric8NotInsideInfoContributorTest {
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* test "User-Agent" functionality via system properties
|
||||
*/
|
||||
@SpringBootTest(classes = App.class)
|
||||
@SpringBootTest(classes = App.class, properties = "spring.main.cloud-platform=KUBERNETES")
|
||||
class Fabric8ClientUserAgentEnvPropertyTests {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -35,8 +35,10 @@ class Fabric8ClientUserAgentTests {
|
||||
|
||||
private static final String USER_AGENT = "spring.cloud.kubernetes.client.userAgent=non-default";
|
||||
|
||||
private static final String ENABLED_K8S = "spring.main.cloud-platform=KUBERNETES";
|
||||
|
||||
@Nested
|
||||
@SpringBootTest(classes = App.class)
|
||||
@SpringBootTest(classes = App.class, properties = ENABLED_K8S)
|
||||
class DefaultConfigurationForClient {
|
||||
|
||||
@Autowired
|
||||
@@ -51,7 +53,7 @@ class Fabric8ClientUserAgentTests {
|
||||
}
|
||||
|
||||
@Nested
|
||||
@SpringBootTest(classes = App.class, properties = USER_AGENT)
|
||||
@SpringBootTest(classes = App.class, properties = { USER_AGENT, ENABLED_K8S })
|
||||
class PropertiesConfigurationForClient {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -33,8 +33,8 @@ class Fabric8ProfileEnvironmentPostProcessorTests {
|
||||
@Test
|
||||
void whenKubernetesEnvironmentAndNoApiAccessThenProfileEnabled() {
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder(App.class)
|
||||
.web(org.springframework.boot.WebApplicationType.NONE).properties("KUBERNETES_SERVICE_HOST=10.0.0.1")
|
||||
.run();
|
||||
.web(org.springframework.boot.WebApplicationType.NONE)
|
||||
.properties("KUBERNETES_SERVICE_HOST=10.0.0.1", "spring.main.cloud-platform=KUBERNETES").run();
|
||||
|
||||
assertThat(context.getEnvironment().getActiveProfiles()).contains(KUBERNETES_PROFILE);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ 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;
|
||||
import org.springframework.cloud.kubernetes.commons.KubernetesCommonsAutoConfiguration;
|
||||
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
|
||||
@@ -44,7 +43,6 @@ import org.springframework.core.env.Environment;
|
||||
* @author Ioannis Canellos
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnKubernetesEnabled
|
||||
@Import({ KubernetesCommonsAutoConfiguration.class, Fabric8AutoConfiguration.class })
|
||||
@ConditionalOnClass({ ConfigMap.class, Secret.class })
|
||||
@AutoConfigureAfter(KubernetesBootstrapConfiguration.class)
|
||||
|
||||
@@ -22,8 +22,10 @@ import io.fabric8.kubernetes.client.KubernetesClient;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.cloud.CloudPlatform;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.commons.util.TaskSchedulerWrapper;
|
||||
import org.springframework.cloud.kubernetes.commons.config.reload.ConfigReloadProperties;
|
||||
@@ -48,7 +50,7 @@ import org.springframework.core.env.AbstractEnvironment;
|
||||
* @author Kris Iyer
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnProperty(value = "spring.cloud.kubernetes.enabled", matchIfMissing = true)
|
||||
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
|
||||
@ConditionalOnMissingBean(ConfigReloadAutoConfiguration.class)
|
||||
@EnableConfigurationProperties(ConfigReloadProperties.class)
|
||||
public class ConfigReloadDefaultAutoConfiguration {
|
||||
|
||||
@@ -30,9 +30,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@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" })
|
||||
properties = { "spring.main.cloud-platform=KUBERNETES", "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" })
|
||||
public class CoreTestClientViaSystemProperties {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -66,9 +66,9 @@ public class Fabric8ActuatorTests {
|
||||
|
||||
@Nested
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class, properties = {
|
||||
"management.health.kubernetes.enabled=true", "management.endpoint.health.show-details=always",
|
||||
"management.endpoint.health.show-components=always", "management.endpoints.web.exposure.include=health",
|
||||
"spring.cloud.kubernetes.client.namespace=default" })
|
||||
"spring.main.cloud-platform=KUBERNETES", "management.health.kubernetes.enabled=true",
|
||||
"management.endpoint.health.show-details=always", "management.endpoint.health.show-components=always",
|
||||
"management.endpoints.web.exposure.include=health", "spring.cloud.kubernetes.client.namespace=default" })
|
||||
public class EnabledHealthTest {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -30,8 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class Fabric8BootstrapConfigurationTests {
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class,
|
||||
properties = "spring.cloud.kubernetes.enabled=false")
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class)
|
||||
@Nested
|
||||
class KubernetesDisabled {
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ import static org.hamcrest.Matchers.containsString;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
|
||||
properties = { "management.endpoint.health.show-details=always" })
|
||||
properties = { "spring.main.cloud-platform=KUBERNETES", "management.endpoint.health.show-details=always" })
|
||||
@EnableKubernetesMockClient(crud = true, https = false)
|
||||
public class HealthIndicatorTest {
|
||||
|
||||
|
||||
@@ -42,15 +42,15 @@ public class KubernetesConfigConfigurationTest extends KubernetesConfigTestBase
|
||||
|
||||
@Test
|
||||
public void kubernetesWhenKubernetesDefaultEnabled() {
|
||||
setup(KubernetesClientTestConfiguration.class, "spring.cloud.kubernetes.enabled=true",
|
||||
"spring.cloud.kubernetes.client.namespace=default", "spring.main.cloud-platform=KUBERNETES");
|
||||
setup(KubernetesClientTestConfiguration.class, "spring.main.cloud-platform=KUBERNETES",
|
||||
"spring.cloud.kubernetes.client.namespace=default");
|
||||
assertThat(getContext().containsBean("configMapPropertySourceLocator")).isTrue();
|
||||
assertThat(getContext().containsBean("secretsPropertySourceLocator")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void kubernetesWhenKubernetesDisabled() {
|
||||
setup(KubernetesClientTestConfiguration.class, "spring.cloud.kubernetes.enabled=false");
|
||||
setup(KubernetesClientTestConfiguration.class);
|
||||
assertThat(getContext().containsBean("configMapPropertySourceLocator")).isFalse();
|
||||
assertThat(getContext().containsBean("secretsPropertySourceLocator")).isFalse();
|
||||
}
|
||||
@@ -91,8 +91,7 @@ public class KubernetesConfigConfigurationTest extends KubernetesConfigTestBase
|
||||
|
||||
@Test
|
||||
public void kubernetesConfigWhenKubernetesEnabledAndKubernetesConfigDisabled() {
|
||||
setup(KubernetesClientTestConfiguration.class, "spring.cloud.kubernetes.enabled=true",
|
||||
"spring.cloud.kubernetes.config.enabled=false");
|
||||
setup(KubernetesClientTestConfiguration.class, "spring.cloud.kubernetes.config.enabled=false");
|
||||
assertThat(getContext().containsBean("configMapPropertySourceLocator")).isFalse();
|
||||
}
|
||||
|
||||
|
||||
@@ -90,16 +90,16 @@ public class ConfigReloadAutoConfigurationTest extends KubernetesConfigTestBase
|
||||
|
||||
@Test
|
||||
public void kubernetesConfigReloadWhenKubernetesDisabled() {
|
||||
setup(KubernetesClientTestConfiguration.class, "spring.cloud.kubernetes.enabled=false");
|
||||
setup(KubernetesClientTestConfiguration.class);
|
||||
assertThat(this.getContext().containsBean("configurationChangeDetector")).isFalse();
|
||||
assertThat(this.getContext().containsBean("configurationUpdateStrategy")).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void kubernetesReloadEnabled() {
|
||||
setup(KubernetesClientTestConfiguration.class, "spring.cloud.kubernetes.enabled=true",
|
||||
setup(KubernetesClientTestConfiguration.class, "spring.main.cloud-platform=KUBERNETES",
|
||||
"spring.cloud.kubernetes.config.enabled=true", "spring.cloud.kubernetes.secrets.enabled=true",
|
||||
"spring.cloud.kubernetes.reload.enabled=true", "spring.main.cloud-platform=KUBERNETES");
|
||||
"spring.cloud.kubernetes.reload.enabled=true");
|
||||
assertThat(this.getContext().containsBean("configMapPropertySourceLocator")).isTrue();
|
||||
assertThat(this.getContext().containsBean("secretsPropertySourceLocator")).isTrue();
|
||||
assertThat(this.getContext().containsBean("configMapPropertyChangeEventWatcher")).isTrue();
|
||||
@@ -108,9 +108,9 @@ public class ConfigReloadAutoConfigurationTest extends KubernetesConfigTestBase
|
||||
|
||||
@Test
|
||||
public void kubernetesReloadEnabledButSecretDisabled() {
|
||||
setup(KubernetesClientTestConfiguration.class, "spring.cloud.kubernetes.enabled=true",
|
||||
setup(KubernetesClientTestConfiguration.class, "spring.main.cloud-platform=KUBERNETES",
|
||||
"spring.cloud.kubernetes.config.enabled=true", "spring.cloud.kubernetes.secrets.enabled=false",
|
||||
"spring.cloud.kubernetes.reload.enabled=true", "spring.main.cloud-platform=KUBERNETES");
|
||||
"spring.cloud.kubernetes.reload.enabled=true");
|
||||
assertThat(this.getContext().containsBean("configMapPropertySourceLocator")).isTrue();
|
||||
assertThat(this.getContext().containsBean("secretsPropertySourceLocator")).isFalse();
|
||||
assertThat(this.getContext().containsBean("configMapPropertyChangeEventWatcher")).isTrue();
|
||||
@@ -119,9 +119,8 @@ public class ConfigReloadAutoConfigurationTest extends KubernetesConfigTestBase
|
||||
|
||||
@Test
|
||||
public void kubernetesReloadEnabledButSecretAndConfigDisabled() {
|
||||
setup(KubernetesClientTestConfiguration.class, "spring.cloud.kubernetes.enabled=true",
|
||||
"spring.cloud.kubernetes.config.enabled=false", "spring.cloud.kubernetes.secrets.enabled=false",
|
||||
"spring.cloud.kubernetes.reload.enabled=true");
|
||||
setup(KubernetesClientTestConfiguration.class, "spring.cloud.kubernetes.config.enabled=false",
|
||||
"spring.cloud.kubernetes.secrets.enabled=false", "spring.cloud.kubernetes.reload.enabled=true");
|
||||
assertThat(this.getContext().containsBean("configMapPropertySourceLocator")).isFalse();
|
||||
assertThat(this.getContext().containsBean("secretsPropertySourceLocator")).isFalse();
|
||||
assertThat(this.getContext().containsBean("propertyChangeWatcher")).isFalse();
|
||||
|
||||
@@ -19,8 +19,10 @@ package org.springframework.cloud.kubernetes.fabric8.discovery;
|
||||
import io.fabric8.kubernetes.client.KubernetesClient;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.cloud.CloudPlatform;
|
||||
import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.cloud.kubernetes.fabric8.Fabric8AutoConfiguration;
|
||||
@@ -34,7 +36,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnDiscoveryEnabled
|
||||
@ConditionalOnProperty(name = "spring.cloud.kubernetes.enabled", matchIfMissing = true)
|
||||
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
|
||||
@AutoConfigureAfter({ Fabric8AutoConfiguration.class })
|
||||
public class KubernetesCatalogWatchAutoConfiguration {
|
||||
|
||||
|
||||
@@ -22,13 +22,14 @@ import org.springframework.boot.actuate.health.HealthIndicator;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.cloud.CloudPlatform;
|
||||
import org.springframework.cloud.client.CommonsClientAutoConfiguration;
|
||||
import org.springframework.cloud.client.ConditionalOnBlockingDiscoveryEnabled;
|
||||
import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled;
|
||||
import org.springframework.cloud.client.ConditionalOnDiscoveryHealthIndicatorEnabled;
|
||||
import org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClientAutoConfiguration;
|
||||
import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesEnabled;
|
||||
import org.springframework.cloud.kubernetes.commons.PodUtils;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryClientHealthIndicatorInitializer;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
|
||||
@@ -45,7 +46,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnDiscoveryEnabled
|
||||
@ConditionalOnKubernetesEnabled
|
||||
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
|
||||
@AutoConfigureBefore({ SimpleDiscoveryClientAutoConfiguration.class, CommonsClientAutoConfiguration.class })
|
||||
@AutoConfigureAfter({ Fabric8AutoConfiguration.class })
|
||||
public class KubernetesDiscoveryClientAutoConfiguration {
|
||||
|
||||
@@ -21,7 +21,9 @@ import io.fabric8.kubernetes.client.KubernetesClient;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.cloud.CloudPlatform;
|
||||
import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled;
|
||||
import org.springframework.cloud.client.ConditionalOnDiscoveryHealthIndicatorEnabled;
|
||||
import org.springframework.cloud.client.ConditionalOnReactiveDiscoveryEnabled;
|
||||
@@ -30,7 +32,6 @@ import org.springframework.cloud.client.discovery.composite.reactive.ReactiveCom
|
||||
import org.springframework.cloud.client.discovery.health.DiscoveryClientHealthIndicatorProperties;
|
||||
import org.springframework.cloud.client.discovery.health.reactive.ReactiveDiscoveryClientHealthIndicator;
|
||||
import org.springframework.cloud.client.discovery.simple.reactive.SimpleReactiveDiscoveryClientAutoConfiguration;
|
||||
import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesEnabled;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.cloud.kubernetes.fabric8.discovery.ConditionalOnKubernetesDiscoveryEnabled;
|
||||
import org.springframework.cloud.kubernetes.fabric8.discovery.KubernetesClientServicesFunction;
|
||||
@@ -46,7 +47,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnDiscoveryEnabled
|
||||
@ConditionalOnReactiveDiscoveryEnabled
|
||||
@ConditionalOnKubernetesEnabled
|
||||
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
|
||||
@ConditionalOnKubernetesDiscoveryEnabled
|
||||
@AutoConfigureBefore({ SimpleReactiveDiscoveryClientAutoConfiguration.class,
|
||||
ReactiveCommonsClientAutoConfiguration.class })
|
||||
|
||||
@@ -60,7 +60,7 @@ public class KubernetesCatalogServicesWatchConfigurationTest {
|
||||
|
||||
@Test
|
||||
public void kubernetesCatalogWatchWhenKubernetesDisabled() throws Exception {
|
||||
setup("spring.cloud.kubernetes.enabled=false");
|
||||
setup();
|
||||
assertThat(this.context.containsBean("kubernetesCatalogWatch")).isFalse();
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ public class KubernetesCatalogServicesWatchConfigurationTest {
|
||||
|
||||
@Test
|
||||
public void kubernetesCatalogWatchDefaultEnabled() throws Exception {
|
||||
setup();
|
||||
setup("spring.main.cloud-platform=KUBERNETES");
|
||||
assertThat(this.context.containsBean("kubernetesCatalogWatch")).isTrue();
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ public class KubernetesDiscoveryClientAutoConfigurationPropertiesTests {
|
||||
|
||||
@Test
|
||||
public void kubernetesDiscoveryWhenKubernetesDisabled() throws Exception {
|
||||
setup("spring.cloud.kubernetes.enabled=false");
|
||||
setup();
|
||||
assertThat(this.context.getBeanNamesForType(KubernetesDiscoveryClient.class)).isEmpty();
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ public class KubernetesDiscoveryClientAutoConfigurationPropertiesTests {
|
||||
|
||||
@Test
|
||||
public void kubernetesDiscoveryDefaultEnabled() throws Exception {
|
||||
setup("spring.cloud.kubernetes.enabled=true");
|
||||
setup("spring.main.cloud-platform=KUBERNETES");
|
||||
assertThat(this.context.getBeanNamesForType(KubernetesDiscoveryClient.class)).hasSize(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,8 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = "spring.cloud.config.enabled=false")
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
|
||||
properties = { "spring.main.cloud-platform=KUBERNETES", "spring.cloud.config.enabled=false" })
|
||||
public class KubernetesDiscoveryClientAutoConfigurationTests {
|
||||
|
||||
@Autowired(required = false)
|
||||
|
||||
@@ -60,8 +60,8 @@ public class KubernetesDiscoveryClientConfigClientBootstrapConfigurationTests {
|
||||
@Test
|
||||
public void onWhenRequested() throws Exception {
|
||||
setup("server.port=7000", "spring.cloud.config.discovery.enabled=true",
|
||||
"spring.cloud.kubernetes.discovery.enabled:true", "spring.cloud.kubernetes.enabled:true",
|
||||
"spring.application.name:test", "spring.cloud.config.discovery.service-id:configserver");
|
||||
"spring.cloud.kubernetes.discovery.enabled:true", "spring.application.name:test",
|
||||
"spring.cloud.config.discovery.service-id:configserver");
|
||||
assertEquals(1, this.context.getParent().getBeanNamesForType(DiscoveryClient.class).length);
|
||||
DiscoveryClient client = this.context.getParent().getBean(DiscoveryClient.class);
|
||||
verify(client, atLeast(2)).getInstances("configserver");
|
||||
|
||||
@@ -44,7 +44,7 @@ class KubernetesReactiveDiscoveryClientAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void shouldWorkWithDefaults() {
|
||||
contextRunner.run(context -> {
|
||||
contextRunner.withPropertyValues("spring.main.cloud-platform=KUBERNETES").run(context -> {
|
||||
assertThat(context).hasSingleBean(ReactiveDiscoveryClient.class);
|
||||
assertThat(context).hasSingleBean(ReactiveDiscoveryClientHealthIndicator.class);
|
||||
});
|
||||
@@ -70,7 +70,7 @@ class KubernetesReactiveDiscoveryClientAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void shouldNotHaveDiscoveryClientWhenKubernetesDisabled() {
|
||||
contextRunner.withPropertyValues("spring.cloud.kubernetes.enabled=false").run(context -> {
|
||||
contextRunner.run(context -> {
|
||||
assertThat(context).doesNotHaveBean("kubernetesReactiveDiscoveryClient");
|
||||
assertThat(context).doesNotHaveBean(ReactiveDiscoveryClient.class);
|
||||
assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class);
|
||||
@@ -96,10 +96,11 @@ class KubernetesReactiveDiscoveryClientAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void worksWithoutActuator() {
|
||||
contextRunner.withClassLoader(new FilteredClassLoader("org.springframework.boot.actuate")).run(context -> {
|
||||
assertThat(context).hasSingleBean(ReactiveDiscoveryClient.class);
|
||||
assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class);
|
||||
});
|
||||
contextRunner.withPropertyValues("spring.main.cloud-platform=KUBERNETES")
|
||||
.withClassLoader(new FilteredClassLoader("org.springframework.boot.actuate")).run(context -> {
|
||||
assertThat(context).hasSingleBean(ReactiveDiscoveryClient.class);
|
||||
assertThat(context).doesNotHaveBean(ReactiveDiscoveryClientHealthIndicator.class);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,9 +20,10 @@ import io.fabric8.kubernetes.client.Config;
|
||||
import me.snowdrop.istio.client.DefaultIstioClient;
|
||||
import me.snowdrop.istio.client.IstioClient;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesEnabled;
|
||||
import org.springframework.boot.cloud.CloudPlatform;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@@ -33,7 +34,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnProperty(value = "spring.cloud.istio.enabled", matchIfMissing = true)
|
||||
@ConditionalOnKubernetesEnabled
|
||||
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
|
||||
public class IstioAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -31,7 +31,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class IstioAutoConfigurationTests {
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
|
||||
properties = "spring.main.cloud-platform=KUBERNETES")
|
||||
@Nested
|
||||
class IstioClientPresentByDefault {
|
||||
|
||||
@@ -45,8 +46,7 @@ public class IstioAutoConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
|
||||
properties = { "spring.cloud.kubernetes.enabled=false" })
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class)
|
||||
@Nested
|
||||
class IstioClientNotPresentWhenKubernetesDisabled {
|
||||
|
||||
@@ -61,7 +61,7 @@ public class IstioAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class,
|
||||
properties = { "spring.cloud.istio.enabled=true" })
|
||||
properties = { "spring.main.cloud-platform=KUBERNETES", "spring.cloud.istio.enabled=true" })
|
||||
@Nested
|
||||
class IstioClientPresentWhenIstioEnabled {
|
||||
|
||||
|
||||
@@ -31,10 +31,10 @@ import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = {
|
||||
// Make sure test passes without Kubernetes cluster
|
||||
"spring.cloud.kubernetes.leader.autoStartup=false", "management.endpoints.web.exposure.include=info",
|
||||
"management.endpoint.info.show-details=always", "management.info.kubernetes.enabled=true" })
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
properties = { "spring.main.cloud-platform=KUBERNETES", "spring.cloud.kubernetes.leader.autoStartup=false",
|
||||
"management.endpoints.web.exposure.include=info", "management.endpoint.info.show-details=always",
|
||||
"management.info.kubernetes.enabled=true" })
|
||||
public class Fabric8LeaderAutoConfigurationTests {
|
||||
|
||||
@Value("${local.server.port}")
|
||||
|
||||
@@ -16,9 +16,10 @@
|
||||
|
||||
package org.springframework.cloud.kubernetes.fabric8.loadbalancer;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.cloud.CloudPlatform;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.ConditionalOnKubernetesEnabled;
|
||||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.loadbalancer.KubernetesLoadBalancerProperties;
|
||||
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClients;
|
||||
@@ -32,7 +33,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@EnableConfigurationProperties(KubernetesLoadBalancerProperties.class)
|
||||
@ConditionalOnKubernetesEnabled
|
||||
@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES)
|
||||
@ConditionalOnProperty(value = "spring.cloud.kubernetes.loadbalancer.enabled", matchIfMissing = true)
|
||||
@LoadBalancerClients(defaultConfiguration = Fabric8LoadBalancerClientConfiguration.class)
|
||||
public class Fabric8LoadBalancerAutoConfiguration {
|
||||
|
||||
@@ -41,31 +41,31 @@ class Fabric8LoadBalancerAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
void kubernetesLoadBalancerWhenKubernetesDisabledAndLoadBalancerDisabled() {
|
||||
setup("spring.cloud.kubernetes.enabled=false", "spring.cloud.kubernetes.loadbalancer.enabled=false");
|
||||
setup("spring.cloud.kubernetes.loadbalancer.enabled=false");
|
||||
assertThat(this.context.getBeanNamesForType(Fabric8ServiceInstanceMapper.class)).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void kubernetesLoadBalancerWhenKubernetesDisabledAndLoadBalancerEnabled() {
|
||||
setup("spring.cloud.kubernetes.enabled=false", "spring.cloud.kubernetes.loadbalancer.enabled=true");
|
||||
setup("spring.cloud.kubernetes.loadbalancer.enabled=true");
|
||||
assertThat(this.context.getBeanNamesForType(Fabric8ServiceInstanceMapper.class)).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void kubernetesLoadBalancerWhenKubernetesEnabledAndLoadBalancerEnabled() {
|
||||
setup("spring.cloud.kubernetes.enabled=true", "spring.cloud.kubernetes.loadbalancer.enabled=true");
|
||||
setup("spring.main.cloud-platform=KUBERNETES", "spring.cloud.kubernetes.loadbalancer.enabled=true");
|
||||
assertThat(this.context.getBeanNamesForType(Fabric8ServiceInstanceMapper.class)).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void kubernetesLoadBalancerWhenKubernetesEnabledAndLoadBalancerDisabled() {
|
||||
setup("spring.cloud.kubernetes.enabled=true", "spring.cloud.kubernetes.loadbalancer.enabled=false");
|
||||
setup("spring.cloud.kubernetes.loadbalancer.enabled=false");
|
||||
assertThat(this.context.getBeanNamesForType(Fabric8ServiceInstanceMapper.class)).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void kubernetesLoadBalancerWhenDefaultProperties() {
|
||||
setup();
|
||||
setup("spring.main.cloud-platform=KUBERNETES");
|
||||
assertThat(this.context.getBeanNamesForType(Fabric8ServiceInstanceMapper.class)).hasSize(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,8 @@ import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@TestPropertySource(properties = "spring.cloud.kubernetes.discovery.all-namespaces=true")
|
||||
@TestPropertySource(properties = { "spring.main.cloud-platform=KUBERNETES",
|
||||
"spring.cloud.kubernetes.discovery.all-namespaces=true" })
|
||||
@EnableKubernetesMockClient(crud = true, https = false)
|
||||
class LoadBalancerAllNamespacesTests {
|
||||
|
||||
|
||||
@@ -32,7 +32,8 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
properties = "spring.main.cloud-platform=KUBERNETES")
|
||||
@EnableKubernetesMockClient(crud = true, https = false)
|
||||
class LoadBalancerTests {
|
||||
|
||||
|
||||
@@ -43,8 +43,8 @@ import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@TestPropertySource(properties = { "spring.cloud.kubernetes.loadbalancer.mode=SERVICE",
|
||||
"spring.cloud.kubernetes.loadbalancer.enabled=true" })
|
||||
@TestPropertySource(properties = { "spring.main.cloud-platform=KUBERNETES",
|
||||
"spring.cloud.kubernetes.loadbalancer.mode=SERVICE", "spring.cloud.kubernetes.loadbalancer.enabled=true" })
|
||||
@EnableKubernetesMockClient(crud = true, https = false)
|
||||
class LoadBalancerWithServiceTests {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user