Created
March 16, 2017 17:43
-
-
Save tommysitu/b3e3ff288fe38ec8f6d4d77d2d5aea5d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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