Skip to content

Commit

Permalink
fix issue (#1542)
Browse files Browse the repository at this point in the history
  • Loading branch information
wind57 authored Dec 21, 2023
1 parent bf5b1fd commit a77c8c0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,16 @@ public static ApiClient kubernetesApiClient() {
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, "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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;
Expand All @@ -31,6 +32,8 @@
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;
Expand All @@ -43,6 +46,7 @@
/**
* @author wind57
*/
@ExtendWith(OutputCaptureExtension.class)
class KubernetesClientConfigDataLocationResolverTests {

private static final DeferredLogFactory FACTORY = Supplier::get;
Expand Down Expand Up @@ -142,7 +146,7 @@ void testBothPresent() {
* 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");
Expand Down Expand Up @@ -172,6 +176,10 @@ void testBothPresentExplicitly() {
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."));
}

/*
Expand Down

0 comments on commit a77c8c0

Please sign in to comment.