Skip to content

Instantly share code, notes, and snippets.

@tommysitu
Created March 16, 2017 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommysitu/b3e3ff288fe38ec8f6d4d77d2d5aea5d to your computer and use it in GitHub Desktop.
Save tommysitu/b3e3ff288fe38ec8f6d4d77d2d5aea5d to your computer and use it in GitHub Desktop.
@Bean
public RestTemplate k8sRestTemplate(K8sConfig k8sConfig) {
RestTemplate restTemplate = new RestTemplate();
Path caCertFile = Paths.get(k8sConfig.getCaCertPath());
if (Files.exists(caCertFile) && Files.isRegularFile(caCertFile)) {
SSLContext sslContext = SslUtils.createSslContextFromCertFile(caCertFile);
CloseableHttpClient httpsClient = HttpClients.custom().useSystemProperties().setSSLContext(sslContext).build();
restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpsClient));
} else {
LOGGER.warn("Certificate file {} is not found, Kubernetes api client will not be configured to use HTTPS protocol.", caCertFile.toString());
restTemplate.setRequestFactory(new SimpleClientHttpRequestFactory());
}
return restTemplate;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment