Skip to content

Commit

Permalink
Merge branch 'main' into fix-1176-drop-deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
wind57 committed Dec 6, 2024
2 parents 2ad54b7 + f342faf commit 87298a0
Show file tree
Hide file tree
Showing 100 changed files with 1,188 additions and 1,613 deletions.
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"dependencies": {
"antora": "3.2.0-alpha.6",
"@antora/atlas-extension": "1.0.0-alpha.2",
"@antora/collector-extension": "1.0.0-beta.5",
"@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"
Expand Down
6 changes: 3 additions & 3 deletions docs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-kubernetes</artifactId>
<version>3.2.0-SNAPSHOT</version>
<version>3.2.1-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<packaging>jar</packaging>
Expand All @@ -21,7 +21,7 @@
<!-- Don't upload docs jar to central / repo.spring.io -->
<maven-deploy-plugin-default.phase>none</maven-deploy-plugin-default.phase>
</properties>
<dependencies>
<!-- <dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>spring-cloud-starter-kubernetes-fabric8</artifactId>
Expand All @@ -34,7 +34,7 @@
<groupId>${project.groupId}</groupId>
<artifactId>spring-cloud-starter-kubernetes-fabric8-config</artifactId>
</dependency>
</dependencies>
</dependencies> -->
<build>
<sourceDirectory>src/main/asciidoc</sourceDirectory>
</build>
Expand Down
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-build</artifactId>
<version>4.2.0-SNAPSHOT</version>
<version>4.2.1-SNAPSHOT</version>
<relativePath/>
</parent>

<artifactId>spring-cloud-kubernetes</artifactId>
<version>3.2.0-SNAPSHOT</version>
<version>3.2.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Spring Cloud Kubernetes</name>

Expand Down Expand Up @@ -70,10 +70,10 @@
<failsafe-reports-directory>failsafe-reports</failsafe-reports-directory>
<!-- Dependency Versions -->
<mockito-inline.version>4.8.1</mockito-inline.version>
<spring-cloud-commons.version>4.2.0-SNAPSHOT</spring-cloud-commons.version>
<spring-cloud-config.version>4.2.0-SNAPSHOT</spring-cloud-config.version>
<spring-cloud-bus.version>4.2.0-SNAPSHOT</spring-cloud-bus.version>
<spring-cloud-contract.version>4.2.0-SNAPSHOT</spring-cloud-contract.version>
<spring-cloud-commons.version>4.2.1-SNAPSHOT</spring-cloud-commons.version>
<spring-cloud-config.version>4.2.1-SNAPSHOT</spring-cloud-config.version>
<spring-cloud-bus.version>4.2.1-SNAPSHOT</spring-cloud-bus.version>
<spring-cloud-contract.version>4.2.1-SNAPSHOT</spring-cloud-contract.version>

<maven-checkstyle-plugin.failsOnError>true</maven-checkstyle-plugin.failsOnError>
<maven-checkstyle-plugin.failsOnViolation>true
Expand Down
2 changes: 1 addition & 1 deletion spring-cloud-kubernetes-client-autoconfig/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>spring-cloud-kubernetes</artifactId>
<groupId>org.springframework.cloud</groupId>
<version>3.2.0-SNAPSHOT</version>
<version>3.2.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion spring-cloud-kubernetes-client-config/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>spring-cloud-kubernetes</artifactId>
<groupId>org.springframework.cloud</groupId>
<version>3.2.0-SNAPSHOT</version>
<version>3.2.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@
import org.springframework.boot.test.system.OutputCaptureExtension;
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
import org.springframework.cloud.kubernetes.commons.config.ConfigMapConfigProperties;
import org.springframework.cloud.kubernetes.commons.config.Constants;
import org.springframework.cloud.kubernetes.commons.config.RetryProperties;
import org.springframework.core.env.CompositePropertySource;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.PropertySource;
import org.springframework.mock.env.MockEnvironment;

Expand Down Expand Up @@ -100,12 +98,11 @@ public void afterEach() {

/**
* <pre>
* we try to read all config maps in a namespace and fail,
* thus generate a well defined name for the source.
* we try to read all config maps in a namespace and fail.
* </pre>
*/
@Test
void namedSingleConfigMapFails() {
void namedSingleConfigMapFails(CapturedOutput output) {
String name = "my-config";
String namespace = "spring-k8s";
String path = "/api/v1/namespaces/" + namespace + "/configmaps";
Expand All @@ -120,13 +117,10 @@ void namedSingleConfigMapFails() {
configMapConfigProperties, new KubernetesNamespaceProvider(new MockEnvironment()));

CompositePropertySource propertySource = (CompositePropertySource) locator.locate(new MockEnvironment());
MapPropertySource mapPropertySource = (MapPropertySource) propertySource.getPropertySources()
.stream()
.findAny()
.orElseThrow();

assertThat(mapPropertySource.getName()).isEqualTo("configmap..spring-k8s");
assertThat(propertySource.getProperty(Constants.ERROR_PROPERTY)).isEqualTo("true");
assertThat(propertySource.getPropertySources()).isEmpty();
assertThat(output.getOut()).contains("Failure in reading named sources");
assertThat(output.getOut()).contains("Failed to load source: { config-map name : 'Optional[my-config]'");

}

Expand Down Expand Up @@ -168,11 +162,12 @@ void namedTwoConfigMapsOneFails(CapturedOutput output) {
CompositePropertySource propertySource = (CompositePropertySource) locator.locate(new MockEnvironment());
List<String> names = propertySource.getPropertySources().stream().map(PropertySource::getName).toList();

// two sources are present, one being empty
assertThat(names).containsExactly("configmap.two.default", "configmap..default");
assertThat(propertySource.getProperty(Constants.ERROR_PROPERTY)).isEqualTo("true");
// one property source is present
assertThat(names).containsExactly("configmap.two.default");
assertThat(output.getOut())
.doesNotContain("sourceName : two was requested, but not found in namespace : default");
assertThat(output.getOut()).contains("Failure in reading named sources");
assertThat(output.getOut()).contains("Failed to load source: { config-map name : 'Optional[one]'");

}

Expand Down Expand Up @@ -212,20 +207,19 @@ void namedTwoConfigMapsBothFail(CapturedOutput output) {
configMapConfigProperties, new KubernetesNamespaceProvider(new MockEnvironment()));

CompositePropertySource propertySource = (CompositePropertySource) locator.locate(new MockEnvironment());
List<String> names = propertySource.getPropertySources().stream().map(PropertySource::getName).toList();

assertThat(names).containsExactly("configmap..default");
assertThat(propertySource.getProperty(Constants.ERROR_PROPERTY)).isEqualTo("true");
assertThat(propertySource.getPropertySources()).isEmpty();
assertThat(output.getOut())
.doesNotContain("sourceName : one was requested, but not found in namespace : default");
assertThat(output.getOut())
.doesNotContain("sourceName : two was requested, but not found in namespace : default");
assertThat(output.getOut()).contains("Failure in reading named sources");
assertThat(output.getOut()).contains("Failed to load source: { config-map name : 'Optional[one]'");
}

/**
* <pre>
* we try to read all config maps in a namespace and fail,
* thus generate a well defined name for the source.
* we try to read all config maps in a namespace and fail.
* </pre>
*/
@Test
Expand Down Expand Up @@ -256,12 +250,11 @@ void labeledSingleConfigMapFails(CapturedOutput output) {
configMapConfigProperties, new KubernetesNamespaceProvider(new MockEnvironment()));

CompositePropertySource propertySource = (CompositePropertySource) locator.locate(new MockEnvironment());
List<String> sourceNames = propertySource.getPropertySources().stream().map(PropertySource::getName).toList();

assertThat(sourceNames).containsExactly("configmap..spring-k8s");
assertThat(propertySource.getProperty(Constants.ERROR_PROPERTY)).isEqualTo("true");
assertThat(output).contains("failure in reading labeled sources");
assertThat(output).contains("failure in reading named sources");
assertThat(propertySource.getPropertySources()).isEmpty();
assertThat(output.getOut()).contains("Failure in reading labeled sources");
assertThat(output.getOut()).contains("Failure in reading named sources");
assertThat(output.getOut()).contains("Failed to load source: { config map labels : '{a=b}'");
}

/**
Expand Down Expand Up @@ -311,12 +304,11 @@ void labeledTwoConfigMapsOneFails(CapturedOutput output) {
CompositePropertySource propertySource = (CompositePropertySource) locator.locate(new MockEnvironment());
List<String> names = propertySource.getPropertySources().stream().map(PropertySource::getName).toList();

// two sources are present, one being empty
assertThat(names).containsExactly("configmap.two.default", "configmap..default");
assertThat(propertySource.getProperty(Constants.ERROR_PROPERTY)).isEqualTo("true");

assertThat(output).contains("failure in reading labeled sources");
assertThat(output).contains("failure in reading named sources");
// one source is present
assertThat(names).containsExactly("configmap.two.default");
assertThat(output.getOut()).contains("Failure in reading labeled sources");
assertThat(output.getOut()).contains("Failure in reading named sources");
assertThat(output.getOut()).contains("Failed to load source: { config map labels : '{one=1}'");

}

Expand Down Expand Up @@ -364,15 +356,12 @@ void labeledTwoConfigMapsBothFail(CapturedOutput output) {
configMapConfigProperties, new KubernetesNamespaceProvider(new MockEnvironment()));

CompositePropertySource propertySource = (CompositePropertySource) locator.locate(new MockEnvironment());
List<String> names = propertySource.getPropertySources().stream().map(PropertySource::getName).toList();

// all 3 sources ('application' named source, and two labeled sources)
assertThat(names).containsExactly("configmap..default");
assertThat(propertySource.getProperty(Constants.ERROR_PROPERTY)).isEqualTo("true");

assertThat(output).contains("failure in reading labeled sources");
assertThat(output).contains("failure in reading named sources");

assertThat(propertySource.getPropertySources()).isEmpty();
assertThat(output).contains("Failure in reading labeled sources");
assertThat(output).contains("Failure in reading named sources");
assertThat(output.getOut()).contains("Failed to load source: { config map labels : '{one=1}'");
assertThat(output.getOut()).contains("Failed to load source: { config map labels : '{two=2}'");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.springframework.cloud.kubernetes.client.config;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand All @@ -34,12 +35,16 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import org.springframework.boot.test.system.CapturedOutput;
import org.springframework.boot.test.system.OutputCaptureExtension;
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
import org.springframework.cloud.kubernetes.commons.config.ConfigMapConfigProperties;
import org.springframework.cloud.kubernetes.commons.config.Constants;
import org.springframework.cloud.kubernetes.commons.config.NamespaceResolutionFailedException;
import org.springframework.cloud.kubernetes.commons.config.RetryProperties;
import org.springframework.core.env.CompositePropertySource;
import org.springframework.core.env.PropertySource;
import org.springframework.mock.env.MockEnvironment;

Expand All @@ -55,6 +60,7 @@
* @author Ryan Baxter
* @author Isik Erhan
*/
@ExtendWith(OutputCaptureExtension.class)
class KubernetesClientConfigMapPropertySourceLocatorTests {

private static final V1ConfigMapList PROPERTIES_CONFIGMAP_LIST = new V1ConfigMapList()
Expand Down Expand Up @@ -185,7 +191,7 @@ public void locateShouldThrowExceptionOnFailureWhenFailFastIsEnabled() {
}

@Test
public void locateShouldNotThrowExceptionOnFailureWhenFailFastIsDisabled() {
public void locateShouldNotThrowExceptionOnFailureWhenFailFastIsDisabled(CapturedOutput output) {
CoreV1Api api = new CoreV1Api();
stubFor(get("/api/v1/namespaces/default/configmaps")
.willReturn(aResponse().withStatus(500).withBody("Internal Server Error")));
Expand All @@ -196,7 +202,17 @@ public void locateShouldNotThrowExceptionOnFailureWhenFailFastIsDisabled() {
KubernetesClientConfigMapPropertySourceLocator locator = new KubernetesClientConfigMapPropertySourceLocator(api,
configMapConfigProperties, new KubernetesNamespaceProvider(new MockEnvironment()));

assertThatNoException().isThrownBy(() -> locator.locate(new MockEnvironment()));
List<PropertySource<?>> result = new ArrayList<>();
assertThatNoException().isThrownBy(() -> {
PropertySource<?> source = locator.locate(new MockEnvironment());
result.add(source);
});

assertThat(result.get(0)).isInstanceOf(CompositePropertySource.class);
CompositePropertySource composite = (CompositePropertySource) result.get(0);
assertThat(composite.getPropertySources()).hasSize(0);
assertThat(output.getOut()).contains("Failed to load source:");

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.springframework.cloud.kubernetes.client.config;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand All @@ -30,11 +31,15 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import org.springframework.boot.test.system.CapturedOutput;
import org.springframework.boot.test.system.OutputCaptureExtension;
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
import org.springframework.cloud.kubernetes.commons.config.NamespaceResolutionFailedException;
import org.springframework.cloud.kubernetes.commons.config.RetryProperties;
import org.springframework.cloud.kubernetes.commons.config.SecretsConfigProperties;
import org.springframework.core.env.CompositePropertySource;
import org.springframework.core.env.PropertySource;
import org.springframework.mock.env.MockEnvironment;

Expand All @@ -50,6 +55,7 @@
* @author Ryan Baxter
* @author Isik Erhan
*/
@ExtendWith(OutputCaptureExtension.class)
class KubernetesClientSecretsPropertySourceLocatorTests {

private static final String LIST_API = "/api/v1/namespaces/default/secrets";
Expand Down Expand Up @@ -200,7 +206,7 @@ void locateShouldThrowExceptionOnFailureWhenFailFastIsEnabled() {
}

@Test
void locateShouldNotThrowExceptionOnFailureWhenFailFastIsDisabled() {
void locateShouldNotThrowExceptionOnFailureWhenFailFastIsDisabled(CapturedOutput output) {
CoreV1Api api = new CoreV1Api();
stubFor(get(LIST_API).willReturn(aResponse().withStatus(500).withBody("Internal Server Error")));

Expand All @@ -210,7 +216,16 @@ void locateShouldNotThrowExceptionOnFailureWhenFailFastIsDisabled() {
KubernetesClientSecretsPropertySourceLocator locator = new KubernetesClientSecretsPropertySourceLocator(api,
new KubernetesNamespaceProvider(new MockEnvironment()), secretsConfigProperties);

assertThatNoException().isThrownBy(() -> locator.locate(new MockEnvironment()));
List<PropertySource<?>> result = new ArrayList<>();
assertThatNoException().isThrownBy(() -> {
PropertySource<?> source = locator.locate(new MockEnvironment());
result.add(source);
});

assertThat(result.get(0)).isInstanceOf(CompositePropertySource.class);
CompositePropertySource composite = (CompositePropertySource) result.get(0);
assertThat(composite.getPropertySources()).hasSize(0);
assertThat(output.getOut()).contains("Failed to load source:");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,10 @@ void test(CapturedOutput output) {

// we fail while reading 'configMapOne'
Awaitility.await().atMost(Duration.ofSeconds(10)).pollInterval(Duration.ofSeconds(1)).until(() -> {
boolean one = output.getOut().contains("failure in reading named sources");
boolean two = output.getOut()
.contains("there was an error while reading config maps/secrets, no reload will happen");
boolean one = output.getOut().contains("Failure in reading named sources");
boolean two = output.getOut().contains("Failed to load source");
boolean three = output.getOut()
.contains("reloadable condition was not satisfied, reload will not be triggered");
.contains("Reloadable condition was not satisfied, reload will not be triggered");
boolean updateStrategyNotCalled = !strategyCalled[0];
return one && two && three && updateStrategyNotCalled;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,10 @@ void test(CapturedOutput output) {

// we fail while reading 'configMapOne'
Awaitility.await().atMost(Duration.ofSeconds(10)).pollInterval(Duration.ofSeconds(1)).until(() -> {
boolean one = output.getOut().contains("failure in reading named sources");
boolean two = output.getOut()
.contains("there was an error while reading config maps/secrets, no reload will happen");
boolean one = output.getOut().contains("Failure in reading named sources");
boolean two = output.getOut().contains("Failed to load source");
boolean three = output.getOut()
.contains("reloadable condition was not satisfied, reload will not be triggered");
.contains("Reloadable condition was not satisfied, reload will not be triggered");
boolean updateStrategyNotCalled = !strategyCalled[0];
return one && two && three && updateStrategyNotCalled;
});
Expand Down
Loading

0 comments on commit 87298a0

Please sign in to comment.