From 4e36d38e0d7d9ff3cbaab81da93bf21824160439 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Feb 2025 14:12:03 -0500 Subject: [PATCH 1/3] Bump @springio/asciidoctor-extensions in /docs (#1861) Bumps [@springio/asciidoctor-extensions](https://github.com/spring-io/asciidoctor-extensions) from 1.0.0-alpha.14 to 1.0.0-alpha.16. - [Changelog](https://github.com/spring-io/asciidoctor-extensions/blob/main/CHANGELOG.adoc) - [Commits](https://github.com/spring-io/asciidoctor-extensions/compare/v1.0.0-alpha.14...v1.0.0-alpha.16) --- updated-dependencies: - dependency-name: "@springio/asciidoctor-extensions" dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- docs/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/package.json b/docs/package.json index ca5b2ce8..755f9ee7 100644 --- a/docs/package.json +++ b/docs/package.json @@ -5,6 +5,6 @@ "@antora/collector-extension": "1.0.1", "@asciidoctor/tabs": "1.0.0-beta.6", "@springio/antora-extensions": "1.14.2", - "@springio/asciidoctor-extensions": "1.0.0-alpha.14" + "@springio/asciidoctor-extensions": "1.0.0-alpha.16" } } From b5c8a61f7d93f592eba01debb38be0a39cfa311e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Feb 2025 14:16:46 -0500 Subject: [PATCH 2/3] Bump org.wiremock:wiremock-standalone from 3.9.1 to 3.9.2 (#1859) Bumps [org.wiremock:wiremock-standalone](https://github.com/wiremock/wiremock) from 3.9.1 to 3.9.2. - [Release notes](https://github.com/wiremock/wiremock/releases) - [Commits](https://github.com/wiremock/wiremock/compare/3.9.1...3.9.2) --- updated-dependencies: - dependency-name: org.wiremock:wiremock-standalone dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- spring-cloud-kubernetes-dependencies/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-cloud-kubernetes-dependencies/pom.xml b/spring-cloud-kubernetes-dependencies/pom.xml index cbde7c83..5f59dbad 100644 --- a/spring-cloud-kubernetes-dependencies/pom.xml +++ b/spring-cloud-kubernetes-dependencies/pom.xml @@ -34,7 +34,7 @@ 6.9.2 19.0.2 - 3.9.1 + 3.9.2 From 9518285f33a1e76c8b62d41c9e234a5bddbbfc37 Mon Sep 17 00:00:00 2001 From: erabii Date: Thu, 6 Feb 2025 02:30:13 +0200 Subject: [PATCH 3/3] Fix 1831 (#1863) * fix issue Signed-off-by: wind57 * refactor Signed-off-by: wind57 * fix issue Signed-off-by: wind57 * review comments Signed-off-by: wind57 --------- Signed-off-by: wind57 --- .../commons/config/ConfigUtils.java | 9 ++- .../KubernetesConfigDataLocationResolver.java | 14 ++-- .../DummyConfigDataLocationResolver.java | 43 ++++++++++ .../discovery/Fabric8ConfigServerTest.java | 78 +++++++++++++++++++ .../test/resources/META-INF/spring.factories | 2 + 5 files changed, 135 insertions(+), 11 deletions(-) create mode 100644 spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/DummyConfigDataLocationResolver.java create mode 100644 spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8ConfigServerTest.java create mode 100644 spring-cloud-kubernetes-fabric8-discovery/src/test/resources/META-INF/spring.factories diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ConfigUtils.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ConfigUtils.java index 886e9e7b..95cf2636 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ConfigUtils.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ConfigUtils.java @@ -339,10 +339,11 @@ public final class ConfigUtils { String name, ApplicationListener listener) { bootstrapContext.registerIfAbsent(cls, BootstrapRegistry.InstanceSupplier.of(instance)); bootstrapContext.addCloseListener(event -> { - if (event.getApplicationContext().getBeanFactory().getSingleton(name) == null) { - event.getApplicationContext() - .getBeanFactory() - .registerSingleton(name, event.getBootstrapContext().get(cls)); + + T singleton = event.getBootstrapContext().get(cls); + + if (event.getApplicationContext().getBeanFactory().getSingleton(name) == null && singleton != null) { + event.getApplicationContext().getBeanFactory().registerSingleton(name, singleton); event.getApplicationContext().addApplicationListener(listener); } }); diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/KubernetesConfigDataLocationResolver.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/KubernetesConfigDataLocationResolver.java index 95907843..51acafc2 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/KubernetesConfigDataLocationResolver.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/KubernetesConfigDataLocationResolver.java @@ -52,6 +52,8 @@ import static org.springframework.util.ClassUtils.isPresent; public abstract class KubernetesConfigDataLocationResolver implements ConfigDataLocationResolver, Ordered { + private static final Class PROPERTIES_CLASS = KubernetesClientProperties.class; + private static final boolean RETRY_IS_PRESENT = isPresent("org.springframework.retry.annotation.Retryable", null); private final Log log; @@ -139,8 +141,7 @@ public abstract class KubernetesConfigDataLocationResolver SecretsConfigProperties secretsProperties) { ConfigurableBootstrapContext bootstrapContext = resolverContext.getBootstrapContext(); - registerSingle(bootstrapContext, KubernetesClientProperties.class, clientProperties, - "configDataKubernetesClientProperties"); + registerSingle(bootstrapContext, PROPERTIES_CLASS, clientProperties, "configDataKubernetesClientProperties"); if (configMapProperties != null) { registerSingle(bootstrapContext, ConfigMapConfigProperties.class, configMapProperties, @@ -174,15 +175,14 @@ public abstract class KubernetesConfigDataLocationResolver private static KubernetesClientProperties clientProperties(ConfigDataLocationResolverContext context, String namespace) { KubernetesClientProperties kubernetesClientProperties; + ConfigurableBootstrapContext bootstrapContext = context.getBootstrapContext(); - if (context.getBootstrapContext().isRegistered(KubernetesClientProperties.class)) { - kubernetesClientProperties = context.getBootstrapContext() - .get(KubernetesClientProperties.class) - .withNamespace(namespace); + if (bootstrapContext.isRegistered(PROPERTIES_CLASS) && bootstrapContext.get(PROPERTIES_CLASS) != null) { + kubernetesClientProperties = bootstrapContext.get(PROPERTIES_CLASS).withNamespace(namespace); } else { kubernetesClientProperties = context.getBinder() - .bindOrCreate(KubernetesClientProperties.PREFIX, Bindable.of(KubernetesClientProperties.class)) + .bindOrCreate(KubernetesClientProperties.PREFIX, Bindable.of(PROPERTIES_CLASS)) .withNamespace(namespace); } diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/DummyConfigDataLocationResolver.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/DummyConfigDataLocationResolver.java new file mode 100644 index 00000000..42e85522 --- /dev/null +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/DummyConfigDataLocationResolver.java @@ -0,0 +1,43 @@ +/* + * Copyright 2013-2025 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; + +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.config.ConfigDataLocation; +import org.springframework.boot.context.config.ConfigDataLocationResolverContext; +import org.springframework.boot.context.config.Profiles; +import org.springframework.boot.logging.DeferredLogFactory; +import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider; +import org.springframework.cloud.kubernetes.commons.config.KubernetesConfigDataLocationResolver; + +/** + * @author wind57 + */ +@ConditionalOnProperty(value = "dummy.config.loader.enabled", havingValue = "true", matchIfMissing = false) +class DummyConfigDataLocationResolver extends KubernetesConfigDataLocationResolver { + + DummyConfigDataLocationResolver(DeferredLogFactory factory) { + super(factory); + } + + @Override + protected void registerBeans(ConfigDataLocationResolverContext resolverContext, ConfigDataLocation location, + Profiles profiles, PropertyHolder propertyHolder, KubernetesNamespaceProvider namespaceProvider) { + + } + +} diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8ConfigServerTest.java b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8ConfigServerTest.java new file mode 100644 index 00000000..685cb443 --- /dev/null +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8ConfigServerTest.java @@ -0,0 +1,78 @@ +/* + * Copyright 2013-2025 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.fabric8.discovery; + +import com.github.tomakehurst.wiremock.WireMockServer; +import com.github.tomakehurst.wiremock.client.WireMock; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.ApplicationContext; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; +import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; + +/** + * Test that proves that this + * issue + * is fixed. + * + * @author wind57 + */ +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + properties = { "spring.main.cloud-platform=KUBERNETES", + "spring.config.import=kubernetes:, optional:configserver:", "dummy.config.loader.enabled=true" }) +class Fabric8ConfigServerTest { + + private static WireMockServer wireMockServer; + + @Autowired + private ApplicationContext applicationContext; + + @BeforeAll + static void beforeAll() { + wireMockServer = new WireMockServer(options().port(8888)); + wireMockServer.start(); + WireMock.configureFor("localhost", wireMockServer.port()); + } + + @AfterAll + static void after() { + WireMock.shutdownServer(); + wireMockServer.stop(); + } + + @Test + void test() { + stubFor(get(urlEqualTo("/application/default")).willReturn(aResponse().withStatus(200).withBody("{}"))); + Assertions.assertThat(applicationContext).isNotNull(); + } + + @SpringBootApplication + protected static class TestConfig { + + } + +} diff --git a/spring-cloud-kubernetes-fabric8-discovery/src/test/resources/META-INF/spring.factories b/spring-cloud-kubernetes-fabric8-discovery/src/test/resources/META-INF/spring.factories new file mode 100644 index 00000000..d92d10c6 --- /dev/null +++ b/spring-cloud-kubernetes-fabric8-discovery/src/test/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.boot.context.config.ConfigDataLocationResolver=\ +org.springframework.cloud.kubernetes.DummyConfigDataLocationResolver