From 05dbdcf5d0cbc8e30d1048b2ca3a01cc9b772eb9 Mon Sep 17 00:00:00 2001 From: erabii Date: Fri, 16 Feb 2024 17:42:21 +0200 Subject: [PATCH] minor unification of two conditionals (#1577) --- ...KubernetesClientActuatorConfiguration.java | 10 ++--- ...nalOnKubernetesHealthIndicatorEnabled.java | 41 +++++++++++++++++++ ...tesBlockingDiscoveryHealthInitializer.java | 5 +-- .../fabric8/Fabric8ActuatorConfiguration.java | 10 ++--- ...lientNotPresentWhenIstioDisabledTest.java} | 2 +- ...NotPresentWhenKubernetesDisabledTest.java} | 2 +- ...figurationClientPresentByDefaultTest.java} | 2 +- ...ionClientPresentWhenIstioEnabledTest.java} | 2 +- 8 files changed, 53 insertions(+), 21 deletions(-) create mode 100644 spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/autoconfig/ConditionalOnKubernetesHealthIndicatorEnabled.java rename spring-cloud-kubernetes-fabric8-istio/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/istio/{IstioAutoConfigurationClientNotPresentWhenIstioDisabled.java => IstioAutoConfigurationClientNotPresentWhenIstioDisabledTest.java} (95%) rename spring-cloud-kubernetes-fabric8-istio/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/istio/{IstioAutoConfigurationClientNotPresentWhenKubernetesDisabled.java => IstioAutoConfigurationClientNotPresentWhenKubernetesDisabledTest.java} (99%) rename spring-cloud-kubernetes-fabric8-istio/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/istio/{IstioAutoConfigurationClientPresentByDefault.java => IstioAutoConfigurationClientPresentByDefaultTest.java} (96%) rename spring-cloud-kubernetes-fabric8-istio/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/istio/{IstioAutoConfigurationClientPresentWhenIstioEnabled.java => IstioAutoConfigurationClientPresentWhenIstioEnabledTest.java} (95%) diff --git a/spring-cloud-kubernetes-client-autoconfig/src/main/java/org/springframework/cloud/kubernetes/client/KubernetesClientActuatorConfiguration.java b/spring-cloud-kubernetes-client-autoconfig/src/main/java/org/springframework/cloud/kubernetes/client/KubernetesClientActuatorConfiguration.java index eae0776446..82f9f67fdc 100644 --- a/spring-cloud-kubernetes-client-autoconfig/src/main/java/org/springframework/cloud/kubernetes/client/KubernetesClientActuatorConfiguration.java +++ b/spring-cloud-kubernetes-client-autoconfig/src/main/java/org/springframework/cloud/kubernetes/client/KubernetesClientActuatorConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2020 the original author or authors. + * Copyright 2013-2024 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. @@ -20,11 +20,8 @@ import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator; 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.boot.autoconfigure.condition.ConditionalOnCloudPlatform; -import org.springframework.boot.cloud.CloudPlatform; import org.springframework.cloud.kubernetes.commons.PodUtils; +import org.springframework.cloud.kubernetes.commons.autoconfig.ConditionalOnKubernetesHealthIndicatorEnabled; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -32,8 +29,7 @@ * @author wind57 */ @Configuration(proxyBeanMethods = false) -@ConditionalOnClass(HealthIndicator.class) -@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES) +@ConditionalOnKubernetesHealthIndicatorEnabled public class KubernetesClientActuatorConfiguration { @Bean diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/autoconfig/ConditionalOnKubernetesHealthIndicatorEnabled.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/autoconfig/ConditionalOnKubernetesHealthIndicatorEnabled.java new file mode 100644 index 0000000000..2538937edd --- /dev/null +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/autoconfig/ConditionalOnKubernetesHealthIndicatorEnabled.java @@ -0,0 +1,41 @@ +/* + * Copyright 2013-2024 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.autoconfig; + +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.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform; +import org.springframework.boot.cloud.CloudPlatform; + +/** + * @author wind57 + **/ +@Target({ ElementType.TYPE, ElementType.METHOD }) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@ConditionalOnClass(name = "org.springframework.boot.actuate.health.HealthIndicator") +@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES) +public @interface ConditionalOnKubernetesHealthIndicatorEnabled { + +} diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/ConditionalOnSpringCloudKubernetesBlockingDiscoveryHealthInitializer.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/ConditionalOnSpringCloudKubernetesBlockingDiscoveryHealthInitializer.java index 3e0091445a..0f897927f7 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/ConditionalOnSpringCloudKubernetesBlockingDiscoveryHealthInitializer.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/discovery/ConditionalOnSpringCloudKubernetesBlockingDiscoveryHealthInitializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2023 the original author or authors. + * Copyright 2013-2024 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. @@ -23,7 +23,6 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import org.springframework.boot.actuate.health.HealthIndicator; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.cloud.client.ConditionalOnDiscoveryHealthIndicatorEnabled; @@ -36,7 +35,7 @@ @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited -@ConditionalOnClass({ HealthIndicator.class }) +@ConditionalOnClass(name = "org.springframework.boot.actuate.health.HealthIndicator") @ConditionalOnDiscoveryHealthIndicatorEnabled public @interface ConditionalOnSpringCloudKubernetesBlockingDiscoveryHealthInitializer { diff --git a/spring-cloud-kubernetes-fabric8-autoconfig/src/main/java/org/springframework/cloud/kubernetes/fabric8/Fabric8ActuatorConfiguration.java b/spring-cloud-kubernetes-fabric8-autoconfig/src/main/java/org/springframework/cloud/kubernetes/fabric8/Fabric8ActuatorConfiguration.java index 6241835682..890c9b6101 100644 --- a/spring-cloud-kubernetes-fabric8-autoconfig/src/main/java/org/springframework/cloud/kubernetes/fabric8/Fabric8ActuatorConfiguration.java +++ b/spring-cloud-kubernetes-fabric8-autoconfig/src/main/java/org/springframework/cloud/kubernetes/fabric8/Fabric8ActuatorConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2021 the original author or authors. + * Copyright 2013-2024 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. @@ -20,11 +20,8 @@ import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator; 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.boot.autoconfigure.condition.ConditionalOnCloudPlatform; -import org.springframework.boot.cloud.CloudPlatform; import org.springframework.cloud.kubernetes.commons.PodUtils; +import org.springframework.cloud.kubernetes.commons.autoconfig.ConditionalOnKubernetesHealthIndicatorEnabled; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -32,8 +29,7 @@ * @author wind57 */ @Configuration(proxyBeanMethods = false) -@ConditionalOnClass(HealthIndicator.class) -@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES) +@ConditionalOnKubernetesHealthIndicatorEnabled public class Fabric8ActuatorConfiguration { @Bean diff --git a/spring-cloud-kubernetes-fabric8-istio/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/istio/IstioAutoConfigurationClientNotPresentWhenIstioDisabled.java b/spring-cloud-kubernetes-fabric8-istio/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/istio/IstioAutoConfigurationClientNotPresentWhenIstioDisabledTest.java similarity index 95% rename from spring-cloud-kubernetes-fabric8-istio/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/istio/IstioAutoConfigurationClientNotPresentWhenIstioDisabled.java rename to spring-cloud-kubernetes-fabric8-istio/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/istio/IstioAutoConfigurationClientNotPresentWhenIstioDisabledTest.java index d56c652068..29ebadb348 100644 --- a/spring-cloud-kubernetes-fabric8-istio/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/istio/IstioAutoConfigurationClientNotPresentWhenIstioDisabled.java +++ b/spring-cloud-kubernetes-fabric8-istio/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/istio/IstioAutoConfigurationClientNotPresentWhenIstioDisabledTest.java @@ -30,7 +30,7 @@ */ @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class, properties = { "spring.cloud.istio.enabled=false" }) -class IstioAutoConfigurationClientNotPresentWhenIstioDisabled { +class IstioAutoConfigurationClientNotPresentWhenIstioDisabledTest { @Autowired private ConfigurableApplicationContext context; diff --git a/spring-cloud-kubernetes-fabric8-istio/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/istio/IstioAutoConfigurationClientNotPresentWhenKubernetesDisabled.java b/spring-cloud-kubernetes-fabric8-istio/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/istio/IstioAutoConfigurationClientNotPresentWhenKubernetesDisabledTest.java similarity index 99% rename from spring-cloud-kubernetes-fabric8-istio/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/istio/IstioAutoConfigurationClientNotPresentWhenKubernetesDisabled.java rename to spring-cloud-kubernetes-fabric8-istio/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/istio/IstioAutoConfigurationClientNotPresentWhenKubernetesDisabledTest.java index dfa232777c..b11eb1d45e 100644 --- a/spring-cloud-kubernetes-fabric8-istio/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/istio/IstioAutoConfigurationClientNotPresentWhenKubernetesDisabled.java +++ b/spring-cloud-kubernetes-fabric8-istio/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/istio/IstioAutoConfigurationClientNotPresentWhenKubernetesDisabledTest.java @@ -29,7 +29,7 @@ * @author wind57 */ @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class) -class IstioAutoConfigurationClientNotPresentWhenKubernetesDisabled { +class IstioAutoConfigurationClientNotPresentWhenKubernetesDisabledTest { @Autowired private ConfigurableApplicationContext context; diff --git a/spring-cloud-kubernetes-fabric8-istio/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/istio/IstioAutoConfigurationClientPresentByDefault.java b/spring-cloud-kubernetes-fabric8-istio/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/istio/IstioAutoConfigurationClientPresentByDefaultTest.java similarity index 96% rename from spring-cloud-kubernetes-fabric8-istio/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/istio/IstioAutoConfigurationClientPresentByDefault.java rename to spring-cloud-kubernetes-fabric8-istio/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/istio/IstioAutoConfigurationClientPresentByDefaultTest.java index 402ec57aeb..df133c2e83 100644 --- a/spring-cloud-kubernetes-fabric8-istio/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/istio/IstioAutoConfigurationClientPresentByDefault.java +++ b/spring-cloud-kubernetes-fabric8-istio/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/istio/IstioAutoConfigurationClientPresentByDefaultTest.java @@ -30,7 +30,7 @@ */ @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class, properties = "spring.main.cloud-platform=KUBERNETES") -class IstioAutoConfigurationClientPresentByDefault { +class IstioAutoConfigurationClientPresentByDefaultTest { @Autowired private ConfigurableApplicationContext context; diff --git a/spring-cloud-kubernetes-fabric8-istio/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/istio/IstioAutoConfigurationClientPresentWhenIstioEnabled.java b/spring-cloud-kubernetes-fabric8-istio/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/istio/IstioAutoConfigurationClientPresentWhenIstioEnabledTest.java similarity index 95% rename from spring-cloud-kubernetes-fabric8-istio/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/istio/IstioAutoConfigurationClientPresentWhenIstioEnabled.java rename to spring-cloud-kubernetes-fabric8-istio/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/istio/IstioAutoConfigurationClientPresentWhenIstioEnabledTest.java index 7c298aa802..ae34274c2e 100644 --- a/spring-cloud-kubernetes-fabric8-istio/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/istio/IstioAutoConfigurationClientPresentWhenIstioEnabled.java +++ b/spring-cloud-kubernetes-fabric8-istio/src/test/java/org/springframework/cloud/kubernetes/fabric8/client/istio/IstioAutoConfigurationClientPresentWhenIstioEnabledTest.java @@ -30,7 +30,7 @@ */ @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class, properties = { "spring.cloud.istio.enabled=true", "spring.main.cloud-platform=KUBERNETES" }) -class IstioAutoConfigurationClientPresentWhenIstioEnabled { +class IstioAutoConfigurationClientPresentWhenIstioEnabledTest { @Autowired private ConfigurableApplicationContext context;