public static boolean isHttpsAvailable(Config config) { Config sslConfig = new ConfigBuilder(config) .withMasterUrl(Config.HTTPS_PROTOCOL_PREFIX + config.getMasterUrl()) .withRequestTimeout(1000) .withConnectionTimeout(1000) .build(); OkHttpClient client = HttpClientUtils.createHttpClient(config); try { Request request = new Request.Builder().get().url(sslConfig.getMasterUrl()) .build(); Response response = client.newCall(request).execute(); try (ResponseBody body = response.body()) { return response.isSuccessful(); } } catch (Throwable t) { LOG.warn("SSL handshake failed. Falling back to insecure connection."); } finally { if (client != null && client.connectionPool() != null) { client.connectionPool().evictAll(); } } return false; }
orDurationInt(kubernetesClientProperties.getConnectionTimeout(), base.getConnectionTimeout())) .withRequestTimeout(orDurationInt(kubernetesClientProperties.getRequestTimeout(), base.getRequestTimeout())) .withRollingTimeout(orDurationLong(kubernetesClientProperties.getRollingTimeout(),
builder.withRequestTimeout(Integer.parseInt((String) properties.get(KUBERNETES_REQUEST_TIMEOUT_SYSTEM_PROPERTY)));
@Bean @ConditionalOnMissingBean(Config.class) public Config kubernetesClientConfig(KubernetesClientProperties kubernetesClientProperties) { Config base = new Config(); Config properties = new ConfigBuilder(base) //Only set values that have been explicitly specified .withMasterUrl(or(kubernetesClientProperties.getMasterUrl(), base.getMasterUrl())) .withApiVersion(or(kubernetesClientProperties.getApiVersion(), base.getApiVersion())) .withNamespace(or(kubernetesClientProperties.getNamespace(), base.getNamespace())) .withUsername(or(kubernetesClientProperties.getUsername(), base.getUsername())) .withPassword(or(kubernetesClientProperties.getPassword(), base.getPassword())) .withCaCertFile(or(kubernetesClientProperties.getCaCertFile(), base.getCaCertFile())) .withCaCertData(or(kubernetesClientProperties.getCaCertData(), base.getCaCertData())) .withClientKeyFile(or(kubernetesClientProperties.getClientKeyFile(), base.getClientKeyFile())) .withClientKeyData(or(kubernetesClientProperties.getClientKeyData(), base.getClientKeyData())) .withClientCertFile(or(kubernetesClientProperties.getClientCertFile(), base.getClientCertFile())) .withClientCertData(or(kubernetesClientProperties.getClientCertData(), base.getClientCertData())) //No magic is done for the properties below so we leave them as is. .withClientKeyAlgo(or(kubernetesClientProperties.getClientKeyAlgo(), base.getClientKeyAlgo())) .withClientKeyPassphrase(or(kubernetesClientProperties.getClientKeyPassphrase(), base.getClientKeyPassphrase())) .withConnectionTimeout(or(kubernetesClientProperties.getConnectionTimeout(), base.getConnectionTimeout())) .withRequestTimeout(or(kubernetesClientProperties.getRequestTimeout(), base.getRequestTimeout())) .withRollingTimeout(or(kubernetesClientProperties.getRollingTimeout(), base.getRollingTimeout())) .withTrustCerts(or(kubernetesClientProperties.isTrustCerts(), base.isTrustCerts())) .build(); if (properties.getNamespace() == null || properties.getNamespace().isEmpty()) { LOG.warn("No namespace has been detected. Please specify KUBERNETES_NAMESPACE env var, or use a later kubernetes version (1.3 or later)"); } return properties; }
public static boolean isHttpsAvailable(Config config) { Config sslConfig = new ConfigBuilder(config) .withMasterUrl(Config.HTTPS_PROTOCOL_PREFIX + config.getMasterUrl()) .withRequestTimeout(1000) .withConnectionTimeout(1000) .build(); OkHttpClient client = HttpClientUtils.createHttpClient(config); try { Request request = new Request.Builder().get().url(sslConfig.getMasterUrl()) .build(); Response response = client.newCall(request).execute(); try (ResponseBody body = response.body()) { return response.isSuccessful(); } } catch (Throwable t) { LOG.warn("SSL handshake failed. Falling back to insecure connection."); } finally { if (client != null && client.connectionPool() != null) { client.connectionPool().evictAll(); } } return false; }
builder.withRequestTimeout(Integer.parseInt((String) properties.get(KUBERNETES_REQUEST_TIMEOUT_SYSTEM_PROPERTY)));
static NamespacedKubernetesClient getKubernetesClient(Config rootConfig, String id, Container gke, KubernetesClientFactory clientFactory) { try { final Config config = rootConfig .getConfig(GKE_CLUSTER_PATH) .getConfig(id); final Cluster cluster = gke.projects().locations().clusters() .get(String.format("projects/%s/locations/%s/clusters/%s", config.getString(GKE_CLUSTER_PROJECT_ID), config.getString(GKE_CLUSTER_ZONE), config.getString(GKE_CLUSTER_ID))).execute(); final io.fabric8.kubernetes.client.Config kubeConfig = new ConfigBuilder() .withMasterUrl("https://" + cluster.getEndpoint()) .withCaCertData(cluster.getMasterAuth().getClusterCaCertificate()) .withClientCertData(cluster.getMasterAuth().getClientCertificate()) .withClientKeyData(cluster.getMasterAuth().getClientKey()) .withNamespace(config.getString(GKE_CLUSTER_NAMESPACE)) .withRequestTimeout(get(rootConfig, rootConfig::getInt, KUBERNETES_REQUEST_TIMEOUT) .orElse(DEFAULT_KUBERNETES_REQUEST_TIMEOUT_MILLIS)) .build(); final OkHttpClient httpClient = HttpClientUtils.createHttpClient(kubeConfig).newBuilder() .protocols(Collections.singletonList(Protocol.HTTP_1_1)) .build(); return clientFactory.apply(httpClient, kubeConfig); } catch (IOException e) { throw Throwables.propagate(e); } }
.withWatchReconnectInterval(5000) .withWatchReconnectLimit(5) .withRequestTimeout(5000) .withHttpProxy("httpProxy") .withTlsVersions(TLS_1_2, TLS_1_1)
builder = builder.withRequestTimeout(readTimeout * 1000).withConnectionTimeout(connectTimeout * 1000); builder.withMaxConcurrentRequestsPerHost(maxRequestsPerHost);
if (clientTimeout.isPositive()) { configBuilder.withConnectionTimeout((int) clientTimeout.toMilliseconds()); configBuilder.withRequestTimeout((int) clientTimeout.toMilliseconds()); } else { throw new IllegalArgumentException("Kubernetes client timeout should be a positive duration: " + clientTimeout.toString());
@Bean @ConditionalOnMissingBean(Config.class) public Config kubernetesClientConfig() { Config base = new Config(); Config properites = new ConfigBuilder(base) //Only set values that have been explicitly specified .withMasterUrl(or(properties.getMasterUrl(), base.getMasterUrl())) .withMasterUrl(or(properties.getApiVersion(), base.getApiVersion())) .withMasterUrl(or(properties.getApiVersion(), base.getMasterUrl())) .withUsername(or(properties.getUsername(), base.getUsername())) .withPassword(or(properties.getPassword(), base.getPassword())) .withCaCertFile(or(properties.getCaCertFile(), base.getCaCertFile())) .withCaCertData(or(properties.getCaCertData(), base.getCaCertData())) .withClientKeyFile(or(properties.getClientKeyFile(), base.getClientKeyFile())) .withClientKeyData(or(properties.getClientKeyData(), base.getClientKeyData())) .withClientCertFile(or(properties.getClientCertFile(), base.getClientCertFile())) .withClientCertData(or(properties.getClientCertData(), base.getClientCertData())) //No magic is done for the properties below so we leave them as is. .withClientKeyAlgo(or(properties.getClientKeyAlgo(), base.getClientKeyAlgo())) .withClientKeyPassphrase(or(properties.getClientKeyPassphrase(), base.getClientKeyPassphrase())) .withConnectionTimeout(or(properties.getConnectionTimeout(), base.getConnectionTimeout())) .withRequestTimeout(or(properties.getRequestTimeout(), base.getRequestTimeout())) .withRollingTimeout(or(properties.getRollingTimeout(), base.getRollingTimeout())) .withTrustCerts(or(properties.isTrustCerts(), base.isTrustCerts())) .build(); if (!base.equals(properites)) { System.out.println("Objects different"); } return properites; }
@Bean @ConditionalOnMissingBean(Config.class) public Config kubernetesClientConfig(KubernetesClientProperties kubernetesClientProperties) { Config base = new Config(); Config properties = new ConfigBuilder(base) //Only set values that have been explicitly specified .withMasterUrl(or(kubernetesClientProperties.getMasterUrl(), base.getMasterUrl())) .withApiVersion(or(kubernetesClientProperties.getApiVersion(), base.getApiVersion())) .withNamespace(or(kubernetesClientProperties.getNamespace(), base.getNamespace())) .withUsername(or(kubernetesClientProperties.getUsername(), base.getUsername())) .withPassword(or(kubernetesClientProperties.getPassword(), base.getPassword())) .withCaCertFile(or(kubernetesClientProperties.getCaCertFile(), base.getCaCertFile())) .withCaCertData(or(kubernetesClientProperties.getCaCertData(), base.getCaCertData())) .withClientKeyFile(or(kubernetesClientProperties.getClientKeyFile(), base.getClientKeyFile())) .withClientKeyData(or(kubernetesClientProperties.getClientKeyData(), base.getClientKeyData())) .withClientCertFile(or(kubernetesClientProperties.getClientCertFile(), base.getClientCertFile())) .withClientCertData(or(kubernetesClientProperties.getClientCertData(), base.getClientCertData())) //No magic is done for the properties below so we leave them as is. .withClientKeyAlgo(or(kubernetesClientProperties.getClientKeyAlgo(), base.getClientKeyAlgo())) .withClientKeyPassphrase(or(kubernetesClientProperties.getClientKeyPassphrase(), base.getClientKeyPassphrase())) .withConnectionTimeout(or(kubernetesClientProperties.getConnectionTimeout(), base.getConnectionTimeout())) .withRequestTimeout(or(kubernetesClientProperties.getRequestTimeout(), base.getRequestTimeout())) .withRollingTimeout(or(kubernetesClientProperties.getRollingTimeout(), base.getRollingTimeout())) .withTrustCerts(or(kubernetesClientProperties.isTrustCerts(), base.isTrustCerts())) .build(); if (properties.getNamespace() == null || properties.getNamespace().isEmpty()) { LOG.warn("No namespace has been detected. Please specify KUBERNETES_NAMESPACE env var, or use a later kubernetes version (1.3 or later)"); } return properties; }
orDurationInt(kubernetesClientProperties.getConnectionTimeout(), base.getConnectionTimeout())) .withRequestTimeout(orDurationInt(kubernetesClientProperties.getRequestTimeout(), base.getRequestTimeout())) .withRollingTimeout(orDurationLong(kubernetesClientProperties.getRollingTimeout(),