-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix 1831 #1863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Fix 1831 #1863
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,6 +52,8 @@ | |
| public abstract class KubernetesConfigDataLocationResolver | ||
| implements ConfigDataLocationResolver<KubernetesConfigDataResource>, Ordered { | ||
|
|
||
| private static final Class<KubernetesClientProperties> 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 @@ private void registerProperties(ConfigDataLocationResolverContext resolverContex | |
| 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 @@ private static PropertyHolder of(ConfigDataLocationResolverContext context) { | |
| 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) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we used to do : but now, we will do : |
||
| 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); | ||
| } | ||
|
|
||
|
|
||
43 changes: 43 additions & 0 deletions
43
...y/src/test/java/org/springframework/cloud/kubernetes/DummyConfigDataLocationResolver.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) { | ||
|
|
||
| } | ||
|
|
||
| } |
78 changes: 78 additions & 0 deletions
78
.../java/org/springframework/cloud/kubernetes/fabric8/discovery/Fabric8ConfigServerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
| * <a href="https://github.com/spring-cloud/spring-cloud-kubernetes/issues/1831">issue</a> | ||
| * 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 { | ||
|
|
||
| } | ||
|
|
||
| } |
2 changes: 2 additions & 0 deletions
2
spring-cloud-kubernetes-fabric8-discovery/src/test/resources/META-INF/spring.factories
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| org.springframework.boot.context.config.ConfigDataLocationResolver=\ | ||
| org.springframework.cloud.kubernetes.DummyConfigDataLocationResolver |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have missed this one if it was not for the test tbh.