Merge branch '3.0.x'

This commit is contained in:
Ryan Baxter
2023-12-21 15:16:41 -05:00
2 changed files with 19 additions and 3 deletions

View File

@@ -49,8 +49,16 @@ public final class KubernetesClientUtils {
return apiClient;
}
catch (Exception e) {
LOG.info("Could not create the Kubernetes ApiClient in a cluster environment, because : ", e);
LOG.info("Trying to use a \"standard\" configuration to create the Kubernetes ApiClient");
if (e instanceof IllegalStateException illegalStateException
&& illegalStateException.getCause() instanceof NumberFormatException) {
LOG.info("Could not create the Kubernetes ApiClient in a cluster environment, because connection port " +
"was not provided.");
}
else {
LOG.info("Could not create the Kubernetes ApiClient in a cluster environment, because : ", e);
}
LOG.info("""
Trying to use a "standard" configuration to create the Kubernetes ApiClient""");
try {
ApiClient apiClient = ClientBuilder.defaultClient();
LOG.info("Created standard API client. Unless $KUBECONFIG or $HOME/.kube/config is defined, "

View File

@@ -22,6 +22,7 @@ import io.kubernetes.client.openapi.ApiClient;
import io.kubernetes.client.openapi.apis.CoreV1Api;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito;
import org.springframework.boot.DefaultBootstrapContext;
@@ -31,6 +32,8 @@ import org.springframework.boot.context.config.Profiles;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.boot.context.properties.source.ConfigurationPropertySources;
import org.springframework.boot.logging.DeferredLogFactory;
import org.springframework.boot.test.system.CapturedOutput;
import org.springframework.boot.test.system.OutputCaptureExtension;
import org.springframework.cloud.kubernetes.commons.KubernetesClientProperties;
import org.springframework.cloud.kubernetes.commons.config.ConfigDataRetryableConfigMapPropertySourceLocator;
import org.springframework.cloud.kubernetes.commons.config.ConfigDataRetryableSecretsPropertySourceLocator;
@@ -43,6 +46,7 @@ import org.springframework.mock.env.MockEnvironment;
/**
* @author wind57
*/
@ExtendWith(OutputCaptureExtension.class)
class KubernetesClientConfigDataLocationResolverTests {
private static final DeferredLogFactory FACTORY = Supplier::get;
@@ -142,7 +146,7 @@ class KubernetesClientConfigDataLocationResolverTests {
* these are not retryable beans.
*/
@Test
void testBothPresentExplicitly() {
void testBothPresentExplicitly(CapturedOutput capturedOutput) {
MockEnvironment environment = new MockEnvironment();
environment.setProperty("spring.cloud.kubernetes.config.enabled", "true");
environment.setProperty("spring.cloud.kubernetes.secrets.enabled", "true");
@@ -172,6 +176,10 @@ class KubernetesClientConfigDataLocationResolverTests {
SecretsPropertySourceLocator secretsPropertySourceLocator = context.get(SecretsPropertySourceLocator.class);
Assertions.assertSame(KubernetesClientSecretsPropertySourceLocator.class,
secretsPropertySourceLocator.getClass());
Assertions.assertTrue(capturedOutput.getOut()
.contains("Could not create the Kubernetes ApiClient in a cluster environment, because connection port "
+ "was not provided."));
}
/*