Skip to content
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

Return a default APIClient if we run into an exception #1963

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import io.kubernetes.client.spring.extended.controller.KubernetesInformerFactoryProcessor;
import io.kubernetes.client.util.ClientBuilder;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -25,10 +27,22 @@
@ConditionalOnKubernetesInformerEnabled
public class KubernetesInformerAutoConfiguration {

private static final Logger LOGGER =
LoggerFactory.getLogger(KubernetesInformerAutoConfiguration.class);

@Bean
@ConditionalOnMissingBean
public ApiClient defaultApiClient() throws IOException {
return ClientBuilder.defaultClient();
try {
ryanjbaxter marked this conversation as resolved.
Show resolved Hide resolved
ApiClient apiClient = ClientBuilder.defaultClient();
return apiClient;
} catch (Exception e) {
LOGGER.warn(
"Could not create a Kubernetes ApiClient from either a cluster or standard environment. "
+ "Will return one that always connects to localhost:8080",
e);
return new ClientBuilder().build();
}
}

@Bean
Expand Down