Skip to content

Commit 9415486

Browse files
committed
merge main
Signed-off-by: wind57 <[email protected]>
2 parents dd948bc + f9a678c commit 9415486

File tree

57 files changed

+1683
-3385
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1683
-3385
lines changed

.github/dependabot.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ updates:
2020
- dependency-name: "*"
2121
update-types:
2222
- version-update:semver-major
23+
- version-update:semver-minor
2324
- package-ecosystem: maven
2425
directory: /
2526
schedule:
@@ -31,6 +32,17 @@ updates:
3132
update-types:
3233
- version-update:semver-major
3334
- version-update:semver-minor
35+
- package-ecosystem: maven
36+
directory: /
37+
schedule:
38+
interval: daily
39+
target-branch: 3.2.x
40+
ignore:
41+
# only upgrade by minor or patch
42+
- dependency-name: "*"
43+
update-types:
44+
- version-update:semver-major
45+
- version-update:semver-minor
3446
- package-ecosystem: npm
3547
target-branch: docs-build
3648
directory: /
@@ -46,3 +58,8 @@ updates:
4658
directory: /docs
4759
schedule:
4860
interval: weekly
61+
- package-ecosystem: npm
62+
target-branch: 3.2.x
63+
directory: /docs
64+
schedule:
65+
interval: weekly

.github/workflows/composites/maven-build-with-dry-run-for-tests/action.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ runs:
88
shell: bash
99
run: |
1010
./mvnw install -B \
11-
-Dskip.build.image=true \
11+
-Dspring-boot.build-image.skip=true \
1212
-DskipTests -DskipITs \
1313
-T 1C -U -q
1414

.github/workflows/composites/pre-test-actions/action.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ runs:
2424
- name: build project
2525
shell: bash
2626
run: |
27-
./mvnw clean install -P 'run-on-github-actions' -Dskip.build.image=true -DskipITs -DskipTests -T1C -U -B -q
27+
./mvnw clean install -Dspring-boot.build-image.skip=true -DskipITs -DskipTests -T1C -U -B -q
2828
2929
- name: build controllers project
3030
uses: ./.github/workflows/composites/build-controllers-project

.github/workflows/composites/run-and-save-test-times-when-cache-missing/action.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ runs:
4747
-Dmaven.wagon.http.pool=false \
4848
-Dmaven.wagon.http.retryHandler.class=standard \
4949
-Dmaven.wagon.http.retryHandler.count=3 \
50-
-Dskip.build.image=true
50+
-Dspring-boot.build-image.skip=true
5151
5252
touch /tmp/test_times_${{ env.CURRENT_INDEX }}.txt
5353

.github/workflows/composites/run-and-save-test-times-when-cache-present/action.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ runs:
156156
-Dmaven.wagon.http.pool=false \
157157
-Dmaven.wagon.http.retryHandler.class=standard \
158158
-Dmaven.wagon.http.retryHandler.count=3 \
159-
-Dskip.build.image=true
159+
-Dspring-boot.build-image.skip=true
160160

161161
touch /tmp/test_times_${{ env.CURRENT_INDEX }}.txt
162162

docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
"@antora/collector-extension": "1.0.1",
66
"@asciidoctor/tabs": "1.0.0-beta.6",
77
"@springio/antora-extensions": "1.14.2",
8-
"@springio/asciidoctor-extensions": "1.0.0-alpha.14"
8+
"@springio/asciidoctor-extensions": "1.0.0-alpha.16"
99
}
1010
}

spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/config/ConfigUtils.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,11 @@ public static <T> void registerSingle(ConfigurableBootstrapContext bootstrapCont
339339
String name, ApplicationListener<?> listener) {
340340
bootstrapContext.registerIfAbsent(cls, BootstrapRegistry.InstanceSupplier.of(instance));
341341
bootstrapContext.addCloseListener(event -> {
342-
if (event.getApplicationContext().getBeanFactory().getSingleton(name) == null) {
343-
event.getApplicationContext()
344-
.getBeanFactory()
345-
.registerSingleton(name, event.getBootstrapContext().get(cls));
342+
343+
T singleton = event.getBootstrapContext().get(cls);
344+
345+
if (event.getApplicationContext().getBeanFactory().getSingleton(name) == null && singleton != null) {
346+
event.getApplicationContext().getBeanFactory().registerSingleton(name, singleton);
346347
event.getApplicationContext().addApplicationListener(listener);
347348
}
348349
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
/*
2+
* Copyright 2013-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.kubernetes.commons.config;
18+
19+
import java.util.Collections;
20+
import java.util.HashMap;
21+
import java.util.List;
22+
import java.util.Map;
23+
24+
import org.apache.commons.logging.Log;
25+
26+
import org.springframework.boot.ConfigurableBootstrapContext;
27+
import org.springframework.boot.context.config.ConfigDataLocation;
28+
import org.springframework.boot.context.config.ConfigDataLocationNotFoundException;
29+
import org.springframework.boot.context.config.ConfigDataLocationResolver;
30+
import org.springframework.boot.context.config.ConfigDataLocationResolverContext;
31+
import org.springframework.boot.context.config.ConfigDataResourceNotFoundException;
32+
import org.springframework.boot.context.config.Profiles;
33+
import org.springframework.boot.context.properties.bind.Bindable;
34+
import org.springframework.boot.context.properties.bind.Binder;
35+
import org.springframework.boot.logging.DeferredLogFactory;
36+
import org.springframework.cloud.kubernetes.commons.KubernetesClientProperties;
37+
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
38+
import org.springframework.cloud.kubernetes.commons.config.configdata.KubernetesConfigDataResource;
39+
import org.springframework.core.Ordered;
40+
import org.springframework.core.env.ConfigurableEnvironment;
41+
import org.springframework.core.env.Environment;
42+
import org.springframework.core.env.MapPropertySource;
43+
import org.springframework.core.env.PropertySource;
44+
import org.springframework.core.env.StandardEnvironment;
45+
46+
import static org.springframework.boot.cloud.CloudPlatform.KUBERNETES;
47+
import static org.springframework.cloud.kubernetes.commons.config.ConfigUtils.registerSingle;
48+
import static org.springframework.util.ClassUtils.isPresent;
49+
50+
/**
51+
* @author Ryan Baxter
52+
*/
53+
public abstract class KubernetesConfigDataLocationResolver
54+
implements ConfigDataLocationResolver<KubernetesConfigDataResource>, Ordered {
55+
56+
private static final Class<KubernetesClientProperties> PROPERTIES_CLASS = KubernetesClientProperties.class;
57+
58+
private static final boolean RETRY_IS_PRESENT = isPresent("org.springframework.retry.annotation.Retryable", null);
59+
60+
private final Log log;
61+
62+
public KubernetesConfigDataLocationResolver(DeferredLogFactory factory) {
63+
this.log = factory.getLog(KubernetesConfigDataLocationResolver.class);
64+
}
65+
66+
protected final String getPrefix() {
67+
return "kubernetes:";
68+
}
69+
70+
@Override
71+
public final int getOrder() {
72+
return -1;
73+
}
74+
75+
@Override
76+
public final boolean isResolvable(ConfigDataLocationResolverContext context, ConfigDataLocation location) {
77+
return location.hasPrefix(getPrefix())
78+
&& (KUBERNETES.isEnforced(context.getBinder()) || KUBERNETES.isDetected(new StandardEnvironment()));
79+
}
80+
81+
@Override
82+
public final List<KubernetesConfigDataResource> resolve(ConfigDataLocationResolverContext context,
83+
ConfigDataLocation location)
84+
throws ConfigDataLocationNotFoundException, ConfigDataResourceNotFoundException {
85+
return Collections.emptyList();
86+
}
87+
88+
@Override
89+
public final List<KubernetesConfigDataResource> resolveProfileSpecific(
90+
ConfigDataLocationResolverContext resolverContext, ConfigDataLocation location, Profiles profiles)
91+
throws ConfigDataLocationNotFoundException {
92+
PropertyHolder propertyHolder = PropertyHolder.of(resolverContext);
93+
KubernetesClientProperties clientProperties = propertyHolder.kubernetesClientProperties();
94+
ConfigMapConfigProperties configMapProperties = propertyHolder.configMapConfigProperties();
95+
SecretsConfigProperties secretsProperties = propertyHolder.secretsProperties();
96+
97+
registerProperties(resolverContext, clientProperties, configMapProperties, secretsProperties);
98+
99+
HashMap<String, Object> kubernetesConfigData = new HashMap<>();
100+
kubernetesConfigData.put("spring.cloud.kubernetes.client.namespace", clientProperties.namespace());
101+
if (propertyHolder.applicationName() != null) {
102+
// If its null it means sprig.application.name was not set so don't add it to
103+
// the property source
104+
kubernetesConfigData.put("spring.application.name", propertyHolder.applicationName());
105+
}
106+
PropertySource<Map<String, Object>> propertySource = new MapPropertySource("kubernetesConfigData",
107+
kubernetesConfigData);
108+
ConfigurableEnvironment environment = new StandardEnvironment();
109+
environment.getPropertySources().addLast(propertySource);
110+
environment.setActiveProfiles(profiles.getAccepted().toArray(new String[0]));
111+
KubernetesNamespaceProvider namespaceProvider = kubernetesNamespaceProvider(environment);
112+
113+
registerBeans(resolverContext, location, profiles, propertyHolder, namespaceProvider);
114+
115+
KubernetesConfigDataResource resource = new KubernetesConfigDataResource(clientProperties, configMapProperties,
116+
secretsProperties, location.isOptional(), profiles, environment);
117+
118+
return List.of(resource);
119+
}
120+
121+
protected abstract void registerBeans(ConfigDataLocationResolverContext resolverContext,
122+
ConfigDataLocation location, Profiles profiles, PropertyHolder propertyHolder,
123+
KubernetesNamespaceProvider namespaceProvider);
124+
125+
protected KubernetesNamespaceProvider kubernetesNamespaceProvider(Environment environment) {
126+
return new KubernetesNamespaceProvider(environment);
127+
}
128+
129+
private void registerProperties(ConfigDataLocationResolverContext resolverContext,
130+
KubernetesClientProperties clientProperties, ConfigMapConfigProperties configMapProperties,
131+
SecretsConfigProperties secretsProperties) {
132+
133+
ConfigurableBootstrapContext bootstrapContext = resolverContext.getBootstrapContext();
134+
registerSingle(bootstrapContext, PROPERTIES_CLASS, clientProperties, "configDataKubernetesClientProperties");
135+
136+
if (configMapProperties != null) {
137+
registerSingle(bootstrapContext, ConfigMapConfigProperties.class, configMapProperties,
138+
"configDataConfigMapConfigProperties");
139+
}
140+
141+
if (secretsProperties != null) {
142+
registerSingle(bootstrapContext, SecretsConfigProperties.class, secretsProperties,
143+
"configDataSecretsConfigProperties");
144+
}
145+
}
146+
147+
protected record PropertyHolder(KubernetesClientProperties kubernetesClientProperties,
148+
ConfigMapConfigProperties configMapConfigProperties, SecretsConfigProperties secretsProperties,
149+
String applicationName) {
150+
151+
private static PropertyHolder of(ConfigDataLocationResolverContext context) {
152+
Binder binder = context.getBinder();
153+
154+
String applicationName = binder.bind("spring.application.name", String.class).orElse(null);
155+
String namespace = binder.bind("spring.cloud.kubernetes.client.namespace", String.class)
156+
.orElse(binder.bind("kubernetes.namespace", String.class).orElse(""));
157+
158+
KubernetesClientProperties kubernetesClientProperties = clientProperties(context, namespace);
159+
ConfigMapAndSecrets both = ConfigMapAndSecrets.of(binder);
160+
161+
return new PropertyHolder(kubernetesClientProperties, both.configMapProperties(),
162+
both.secretsConfigProperties(), applicationName);
163+
}
164+
165+
private static KubernetesClientProperties clientProperties(ConfigDataLocationResolverContext context,
166+
String namespace) {
167+
KubernetesClientProperties kubernetesClientProperties;
168+
ConfigurableBootstrapContext bootstrapContext = context.getBootstrapContext();
169+
170+
if (bootstrapContext.isRegistered(PROPERTIES_CLASS) && bootstrapContext.get(PROPERTIES_CLASS) != null) {
171+
kubernetesClientProperties = bootstrapContext.get(PROPERTIES_CLASS).withNamespace(namespace);
172+
}
173+
else {
174+
kubernetesClientProperties = context.getBinder()
175+
.bindOrCreate(KubernetesClientProperties.PREFIX, Bindable.of(PROPERTIES_CLASS))
176+
.withNamespace(namespace);
177+
}
178+
179+
return kubernetesClientProperties;
180+
181+
}
182+
183+
}
184+
185+
/**
186+
* holds ConfigMapConfigProperties and SecretsConfigProperties, both can be null if
187+
* using such sources is disabled.
188+
*/
189+
private record ConfigMapAndSecrets(ConfigMapConfigProperties configMapProperties,
190+
SecretsConfigProperties secretsConfigProperties) {
191+
192+
private static ConfigMapAndSecrets of(Binder binder) {
193+
194+
boolean configEnabled = binder.bind("spring.cloud.kubernetes.config.enabled", boolean.class).orElse(true);
195+
boolean secretsEnabled = binder.bind("spring.cloud.kubernetes.secrets.enabled", boolean.class).orElse(true);
196+
197+
ConfigMapConfigProperties configMapConfigProperties = null;
198+
if (configEnabled) {
199+
configMapConfigProperties = binder.bindOrCreate(ConfigMapConfigProperties.PREFIX,
200+
ConfigMapConfigProperties.class);
201+
}
202+
203+
SecretsConfigProperties secretsProperties = null;
204+
if (secretsEnabled) {
205+
secretsProperties = binder.bindOrCreate(SecretsConfigProperties.PREFIX, SecretsConfigProperties.class);
206+
}
207+
208+
return new ConfigMapAndSecrets(configMapConfigProperties, secretsProperties);
209+
210+
}
211+
}
212+
213+
}

spring-cloud-kubernetes-controllers/pom.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@
3333
<executions>
3434
<execution>
3535
<id>build-image</id>
36-
<configuration>
37-
<skip>${skip.build.image}</skip>
38-
</configuration>
3936
<phase>package</phase>
4037
<goals>
4138
<goal>build-image-no-fork</goal>

spring-cloud-kubernetes-dependencies/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
<name>Spring Cloud Kubernetes :: Dependencies</name>
3333
<description>Spring Cloud Kubernetes Dependencies</description>
3434
<properties>
35-
<kubernetes-fabric8-client.version>6.13.4</kubernetes-fabric8-client.version>
35+
<kubernetes-fabric8-client.version>6.13.5</kubernetes-fabric8-client.version>
3636
<kubernetes-native-client.version>19.0.2</kubernetes-native-client.version>
37-
<wiremock.version>3.4.2</wiremock.version>
37+
<wiremock.version>3.9.2</wiremock.version>
3838
</properties>
3939
<dependencyManagement>
4040
<dependencies>

0 commit comments

Comments
 (0)